[Windows / CPU] NYI crash in Categorical.log_prob → floordiv (SymInt) when calling gather

Open
#1,476 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp

Research direction

Start with TorchSharp's Categorical.log_prob entry point and compare it with the upstream torch/distributions/categorical.py fallback mentioned in the issue. Then inspect the CPU gather path implicated by c10/core/SymNodeImpl.h:76; done means the supplied Windows CPU repro no longer raises the NYI floordiv exception and log_prob completes.

Written by the indexing model from the issue text.

Description

Missing Feature

TorchSharp: 0.105.0
TorchSharp-cuda-windows 0.105.0
OS : Windows 11
.NET : 8.0.3
Hardware : intel 13th i9 - 13980HX, RTX 4090 laptop (not used – repro on CPU)

Repro case:

using TorchSharp;
using static TorchSharp.torch;

torch.random.manual_seed(0);

// any 1-D probability vector, CPU
using var probs = tensor(new float[] { 0.3f, 0.4f, 0.3f }, dtype: ScalarType.Float32);

var dist   = torch.distributions.Categorical(probs);
using var sample = dist.sample();            // OK
using var logP   = dist.log_prob(sample);    //  NYI -> floordiv

stack trace:

Unhandled exception. System.AggregateException: One or more errors occurred. (NYI
Exception raised from floordiv at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\c10/core/SymNodeImpl.h:76 (most recent call first):
00007FFE284383C900007FFE28438320 c10.dll!c10::Error::Error [<unknown file> @ <unknown line number>]

Analysis (why it happens)
Categorical.log_prob calls aten::gather under the hood.

On the Windows LibTorch build ≥ 2.1, the CPU branch of gather
was migrated to symbolic shapes; it now performs SymInt::floordiv
when checking overlaps.

That floordiv is marked NYI for Windows releases, so any CPU call
that ultimately reaches gather(select()) with symbolic sizes crashes.

Proposed fix / directions

  • Short-term: Categorical.log_prob could detect 1-D input on CPU and
    compute log(probs[index]) directly (no gather), mirroring PyTorch’s
    distributions/categorical.py fallback.

  • Long-term: implement or disable SymInt::floordiv for CPU gather on
    Windows, or compile LibTorch Windows wheels with
    BUILD_FM_SUPPORT_SYMSHAPE=OFF until full support lands.

Dominant language
C#
Stars
1.9k
Forks
228
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/TorchSharp

All issues in dotnet/TorchSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.