Skip to content

fix(converters): let converters declare uint8 support and reject uint8 tensors otherwise - #4819

Closed
narendasan wants to merge 1 commit into
mainfrom
narendasan/uint8-pytorch-fallback
Closed

narendasan wants to merge 1 commit into
mainfrom
narendasan/uint8-pytorch-fallback

Conversation

@narendasan

@narendasan narendasan commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • TensorRT accepts a UInt8 tensor only as a network input or output, and only into an identity, a cast or a shape read ("has datatype UInt8 but is not network-level IO"). Torch-TensorRT converted other ops on uint8 tensors anyway, so compilation failed outright: a permute, reshape, slice, stack or reduction of a uint8 camera frame stopped with "Could not get tensor shape", and a comparison with a scalar with "Currently supported target_quantized_type for uint8 is FP4".
  • Converters now declare whether they can take a uint8 tensor: supports_uint8 on dynamo_tensorrt_converter / ConverterSupport, next to supports_dynamic_shapes, default False. ConverterRegistry.__getitem__ skips a converter without it when an ATen node reads a uint8 input or produces a uint8 output (node_has_uint8_tensors). The node then runs in PyTorch, and the uint8 tensors it shares with an engine become that engine's inputs and outputs.
  • Opted in, because they cast before anything else reads the input: _to_copy, clone, sym_size.int, log1p, and add/sub/mul/div (.Tensor/.Scalar), whose new validator accepts a uint8 operand only when the result is floating. A uint8 result would need uint8 math.
  • Constants and non-ATen operators are not checked, so FP4 weights packed in uint8 and plugins are unaffected.
  • The decision lives in the registry, so both partitioners and the interpreter see the same answer, and a new converter is safe by default. A uint8 rejection shows up as "no validated TensorRT converter"; the registry's debug log names supports uint8.
  • Builds on the uint8 bindings from fix: run and convert engines that have uint8 or FP8 bindings #4782. Robot policies that take raw camera frames hit this whenever they rearranged frames before casting them; LeRobot's WALL-X and MolmoAct2 now compile that way. Their ExecuTorch programs also need fix(executorch): save programs that keep a view outside the TensorRT engines #4817, since the views of uint8 frames left in PyTorch lower to _reshape_copy.
  • Not covered: the hierarchical partitioner decides support from converter names alone (CONVERTERS.keys()), so it skips this check as it skips every validator.

Tests

  • tests/py/dynamo/conversion/test_uint8_support.py (new):
    • Registry decisions on exported nodes: permute, comparison and uint8-result arithmetic rejected; cast and floating-result arithmetic accepted; the flag admits a converter; constants and non-ATen operators not counted.
    • End-to-end compiles with both partitioners: stacked, permuted and thresholded uint8 frames match eager (fails on main), and a cast or promotion out of uint8 stays in the engine.
  • tests/py/dynamo/conversion, partitioning, lowering, models/test_dtype_support.py, models/test_export_serde.py, run with -n 6: 2862 passed. Failures:
    • test_arange_export, which fails on main as well.
    • Three test_moe_aten.py grouped-matmul tests, which returned values up to 2.5e38. They have no uint8 tensors, so this change leaves their converter selection unchanged, and they pass when run alone.
  • Probed 32 uint8 patterns by hand. Of the 27 also run on main, 20 fail to compile there; with this change all 32 compile and match eager, and the ones that already worked still build into the engine.

🤖 Generated with Claude Code

@github-actions github-actions Bot added component: tests Issues re: Tests component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Oct 7, 2026
@meta-cla meta-cla Bot added the cla signed label Oct 7, 2026
@github-actions
github-actions Bot requested a review from zewenli98 October 7, 2026 23:36
…8 tensors otherwise

TensorRT accepts a UInt8 tensor only as a network input or output, and only into
an identity, a cast or a shape read. Torch-TensorRT converted other ops on uint8
tensors anyway, so compilation failed outright: a permute, reshape, slice, stack
or reduction of a uint8 camera frame stopped with "Could not get tensor shape",
and a comparison with a scalar with "Currently supported target_quantized_type
for uint8 is FP4". Robot policies that take raw camera frames hit this whenever
they rearranged frames before casting them to float.

Converters now declare whether they can take a uint8 tensor (supports_uint8,
next to supports_dynamic_shapes), and the registry skips a converter that does
not when an ATen node reads a uint8 input or produces a uint8 output. The node
then runs in PyTorch, and the uint8 tensors it shares with an engine become that
engine's inputs and outputs. The converters that cast before anything else reads
the input opt in: _to_copy, clone, sym_size, log1p, and add/sub/mul/div, whose
validators accept a uint8 operand when the result is floating. Constants and
non-ATen operators are not checked, so FP4 weights packed in uint8 still
convert. Since the decision lives in the registry, both partitioners and the
interpreter see the same answer, and a new converter is safe by default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@narendasan
narendasan force-pushed the narendasan/uint8-pytorch-fallback branch from 2a48fc3 to dacfd2e Compare October 8, 2026 02:49
@narendasan narendasan changed the title fix(partitioning): run ops on uint8 tensors in PyTorch unless TensorRT can build them fix(converters): let converters declare uint8 support and reject uint8 tensors otherwise Oct 8, 2026
@github-actions github-actions Bot added the component: conversion Issues re: Conversion stage label Oct 8, 2026
@narendasan

Copy link
Copy Markdown
Collaborator Author

Superseded by #4953: the partitioners now keep any node that would make a uint8 tensor inside the engine in PyTorch (makes_uint8_tensor), and the interpreter widens uint8 for data-movement ops and comparisons, so these camera-frame graphs compile and match on main (verified with this PR's end-to-end tests). Closing.

@narendasan narendasan closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant