Skip to content

fix: run and convert engines that have uint8 or FP8 bindings - #4782

Merged
lanluo-nvidia merged 2 commits into
pytorch:mainfrom
shoumikhin:uint8-engine-io
Oct 6, 2026
Merged

lanluo-nvidia merged 2 commits into
pytorch:mainfrom
shoumikhin:uint8-engine-io

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

The C++ runtime could not run engines with uint8 or FP8 (8-bit floating-point) inputs or outputs. Its type table lacked both entries, so inputs failed during engine loading and outputs failed when the runtime allocated them.

This change maps TensorRT UINT8 to torch.uint8 and FP8 to torch.float8_e4m3fn. It also removes the uint8 fallbacks from log1p and dynamic graph-input clone and _to_copy conversion. The int8 limit in log1p and the uint8 limit in gather remain.

This is not general uint8 operator support. Cast a uint8 input to a supported type before any other operation. For example:

return (image.float() / 255).permute(2, 0, 1)

Reshape, slice, permute, and arithmetic on the raw uint8 input can stop compilation with an error instead of falling back to PyTorch. Clone can preserve a uint8 binding, and the log1p converter inserts the float cast itself.

Four runtime tests cover uint8 and FP8 input and output bindings. Three build engines directly because the converter excludes casts to uint8 and FP8, and TensorRT requires dequantization instead of a cast for an FP8 input. Converter tests require one engine for uint8 clone, _to_copy, and log1p. The new dynamic _to_copy test checks every uint8 value at batch sizes 1, 7, and 32.

On H100 with TensorRT 11.3, all 198 tests in the five-file run pass, including both FP8 cases. Restoring only the _to_copy uint8 fallback makes exactly the new test fail; the other 197 still pass. All seven binding and converter regression cases fail on the main-branch wheel. Black and isort checks pass.

The full CI lane must run once with the ci: full label before merge. The binding tests are not in the fast lane. FP8 tests need compute capability 8.9 or newer and skip on the current A10G CI runners.

@meta-cla meta-cla Bot added the cla signed label Oct 5, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: core Issues re: The core compiler labels Oct 5, 2026
@github-actions
github-actions Bot requested a review from narendasan October 5, 2026 23:22
@shoumikhin shoumikhin changed the title fix(runtime): load engines that have uint8 inputs fix(runtime): load engines that have uint8 inputs or FP8 outputs Oct 6, 2026
@shoumikhin
shoumikhin marked this pull request as ready for review October 6, 2026 02:01
@shoumikhin shoumikhin changed the title fix(runtime): load engines that have uint8 inputs or FP8 outputs fix(runtime): run engines that have uint8 or FP8 inputs and outputs Oct 6, 2026
@github-actions github-actions Bot added component: conversion Issues re: Conversion stage component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Oct 6, 2026
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Oct 6, 2026
…es it

The ACT program took the tensors that `prepare_observation_for_inference`
makes: float32 images in channel-first order, and a batch dimension on
every input. So whatever ran the program had to convert each camera
frame with PyTorch first, and slice the batch off the actions.

The program now does that conversion itself. It takes the robot's frame
as the robot gives it, uint8 images in height, width, channel order and
the float32 state, with no batch dimension. It returns the chunk's
actions as a [steps, action_dim] array in robot units. The conversion is
the same code LeRobot runs (divide by 255, then permute), now inside the
compiled graph. As a bonus, the camera frames reach the GPU 4 times
smaller as uint8.

The test case keeps the raw frame, so the startup check feeds the
program exactly what the robot will.

Compiling a uint8 input with Torch-TensorRT needs
pytorch/TensorRT#4782. Without it, the ExecuTorch-TensorRT and
Torch-TensorRT routes fail to build.

Tested on a Jetson AGX Thor: all four ACT routes (ExecuTorch-TensorRT,
ONNX-TensorRT, Torch-TensorRT, ExecuTorch-CUDA) export, and each program
reproduces the PyTorch policy's actions on the raw test frame (largest
difference 0.022 to 0.034, tolerance 0.5). ruff format and ruff check
pass.
The C++ runtime could not run engines with uint8 or FP8 bindings.
Its TensorRT to PyTorch type table had no entry for either type.
Inputs failed when the engine was loaded. Outputs failed on the first
call, when the runtime tried to allocate them.

Map UINT8 to torch.uint8 and FP8 to torch.float8_e4m3fn. This covers
both input and output bindings.

Add four tests. One compiles an image model that casts its uint8
input to float before any other operation and compares with PyTorch.
Three build engines directly and check exact values for a uint8
output, an FP8 output, and an FP8 input. Direct construction is needed
because the converter excludes casts to uint8 and FP8, and TensorRT
requires dequantization instead of a cast for an FP8 input.

The FP8 tests require compute capability 8.9 or newer.
The log1p check and the dynamic graph-input copy check sent uint8
inputs back to PyTorch. Those checks worked around a missing uint8
entry in the C++ runtime's type table. With that entry fixed, these
operations can run in an engine.

Remove uint8 from the two checks. Update the copy check's docstring
and explain why log1p still rejects int8: TensorRT treats an int8
input as quantized data, so math after a cast fails the engine build.
The uint8 gather check also stays.

This is not general uint8 operator support. Cast a uint8 input to a
supported type before any other operation. Reshape, slice, permute,
and arithmetic on the raw uint8 input can stop compilation with an
error instead of falling back. Clone can preserve a uint8 binding,
and the log1p converter inserts the needed float cast itself.

Check that uint8 log1p and dynamic clone build one engine and match
PyTorch. Add a separate dynamic uint8 to float16 _to_copy test that
requires one engine and exact values from 0 through 255 at batch
sizes 1, 7, and 32.
@shoumikhin shoumikhin changed the title fix(runtime): run engines that have uint8 or FP8 inputs and outputs fix: run and convert engines that have uint8 or FP8 bindings Oct 6, 2026

@lanluo-nvidia lanluo-nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: full 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.

2 participants