pytorch / pytorch/TensorRT

🐛 [Bug] Dynamic shape inputs with bool or integer dtype generate all-zero tensors in py/torch_tensorrt/_Input.py

Open
#3,774 0 comments 0 reactions 1 assignee View on GitHub

@chohk88 is already working on this.

Since Aug 13, 2025.

bug story: Dynamic Shapes & Symbolic Tracing
Dominant language
Python
Stars
3k
Forks
410
Avg merge
3d 18h
Merged PRs (30d)
78

Description

Bug Description

When creating example tensors in py/torch_tensorrt/_Input.py for dynamic shape inputs, if the dtype is bool or an integer type, the generated tensor values are always zeros.
This can hide potential issues during testing, as certain operators (e.g., masked_scatter) only fail when non-zero values are present.

  • Leads to false positives in tests (tests may pass when they should fail).
  • Previously, all-zero inputs masked the bug in masked_scatter lowering.

Suggested Fix

  • For integer types: use torch.randint to generate non-zero integer values within a valid range.
  • For bool types: use torch.randint(0, 2, shape, dtype=torch.bool) to generate True/False values.

To Reproduce

Steps to reproduce the behavior:

>>> from torch_tensorrt import Input, dtype
>>> inp = Input(shape=(2, 3, 4), dtype=dtype.i32)  # or dtype.b for bool
>>> tensor = inp.example_tensor()
>>> print(tensor)
tensor([[[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0]],

        [[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0]]], dtype=torch.int32)
>>> inp = Input(shape=(2, 3, 4), dtype=dtype.f32)  # or dtype.b for bool
>>> tensor = inp.example_tensor()
>>> print(tensor)
tensor([[[0.6153, 0.5687, 0.2490, 0.9037],
         [0.3493, 0.4183, 0.4426, 0.6528],
         [0.5984, 0.2750, 0.5047, 0.8155]],

        [[0.6317, 0.3662, 0.0555, 0.8364],
         [0.6513, 0.6876, 0.3619, 0.2728],
         [0.5101, 0.5578, 0.1134, 0.4469]]])
# Output: all zeros, regardless of dtype

Expected behavior

Environment

Build information about Torch-TensorRT can be found by turning on debug messages

  • Torch-TensorRT Version (e.g. 1.0.0):
  • PyTorch Version (e.g. 1.0):
  • CPU Architecture:
  • OS (e.g., Linux):
  • How you installed PyTorch (conda, pip, libtorch, source):
  • Build command you used (if compiling from source):
  • Are you using local sources or building from archives:
  • Python version:
  • CUDA version:
  • GPU models and configuration:
  • Any other relevant information:

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.