pytorch - 💡(How to fix) Fix torch.split raises IndexError incorrectly when called in FakeTensorMode and dim_size == 0 but split_size > 0 [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181462Fetched 2026-04-25 06:02:29
View on GitHub
Comments
0
Participants
1
Timeline
19
Reactions
0
Author
Participants
Timeline (top)
labeled ×7mentioned ×6subscribed ×6

Code Example

import torch
from torch._subclasses.fake_tensor import FakeTensorMode

# Real tensor works
x = torch.empty(0)
print(torch.split(x, 2))
# Expected/actual: (tensor([]),)

# FakeTensor crashes
with FakeTensorMode():
  fx = torch.empty(0)
  print(torch.split(fx, 2))
# Raises IndexError
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

import torch
from torch._subclasses.fake_tensor import FakeTensorMode

# Real tensor works
x = torch.empty(0)
print(torch.split(x, 2))
# Expected/actual: (tensor([]),)

# FakeTensor crashes
with FakeTensorMode():
  fx = torch.empty(0)
  print(torch.split(fx, 2))
# Raises IndexError

Versions

Collecting environment information... PyTorch version: 2.6.0 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64) GCC version: Could not collect Clang version: 17.0.0 (clang-1700.6.4.2) CMake version: Could not collect Libc version: N/A

Python version: 3.12.8 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 10:37:40) [Clang 14.0.6 ] (64-bit runtime) Python platform: macOS-26.3.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Apple M3 Pro

Versions of relevant libraries: [pip3] mypy-extensions==1.0.0 [pip3] numpy==2.2.3 [pip3] optree==0.14.1 [pip3] torch==2.6.0 [conda] numpy 2.2.3 pypi_0 pypi [conda] optree 0.14.1 pypi_0 pypi [conda] torch 2.6.0 pypi_0 pypi

cc @chauhang @penguinwu @eellison @aorenste @bdhirsh @bobrenjc93

extent analysis

TL;DR

The issue is likely due to an incompatibility between PyTorch's FakeTensorMode and the torch.split function, and a workaround may involve avoiding the use of FakeTensorMode or updating PyTorch to a version where this issue is fixed.

Guidance

  • Verify that the issue is specific to FakeTensorMode by testing other PyTorch functions to see if they behave as expected.
  • Check the PyTorch documentation and release notes to see if this issue is known and fixed in a later version.
  • Consider filing a bug report or seeking help from the PyTorch community if the issue persists.
  • If possible, try to reproduce the issue with a minimal example to help isolate the cause.

Example

No code example is provided as the issue is likely related to the interaction between FakeTensorMode and torch.split, and without more information, it's difficult to provide a specific code workaround.

Notes

The issue may be specific to the version of PyTorch being used (2.6.0), and updating to a later version may resolve the issue. However, without more information, it's difficult to provide a definitive solution.

Recommendation

Apply workaround: The best course of action is to avoid using FakeTensorMode until the issue is resolved or to update PyTorch to a version where this issue is fixed, if available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING