[Windows / CPU] NYI crash in Categorical.log_prob → floordiv (SymInt) when calling gather
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
- Domain
- machine-learning
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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/TorchSharp
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 56/100
dotnet/TorchSharp#1574 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
dotnet/TorchSharp#1567 ·
-
question
Difficulty 5/5 Over a week Newbie friendliness 25/100
dotnet/TorchSharp#1557 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
dotnet/TorchSharp#1545 · 1 reaction ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
dotnet/TorchSharp#1541 ·
All issues in dotnet/TorchSharp
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·