Skip to content

🐛 [Bug] Engine build fails when an all-zero F.pad is followed by an elementwise op (seen in SmolVLA) #4988

Closed

Description

@shoumikhin

Bug Description

Padding by zero on every side changes nothing, but Torch-TensorRT still builds a padding layer for it. The constant pad converter always builds a slice layer in fill mode, with its start and shape given as tensors built inside the network. With TensorRT 11.4, when an elementwise op follows that layer, the engine build fails with an internal assertion. (A zero pad with nothing after it was not tested.)

Real models hit this. SmolVLA's resize_with_pad resizes the image and then pads it by the leftover amount. For a square 256x256 camera image, the leftover is zero on every side, so the vision encoder fails to build. In current LeRobot, a 512x512 image builds fine, because the helper returns before the pad.

To Reproduce

import torch
import torch.nn.functional as F
import torch_tensorrt


class M(torch.nn.Module):
    def forward(self, img):
        return F.pad(img, (0, 0, 0, 0), value=0) * 2.0 - 1.0


m = M().eval()
img = torch.rand(1, 3, 64, 64, device="cuda")
trt = torch_tensorrt.dynamo.compile(torch.export.export(m, (img,)), arg_inputs=[img], min_block_size=1)
print("max abs diff", (trt(img) - m(img)).abs().max().item())

Output:

RuntimeError: TensorRT could not build the engine: [graphOptimizer.cpp::fusePattern::2092] Error Code 2: Internal Error (Assertion std::ranges::all_of( first.inputs, [&](NodeTensor const& t) { return t.get() == first.inputs[0].get(); }) failed.  In fusePattern at /_src/optimizer/common/rewrite/graphOptimizer.cpp:2092)

Expected behavior

The engine builds and matches PyTorch. A small fix: when every pad amount is a constant zero, the converter (or a lowering pass) returns the input unchanged.

Until then, a workaround is to skip the F.pad call when all the amounts are zero, or to feed images that are already the target size.

Environment

  • Torch-TensorRT Version: 2.16.0.dev, built from main
  • PyTorch Version: 2.15.0+cu132
  • TensorRT Version: 11.4.0.106
  • CPU Architecture: x86_64
  • OS: Linux
  • Python version: 3.12
  • CUDA version: 13.2
  • GPU models and configuration: 1x H100

Activity

  1. added 14 commits that reference this issue on Nov 7, 2026
    2e7cbfd
    b9a8fa2
    2d2f52c
    132ddb2
    2222ea0
    0f2e07d
    f32ec18
    563e55d
    96d8c56
    fd76b9b
    e7ecef0
    b336ffc
    e86d8db
    6093844
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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