Skip to content

feat(conversion): grouped_mm: leave large cases to PyTorch, or run them with a grouped GEMM kernel - #5021

Open
shoumikhin wants to merge 6 commits into
pytorch:mainfrom
shoumikhin:grouped-mm-kernel
Open

shoumikhin wants to merge 6 commits into
pytorch:mainfrom
shoumikhin:grouped-mm-kernel

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #5016 (its commits come first).

What is wrong today

aten._grouped_mm is the matrix multiply of mixture-of-experts (MoE) layers. Rows are sorted by expert; offs marks where each expert's rows end. Torch-TensorRT converts it densely: every row is multiplied by every expert's weight. With 128 experts that is 128 times the work.

For one MoE layer (dim 3072, 128 experts, top-8) with 3500 tokens, eager PyTorch takes 2.89 ms on H100, TensorRT 397 ms and 23.7 GiB of extra memory.

A dynamic row count also gets pinned to the example size.

What this change does

An opt-in limit. A new setting, grouped_mm_dense_max_macs, leaves the op to PyTorch when the dense lowering would do more multiply-adds than that (groups * rows * K * N). It is off by default:

trt_model = torch_tensorrt.compile(model, ir="dynamo", inputs=inputs, grouped_mm_dense_max_macs=2**38)

Above 2**38 the dense engine was always slower than PyTorch on H100 and A100.

Without the kernel below, a dynamic row count now runs in PyTorch with a warning, and the engines around it stay dynamic. Under require_full_compilation=True such a compile now fails instead of building an engine that takes only the example size. Refitting such an old saved program fails instead of keeping old weights.

Or a grouped GEMM kernel in TensorRT. A second converter, opt-in with grouped_mm_kernel=True, inserts a TensorRT plugin that runs a Triton grouped matrix multiply. It computes only each row's own group and reads offs on the GPU, so large and dynamic-row MoE layers stay in an engine. The engine stores the kernel's PTX, so running it needs no Triton (refit does), but a driver at least as new as the build machine's.

It takes bfloat16 and float16 on sm_80 or newer, with K and N multiples of 8, so every row is 16-byte aligned, as PyTorch's aten._grouped_mm requires. Both matrices and the output must start 16-byte aligned. From sm_90 on it runs A100's mma.sync PTX. Jetson Thor instead uses tcgen05, which #5016 allows, for 17 to 22% less time.

What was tested

  • test_moe_aten.py: the limit, both converters, kernel conditions, warnings.
  • test_000_grouped_mm_left_to_pytorch.py: over the limit and with dynamic rows the op runs in PyTorch, and such a refit fails.
  • test_000_grouped_mm_kernel.py (including a reloaded dynamic-row engine and refit) and executorch/test_grouped_mm_kernel.py pass on an A100 (sm_80). The same kernel code also passed on a Jetson AGX Orin (sm_87) and Jetson Thor (sm_110).

@meta-cla meta-cla Bot added the cla signed label Nov 12, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Nov 12, 2026
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 13, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Nov 15, 2026
…5021 on main

Brings the grouped GEMM kernel on this branch to the current version of
pytorch#5021 on main. The kernel is opt-in through a grouped_mm_kernel setting (default
False). It declines, with one warning that names the reason, when
Triton, the driver's PTX limit, the GPU, hardware compatibility or
Windows cross-compilation rule it out. A build failure is cached and
logged once. Rows are masked so invalid offsets, past mat1 or negative,
never read or write outside mat1 or the output. The dense converter's
warning suggests the setting only when it is off and the kernel would
likely take the op, checked without starting Triton. The tests are the
same as on main, including engine-only exports run in a fresh process
that loads only TensorRT and PyTorch, and a .pte run by the ExecuTorch
runtime.

It adapts to the release branch's kernel helpers. The plugin launch is
still built in the kernel module, since this branch has no
_common.make_pointer_aot_fn. The 48 KiB shared memory limit is a named
constant in kernels/_common.py, used by the triton_op check, its error
message and this kernel, as on main. compile_triton_to_ptx here hints
every pointer as 16-byte aligned; it gets an optional per-pointer
pointer_alignment, with the old behaviour as the default, so the kernel
can leave the offsets unhinted as it does on main.

This branch is release/2.15 (5aca374) with these release/2.15 ports of
pull requests on main, oldest first:

- pytorch#5014: fix(conversion): leave large aten._grouped_mm to PyTorch instead of the dense lowering
- pytorch#5016: fix(kernels): reject AOT kernels that need more than 48 KiB of shared memory
- pytorch#5017: fix(kernels): give triton_op kernels Triton's pointer alignment hint
- pytorch#5021: feat(conversion): run aten._grouped_mm in TensorRT with a grouped GEMM kernel
- pytorch#5021: fix(conversion): build the grouped GEMM plugin launch directly on release/2.15
- pytorch#5020: feat(dynamo): convert stable sort of index tensors with a counting sort
- pytorch#5020: fix(dynamo): counting sort: add the key count to the engine cache key, convert single rows only
- pytorch#5019: fix(dynamo): keep a select of a uint8 tensor inside the TensorRT engine
- pytorch#5022: fix(dynamo): keep a cast to uint8 inside the TensorRT engine
- pytorch#5023: Compute antialiased resize weights like PyTorch's CUDA kernel
- pytorch#5024: Convert antialiased bilinear resize by default
- pytorch#5021: fix(conversion): compile the grouped GEMM kernel without tensor memory on sm_100 and newer
- pytorch#5015: fix(dynamo): release weights before serializing the engine, not after
- pytorch#5021: feat(conversion): make the grouped GEMM kernel opt-in, as in pytorch#5021 on main

Signed-off-by: Anthony Shoumikhin <[email protected]>
shoumikhin added a commit to shoumikhin/TensorRT that referenced this pull request Nov 15, 2026
…5021 on main

Brings the grouped GEMM kernel on this branch to the current version of
pytorch#5021 on main. The kernel is opt-in through a grouped_mm_kernel setting (default
False). It declines, with one warning that names the reason, when
Triton, the driver's PTX limit, the GPU, hardware compatibility or
Windows cross-compilation rule it out. A build failure is cached and
logged once. Rows are masked so invalid offsets, past mat1 or negative,
never read or write outside mat1 or the output. The dense converter's
warning suggests the setting only when it is off and the kernel would
likely take the op, checked without starting Triton. The tests are the
same as on main, including engine-only exports run in a fresh process
that loads only TensorRT and PyTorch, and a .pte run by the ExecuTorch
runtime.

It adapts to the release branch's kernel helpers. The plugin launch is
still built in the kernel module, since this branch has no
_common.make_pointer_aot_fn. The 48 KiB shared memory limit is a named
constant in kernels/_common.py, used by the triton_op check, its error
message and this kernel, as on main. compile_triton_to_ptx here hints
every pointer as 16-byte aligned; it gets an optional per-pointer
pointer_alignment, with the old behaviour as the default, so the kernel
can leave the offsets unhinted as it does on main.

This branch is release/2.15 (5aca374) with these release/2.15 ports of
pull requests on main, oldest first:

- pytorch#5014: fix(conversion): leave large aten._grouped_mm to PyTorch instead of the dense lowering
- pytorch#5016: fix(kernels): reject AOT kernels that need more than 48 KiB of shared memory
- pytorch#5017: fix(kernels): give triton_op kernels Triton's pointer alignment hint
- pytorch#5021: feat(conversion): run aten._grouped_mm in TensorRT with a grouped GEMM kernel
- pytorch#5021: fix(conversion): build the grouped GEMM plugin launch directly on release/2.15
- pytorch#5020: feat(dynamo): convert stable sort of index tensors with a counting sort
- pytorch#5020: fix(dynamo): counting sort: add the key count to the engine cache key, convert single rows only
- pytorch#5019: fix(dynamo): keep a select of a uint8 tensor inside the TensorRT engine
- pytorch#5022: fix(dynamo): keep a cast to uint8 inside the TensorRT engine
- pytorch#5023: Compute antialiased resize weights like PyTorch's CUDA kernel
- pytorch#5024: Convert antialiased bilinear resize by default
- pytorch#5021: fix(conversion): compile the grouped GEMM kernel without tensor memory on sm_100 and newer
- pytorch#5015: fix(dynamo): release weights before serializing the engine, not after
- pytorch#5021: feat(conversion): make the grouped GEMM kernel opt-in, as in pytorch#5021 on main

Signed-off-by: Anthony Shoumikhin <[email protected]>
@shoumikhin
shoumikhin force-pushed the grouped-mm-kernel branch 3 times, most recently from 82381d2 to 33a7cec Compare November 17, 2026 21:27
@shoumikhin shoumikhin changed the title feat(conversion): run aten._grouped_mm in TensorRT with a grouped GEMM kernel feat(conversion): grouped_mm: leave large cases to PyTorch, or run them with a grouped GEMM kernel Nov 18, 2026
@shoumikhin
shoumikhin force-pushed the grouped-mm-kernel branch 6 times, most recently from bb09ce4 to 908675f Compare November 20, 2026 15:44
…imit

CUDA lets a kernel use more than 48 KiB of dynamic shared memory only after
the launcher opts the kernel in with cuFuncSetAttribute. TensorRT launches
AOT plugin kernels without doing that (pytorch#5010). So a plugin kernel that needs
more than 48 KiB builds into an engine without complaint, and then every run
of the engine fails with a generic plugin assertion that gives no reason.
Large Triton tiles with software pipelining often need more than 48 KiB, so
this is easy to hit.

The capability validators of triton_op and cutedsl_op now decline such a
kernel, the same way they decline hardware-compatible engines. The op and
its eager_fn stay registered, the op runs in PyTorch where the graph
allows it, and
warnings at registration and at conversion name the cause and the fix
(fewer pipeline stages or smaller tiles). An op without an eager_fn could not run anywhere, so for it
registration fails with the same explanation instead. For cutedsl_op the
count also includes the kernel's static shared memory, which shares the
same limit, as the CUDA driver reports it when registration loads the PTX.
Kernels at or below 48 KiB are unchanged.

ptx_op and cuda_kernel_op get their launch parameters from an aot_fn, which
TensorRT calls only while it builds the engine. The AOT launch that every
frontend shares now checks the shared_mem it returns there, plus the
kernel's static shared memory as the CUDA driver reports it. A constant
total above 48 KiB fails the engine build, and the build log names the
limit and pytorch#5010, instead of building an engine that fails on every run.
When the driver cannot report the static size, for example without
cuda-python, the check warns that it counts the dynamic memory only, and
the next build reads the size again.
For a custom tactic it only logs a warning, because TensorRT can drop a
tactic whose launch fails and build with another one. A lone custom tactic
is not dropped, so that case still builds and then fails when it runs.

Signed-off-by: Anthony Shoumikhin <[email protected]>
A Triton kernel built for sm_100 or sm_110 keeps its matmul accumulator in
tensor memory. triton_op refused any such kernel, on the belief that a
TensorRT plugin launch cannot set that memory up.

A plugin launch does not need to set it up: the kernel allocates its tensor
memory itself with tcgen05.alloc. Triton's own loader only checks the request
against the tensor memory an SM has: 576 columns on sm_107 and 512 elsewhere.
Accept up to that and keep refusing anything larger, with a message that names
the limit.

Tested: tests/py/kernels/test_triton_op.py, including a triton_op registration
of a kernel with tensor memory, compiled for sm_100 on another GPU and small
enough for the 48 KiB limit; the new and changed tests fail without the
change. A grouped GEMM kernel built with tcgen05 this way ran inside a
TensorRT engine on Jetson Thor and matched the reference.

Signed-off-by: Anthony Shoumikhin <[email protected]>
…ent hint

When Triton launches a kernel the normal way, it looks at each pointer
argument and tells the compiler which ones are 16-byte aligned. That hint
lets the compiler use vector loads, and for 1- and 2-byte elements also
asynchronous copies and software pipelining.

triton_op compiles the kernel ahead of time, before any pointer exists,
so it never passes the hint, and every triton_op kernel gets scalar memory
accesses only. Such a kernel can run several times slower inside a
TensorRT engine than the same kernel launched by Triton.

triton_op now takes pointer_alignment, with the same meaning and default
as in cutedsl_op: the byte alignment the kernel may assume for every
pointer, or a mapping from pointer names to alignments. Any alignment
above 1 becomes Triton's divisibility hint for that pointer, capped at 16
as Triton's own launcher does, and names that are not pointer parameters
are rejected. The default of 1 adds no hint, so existing registrations
compile exactly as before. Scalar arguments still get no hint, unlike in
Triton's launcher, so an access masked by a runtime size can stay scalar.
The declared alignment must hold for every pointer the kernel gets, and
a misaligned vector access is a sticky CUDA error. TensorRT does not document an
alignment for the buffers it allocates inside the engine, though in my
tests, including the engine test where TensorRT layers surround the
kernel, they were always aligned. TensorRT binds engine inputs as given,
so an offset view whose byte offset is not a multiple of the alignment
does not meet it. Values must be powers of two from 1 to 256. Both
frontends now share one pointer_alignment parser. Pipelining can take a
kernel over the 48 KiB shared memory limit, so the advice for that case
now also names pointer_alignment, and the registration log shows the
alignments in use.

Signed-off-by: Anthony Shoumikhin <[email protected]>
…t is set

The aten._grouped_mm converter multiplies every row by the weight of every
group and then masks away the unwanted results. A mixture-of-experts layer
with 128 experts therefore does 128 times the work and builds a
[groups, rows, N] temporary tensor. For large layers this is far slower than
PyTorch's grouped matmul, which only computes each row's own group, and it
can need more GPU memory than the device has.

A new setting, grouped_mm_dense_max_macs, makes grouped_mm_validator
decline the op when the dense lowering would do more multiply-adds than
that (groups * rows * K * N). torch_tensorrt.compile,
cross_compile_for_windows and CompilationSettings take it. It is off
(None) by default, so a default compile converts a statically shaped op
as before and keeps the graph in one engine.
Above 2**38 the dense engine was slower than PyTorch in every case
measured on H100 and A100, so the docs name that value.

The op is still converted when it has one group (no wasted work) and
under require_full_compilation=True.
convert_exported_program_to_serialized_trt_engine has no such setting and
converts every such op with static shapes.

A declined op runs in PyTorch under torch_tensorrt.compile and
torch.compile, and in each compile one warning per node names the
setting. The setting takes only positive integers, not booleans. When saving
for ExecuTorch, a declined op needs a partitioner that takes it, such as
the CUDA partitioner. PyTorch's grouped matmul copies the offsets to the
host when it has no fast kernel (such as float32, or bfloat16 on an
A100), so such a module cannot be captured whole by CUDA graphs. The docs say to keep None for both cases.

The validator also no longer calls int() on a dynamic row count. That
did not raise as the code expected: it pinned the row count to the
example size, so the engines around the op refused any other size. The
op with a dynamic row count still runs in PyTorch, but the engines
around it now stay dynamic, and one warning per node says why. Under assume_dynamic_shape_support=True such
an op used to go into an engine that took only the example size; now it
runs in PyTorch too. With require_full_compilation=True as well, such a
compile now fails as not fully supported instead of building that
engine. Refitting a program saved with such an engine now fails too,
and the docs say to compile it again. Before, a refit whose new graph had
fewer supported operations than min_block_size returned that graph, so an
in-place refit kept the engines' old weights without an error, and
any other refit returned a module with no engines. Such a refit now
fails. As in compile, a
fully supported graph under require_full_compilation is not skipped for
being small, so its engine is refitted.

Signed-off-by: Anthony Shoumikhin <[email protected]>
…M kernel

Mixture-of-experts layers sort their rows by expert and call
aten._grouped_mm, where each row is multiplied only by its own expert's
weight. The existing converter lowers this densely: every row is
multiplied by every expert's weight and the unwanted results are masked
away. With 128 experts that is 128 times the work, so large layers are
slow, and leaving them to PyTorch with grouped_mm_dense_max_macs splits
the graph into more engines. The dense converter also needs a static row
count, so with a dynamic number of tokens the op always runs in PyTorch.

This adds a second converter for the op, opt-in through a new setting,
grouped_mm_kernel (default False), and tried first when set. It inserts
a TensorRT plugin that runs a Triton grouped matrix multiply. The kernel
reads the group offsets on the GPU, so nothing is copied to the host,
and it computes each row only against its own group's weight, with
float32 accumulation as in PyTorch. The kernel is compiled ahead of time
when the engine is built, through torch_tensorrt.kernels, and its PTX is
stored in the engine. Running the engine needs no Triton. Refitting it
converts the program again, so it needs Triton and cuda-python, as the
build does, and the docs say so. Rows past the
last offset belong to no group, and the kernel writes zeros there, as
the dense converter does, so the output never holds stale memory.

With grouped_mm_kernel=True the new converter is used when all of these
hold: bfloat16 or float16 matrices, int32 offsets, the (rows, K) x
(groups, K, N) form without bias, out_dtype unset or equal to the input
dtype, more than one group or a dynamic row count (the dense converter
needs a static one), static K, N and group count, K and N multiples of
8, N above 0, a GPU with
compute capability 8.0 or newer, TensorRT plugins, Triton 3.5 or newer
(3.7 or newer on sm_110, whose code the ptxas of older releases cannot
build) and cuda-python installed, an engine that is not hardware compatible, and
no Windows cross-compilation.
cuda-python reads the driver's PTX limit; without it the PTX could be
too new for the driver, so the kernel declines. The setting is off by
default because an engine with the kernel needs a CUDA driver at least
as new as the build machine's. Otherwise the dense converter and
grouped_mm_dense_max_macs apply as before. When the setting is on but
the GPU, the installed packages or other settings rule the kernel out,
or it does not build, one warning per compile says why. The dense
converter's warnings, for a large op and for a dynamic row count,
suggest the setting only when it is off and the
kernel would likely take the op. That runs the kernel's checks except
the ones that start Triton's driver, read the driver's PTX limit or
compile the kernel, so the warning says the kernel would likely take it.
cross_compile_for_windows does not get the setting, since the kernel
never runs there.

The validator compiles the kernel, so a kernel that cannot be built for
a plugin launch declines the op instead of failing the engine build.
A kernel that built is cached per shape and GPU. A failure is remembered
only for the rest of the compile, so the next compile tries again in case
the failure was temporary, such as a full disk. A plugin registration
with TensorRT that fails halfway is rolled back, so it can be tried again.
Offsets outside mat1 or going down are invalid. The kernel clamps them into
[0, rows] and takes their running maximum, so it never reads or writes
outside mat1 or the output and still writes every output row.

The kernel uses 128 x 128 x 32 tiles. TensorRT gives a plugin kernel at
most 48 KiB of shared memory today, so it uses 3 pipeline stages where
they fit and 2 otherwise. From sm_90 on, the kernel is compiled
with sm_80 instructions (mma.sync), the code that ran on A100, because
Triton's own code for tl.dot there (wgmma on sm_90, tcgen05 from sm_100
on) was not run with these tiles. Apart from its header, which still
targets the device, the PTX is the same as on sm_80, and a test checks
that. compile_triton_to_ptx gets an arch argument for this. On those GPUs
the kernel can be slower than PyTorch's grouped matrix multiply at large
row counts, and the docs say to measure it.
The kernel declares mat1, mat2 and the output 16-byte aligned
(pointer_alignment=16), so Triton uses 16-byte loads and pipelining.
Without it the kernel took up to 2.4 times as long on an A100. TensorRT
requires engine inputs and outputs to be bound 256-byte aligned, though
it does not check this, and PyTorch's aten._grouped_mm needs both
matrices 16-byte aligned and raises otherwise. It also needs their row
strides to be multiples of 16 bytes, so the converter takes only K and N
that are multiples of 8, and every row of mat1, mat2 and the output
starts aligned. The docs say so, and that
a misaligned one fails with a CUDA misaligned address error. TensorRT
does not document an alignment for the buffers it allocates inside the
engine, though in my tests they were always aligned. The offsets get no
hint: a load of a few offsets gains nothing from one.

The tests hold one case per behaviour. The converter tests check which
converter took each op. The validator tests check that the kernel is
opt-in, the dtype, bias, out_dtype, offsets, alignment, zero-width and
one-group conditions, the warning in each compile when Triton, the driver's PTX
limit, the GPU or the settings rule the kernel out, and when the dense
warning suggests the setting.
The kernel tests skip at run time whenever the validator would decline
for the environment. Kernel tests compile it for sm_90 and sm_100 on any
GPU and check that the code is sm_80's, check the pipeline-stage fallback and the shared memory error, and
cover a dynamic row count in one engine, the same in a fresh process
that loads the saved engine without Triton, and a compile failure that
falls back, is tried once per compile and warns in each compile, and a
failed plugin registration that is tried again, and a refit with new
weights, with a static and a dynamic row count. An engine-only
export runs in a fresh process that loads only TensorRT and PyTorch, and
checks the result, that offsets past the row count, negative or going
down never write outside the output, and that rows past the largest
offset are zero.
An ExecuTorch test runs a .pte file with the kernel in a fresh process
that loads neither Triton nor Torch-TensorRT.

Signed-off-by: Anthony Shoumikhin <[email protected]>
…Thor

On Jetson Thor (sm_110) the grouped GEMM kernel ran sm_80's mma.sync
instructions. A Triton plugin kernel can use the tensor memory that tcgen05
needs, so build the kernel for Thor itself, with tcgen05.

Only Thor gets it, because only Thor was measured. Other GPUs from sm_90 on
keep sm_80's instructions. On Thor the kernel still needs Triton 3.7 or newer,
which the converter already checks.

tcgen05 adds 16 bytes of shared memory, so 128x128x32 tiles with 3 stages no
longer fit the 48 KiB a TensorRT plugin kernel gets. 128x256x16 tiles do, and
were the fastest that fit among the shapes measured on Thor. The kernel build
now returns the tile it used, and the launch grid is sized from it.

On Jetson Thor, for bf16 grouped GEMMs with 128 groups and 55k to 70k rows,
each call takes 17 to 22% less time, from the new instructions and the new
tile together, with bitwise identical output. Inside a TensorRT engine, the
2 calls measured took 13% and 17% less time.

Tested: tests/py/dynamo/partitioning/test_000_grouped_mm_kernel.py and the
other grouped GEMM tests on an A100, where the Thor code is compiled and
checked but not run, and an engine runs with Thor's tile on the A100's own
instructions; kernel and engine runs on Jetson Thor.

Signed-off-by: Anthony Shoumikhin <[email protected]>
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 23, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 23, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 23, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
@shoumikhin
shoumikhin force-pushed the grouped-mm-kernel branch 3 times, most recently from 2429f91 to d1b4b82 Compare November 24, 2026 11:01
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 24, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 24, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
@shoumikhin
shoumikhin force-pushed the grouped-mm-kernel branch 2 times, most recently from 54c0e1f to af0fc03 Compare November 24, 2026 21:54
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 24, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 25, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 25, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.
shoumikhin added a commit to shoumikhin/lerobot that referenced this pull request Nov 26, 2026
…s in TensorRT

