dotnet / dotnet/TorchSharp

[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
Missing Feature
Dominant language
C#
Stars
1.9k
Forks
228
PR merge metrics
No merged PRs in 30d

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 [ @ ]
```
**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](https://github.com/pytorch/pytorch/blob/main/torch/distributions/categorical.py).

* 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.