Repository navigation
fix: run and convert engines that have uint8 or FP8 bindings - #4782
Merged
Merged
Conversation
shoumikhin
force-pushed
the
uint8-engine-io
branch
from
October 6, 2026 02:01
8093ad8 to
25f595d
Compare
shoumikhin
marked this pull request as ready for review
October 6, 2026 02:01
shoumikhin
force-pushed
the
uint8-engine-io
branch
from
October 6, 2026 07:27
25f595d to
857d5b9
Compare
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
force-pushed
the
uint8-engine-io
branch
from
October 6, 2026 16:45
857d5b9 to
5126d3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.uint8and FP8 totorch.float8_e4m3fn. It also removes the uint8 fallbacks fromlog1pand dynamic graph-inputcloneand_to_copyconversion. The int8 limit inlog1pand the uint8 limit ingatherremain.This is not general uint8 operator support. Cast a uint8 input to a supported type before any other operation. For example:
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
log1pconverter 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, andlog1p. The new dynamic_to_copytest 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_copyuint8 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: fulllabel 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.