Skip to content

🐛 [Bug] dynamo.compile silently ignores kwarg_inputs entries the program does not take #5031

Open

Description

@shoumikhin

Bug Description

torch_tensorrt.dynamo.compile accepts kwarg_inputs entries that the exported program does not take, and ignores them with no error and no warning. Two cases:

  • a name that forward() does not have (for example a typo);
  • a name that duplicates a positional input, with a different shape.

So a typo in a kwarg_inputs key, or a stale shape, changes nothing and goes unnoticed. Eager PyTorch rejects both calls with a TypeError.

To Reproduce

import torch
import torch_tensorrt


class M(torch.nn.Module):
    def forward(self, x):
        return x * 2 + 1


x = torch.ones(3, device="cuda")
ep = torch.export.export(M().cuda().eval(), (x,))

# 1. a name forward() does not take
torch_tensorrt.dynamo.compile(
    ep, arg_inputs=[x], kwarg_inputs={"bogus": torch.ones(7, device="cuda")}, min_block_size=1
)
# 2. a duplicate of the positional input, with a different shape
torch_tensorrt.dynamo.compile(
    ep, arg_inputs=[x], kwarg_inputs={"x": torch.ones(5, device="cuda")}, min_block_size=1
)

Both calls compile, and the resulting modules run and return [3.0, 3.0, 3.0].

Expected behavior

An error (or at least a warning) for both, matching eager PyTorch:

M()(x, bogus=...) -> TypeError: M.forward() got an unexpected keyword argument 'bogus'
M()(x, x=...)     -> TypeError: M.forward() got multiple values for argument 'x'

Where it happens

From reading the code (not traced in a debugger): in py/torch_tensorrt/dynamo/_compiler.py, _build_user_symbol_bounds falls back, when in_spec.flatten_up_to raises, to looping over user_input_names[len(sample_arg_inputs):] and reading only the keys that match. Keys that match no remaining user input are dropped silently. The multi-profile path (top_level_inputs.extend(sample_kwarg_inputs.values())) also takes the values without checking the names. compile_and_save passes the same arguments, so it behaves the same way.

Environment

  • Torch-TensorRT: 2.15.0 (Python package files identical to the v2.15.0 tag)
  • PyTorch: 2.15.0+cu132
  • Seen on Linux x86_64 with an H100, and on Jetson AGX Thor (aarch64) with the PyPI torch_tensorrt 2.15.0 wheel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions