Skip to content

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

Open

Description

@GGreenNine

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.

Activity

  1. haytham2597 commented on Sep 20, 2025

    @haytham2597

    Hi, i tested this on Libtorch 2.8.0 Cuda 12.8 (with tensors on CPU) and not have any exception. Soon i will try replicate them with old libtorch like 2.1+cpu

    Environment tested:

    • Libtorch 2.8.0+cu128
    • Net Framework 4.7.2
    • Debug mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions