pytorch - 💡(How to fix) Fix torch.export in PyTorch 2.10 emits INT64_MAX instead of None for aten.slice.Tensor end bounds [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#178618Fetched 2026-04-08 01:40:28
View on GitHub
Comments
0
Participants
1
Timeline
24
Reactions
0
Author
Participants
Timeline (top)
mentioned ×9subscribed ×9labeled ×3cross-referenced ×2

Code Example

import torch
import torch.nn as nn
from torch.export import export, Dim

class Model(nn.Module):
    def forward(self, x, y):
        return x[::6, :], y

model = Model()
model.eval()
batch = Dim("batch", min=1, max=1000)
x = torch.randn(30, 6)
y = torch.randn(1000, 3)

prog = export(model, (x, y), dynamic_shapes={"x": {}, "y": {0: batch}})
graph_str = str(prog.graph_module.graph)
print(graph_str)

if "9223372036854775807" in graph_str:
    print("\nBUG: INT64_MAX (9223372036854775807) found in slice args")
else:
    print("\nOK: No INT64_MAX in slice args")

---

PyTorch version: 2.10.0+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 12 (bookworm) (x86_64)
GCC version: (Debian 12.2.0-14+deb12u1) 12.2.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.36

Python version: 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-6.1.0-44-amd64-x86_64-with-glibc2.36
Is CUDA available: False
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA A16-4Q
Nvidia driver version: 570.133.20
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==2.3.4
[pip3] torch==2.10.0+cpu
[pip3] torchaudio==2.10.0+cpu
[pip3] torchvision==0.25.0+cpu
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.export in PyTorch 2.10.0 emits aten.slice.Tensor with explicit 0 and 9223372036854775807 (INT64_MAX) as start/end arguments, instead of None which was used in PyTorch 2.8.0.

This is a regression from the behavior in PyTorch 2.8.0, where slice operations with step > 1 used None for unbounded start/end:

PyTorch 2.8.0: aten.slice.Tensor(x, 0, None, None, 6) PyTorch 2.10.0: aten.slice.Tensor(x, 0, 0, 9223372036854775807, 6)

While semantically equivalent in Python/PyTorch, the INT64_MAX value causes issues for downstream compilers (e.g., torch-mlir / MLIR pipelines) that materialize this constant as an index type — it overflows when the target uses 32-bit indices.

Minimal reproducer

import torch
import torch.nn as nn
from torch.export import export, Dim

class Model(nn.Module):
    def forward(self, x, y):
        return x[::6, :], y

model = Model()
model.eval()
batch = Dim("batch", min=1, max=1000)
x = torch.randn(30, 6)
y = torch.randn(1000, 3)

prog = export(model, (x, y), dynamic_shapes={"x": {}, "y": {0: batch}})
graph_str = str(prog.graph_module.graph)
print(graph_str)

if "9223372036854775807" in graph_str:
    print("\nBUG: INT64_MAX (9223372036854775807) found in slice args")
else:
    print("\nOK: No INT64_MAX in slice args")

Expected behavior (PyTorch 2.8.0)

slice_1 = torch.ops.aten.slice.Tensor(x, 0, None, None, 6)

None is used for unbounded start/end, which downstream compilers can correctly interpret as "slice to end."

Actual behavior (PyTorch 2.10.0)

slice_1 = torch.ops.aten.slice.Tensor(x, 0, 0, 9223372036854775807, 6)

Versions

PyTorch version: 2.10.0+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 12 (bookworm) (x86_64)
GCC version: (Debian 12.2.0-14+deb12u1) 12.2.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.36

Python version: 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-6.1.0-44-amd64-x86_64-with-glibc2.36
Is CUDA available: False
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA A16-4Q
Nvidia driver version: 570.133.20
cuDNN version: Could not collect
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==2.3.4
[pip3] torch==2.10.0+cpu
[pip3] torchaudio==2.10.0+cpu
[pip3] torchvision==0.25.0+cpu

cc @chauhang @penguinwu @avikchaudhuri @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4

extent analysis

Fix Plan

To fix the regression issue in PyTorch 2.10.0, we need to modify the torch.export function to use None for unbounded start/end in slice operations.

Here are the steps:

  • Modify the torch.export function to check if the step size is greater than 1.
  • If the step size is greater than 1, use None for the end argument in the slice operation.
  • Update the export function to handle this change.

Example code:

import torch
import torch.nn as nn
from torch.export import export, Dim

# Define a custom export function
def custom_export(model, args, dynamic_shapes=None):
    # Get the graph module
    graph_module = export(model, args, dynamic_shapes=dynamic_shapes)
    
    # Modify the graph to use None for unbounded start/end
    for node in graph_module.graph.nodes:
        if node.kind() == 'aten::slice':
            # Check if the step size is greater than 1
            step_size = node.inputsAt(4)
            if step_size > 1:
                # Use None for the end argument
                node.inputsAt(3) = None
    
    return graph_module

class Model(nn.Module):
    def forward(self, x, y):
        return x[::6, :], y

model = Model()
model.eval()
batch = Dim("batch", min=1, max=1000)
x = torch.randn(30, 6)
y = torch.randn(1000, 3)

# Use the custom export function
prog = custom_export(model, (x, y), dynamic_shapes={"x": {}, "y": {0: batch}})
graph_str = str(prog.graph_module.graph)
print(graph_str)

if "9223372036854775807" in graph_str:
    print("\nBUG: INT64_MAX (9223372036854775807) found in slice args")
else:
    print("\nOK: No INT64_MAX in slice args")

Verification

To verify that the fix worked, run the modified code and check if the INT64_MAX value is still present in the graph string. If the fix is successful, the INT64_MAX value should be replaced with None.

Extra Tips

  • This fix assumes that the downstream compilers can correctly interpret None as "slice to end."
  • If the downstream compilers do not support None as an index type, additional modifications may be necessary.
  • It is recommended to test the modified code thoroughly to ensure that it works as expected in all scenarios.

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

pytorch - 💡(How to fix) Fix torch.export in PyTorch 2.10 emits INT64_MAX instead of None for aten.slice.Tensor end bounds [1 participants]