Torch-TensorRT runs `aten._grouped_mm`, the grouped matrix multiply of
mixture-of-experts layers, inside TensorRT only with its opt-in
`grouped_mm_kernel` setting (pytorch/TensorRT#5021). Without it, each
such layer stays outside TensorRT, and Praxis-1's `velocity` program
splits into many TensorRT engines with CUDA backend parts between them.
A recipe had no way to pass a setting to the backend's compiler.

`Part` gets `compile_options`, settings of the backend's compiler for
that part alone, empty by default. They go to the compile step as JSON,
so a part refuses values that JSON cannot hold. The trace step hands
them to the compile step of the part's program, which passes them to
the backend's `compile` as the keyword argument `compile_options`, and
only for a part that has some. So a backend whose `compile` takes only
the program and the path, in LeRobot or in a `lerobot_backend_<name>`
package, keeps working unchanged.

Only `executorch_tensorrt` takes them. It adds them to its own
Torch-TensorRT settings. It refuses a setting that the installed
Torch-TensorRT does not have, since Torch-TensorRT would ignore it
without a word. It also refuses one that it already passes, from its
own settings, the user's `--backend` flags or the arguments of its call,
so a recipe never replaces them silently.

The Praxis-1 recipe sets `grouped_mm_kernel` on `velocity` and
`decoder`, the parts that hold the mixture-of-experts layers, only when
the backend is `executorch_tensorrt`. With that backend it also checks,
before any weight loads, that Torch-TensorRT is installed and that its
`CompilationSettings` has the setting. It checks the setting itself
rather than a version. A Torch-TensorRT without the setting is refused
with a ValueError that names the installed version,
pytorch/TensorRT#5021 and Torch-TensorRT 2.15.1. A missing
Torch-TensorRT gets the same install hint that the compile step gives,
which moves into `ExportBackendConfig.install_error` for both.

Tested on CPU with PyTorch 2.15 and ExecuTorch 1.6:
- a backend whose `compile` takes only the program and the path still
  exports;
- a part's settings reach, through the trace and compile steps, a
  backend that takes them; in an export of a tiny Praxis-1, only
  `velocity` and `decoder` get them, and the other programs get no
  keyword argument;
- the TensorRT backend hands a part's settings to a fake Torch-TensorRT
  with its own, and refuses one that the fake does not have, and one
  that it already passes;
- a tiny Praxis-1's `velocity` and `decoder` ask for `grouped_mm_kernel`
  with `executorch_tensorrt`, and no part asks for anything with
  `executorch_cuda`;
- with `executorch_tensorrt`, the recipe refuses before the policy loads
  a fake Torch-TensorRT without the setting and a missing one, and goes
  on with one that has it; with `executorch_cuda` it checks nothing;
- a part refuses compile options that JSON cannot hold.
Each of these tests fails with its part of the change removed. The
export and Praxis-1 tests pass.

This branch has not been deployed

No deployments
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: converters Issues re: Specific op converters 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 documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants