Skip to content

Alpamayo 2 Edge export to ExecuTorch with TensorRT: how to reproduce from source #25253

Open

Description

@shoumikhin

NVIDIA's Alpamayo 2 Edge (a vision-language-action model for driving, NVlabs/alpamayo2-edge), exported with ExecuTorch (PyTorch's solution for deploying models on devices) and Torch-TensorRT, runs every part of the model in TensorRT engines on the GPU. It gives the same reasoning tokens as the PyTorch model. On Jetson AGX Thor it is faster than the model's own PyTorch path, both default and tuned. On DGX Spark it matches the tuned path, and on A100 the tuned path is still faster. Against the default PyTorch path it is 1.7x to 3x faster on every GPU tested. Below are the numbers, measured the same way for both, how to reproduce them, and the places where TensorRT and Torch-TensorRT can still improve.

Results

One full prediction (vision encoder, prefill, 6 reasoning tokens, 10 action expert steps), batch 1, greedy:

GPU ExecuTorch + TensorRT PyTorch, default PyTorch, tuned (--accel tuned) Time saved vs default / tuned GPU memory, GiB (ExecuTorch + TensorRT / tuned PyTorch)
Jetson AGX Thor 495 ms 1067 ms 590 ms 54% / 16% 10.5 / 6.6
DGX Spark 611 ms 1038 ms 617 ms 41% / same not measured / 6.7
A100 273 ms 821 ms 217 ms 67% / 26% slower 11.0 / not measured

Time per stage for ExecuTorch + TensorRT, in ms (A100 / Spark / Thor): vision 96 / 213 / 147, prefill 63 / 159 / 115, decode (6 tokens) 51 / 110 / 104, expert (10 steps) 64 / 128 / 129.

How it was measured: both sides ran on the same GPU, on the synthetic sample from the package's tests (22 camera images, a 3256-token prompt), and are timed over the same span, from the vision encoder to the last expert step. Prompt preparation before it and the conversion to poses after it are not included. Each number is the median of 9 or more warm runs with nothing else on the GPU. GPU memory is the per-process number from nvidia-smi. PyTorch runs the package's predict with top_k=1 on PyTorch 2.15.0; the tuned path uses flash-attn 2.8.3. The TensorRT delegate replays CUDA graphs for decode and expert_step.

Accuracy, against the PyTorch model on the same inputs:

  • The reasoning tokens are identical on all 3 GPUs. The predicted path (64 future poses) differs by at most 0.7 cm on Thor, 1.1 cm on Spark and 1.1 to 1.5 cm on A100 (depending on the build).
  • Over 64 synthetic inputs on A100, the path differs by 3.0 cm median and 9.2 cm max. For scale: PyTorch against itself with a different attention kernel differs by 3.5 cm median and 20 cm max.

Notes:

  • The model is nvidia/Alpamayo2-Edge at b92b6aa3, with the alpamayo2_edge package at 02f55a7. Precision is bfloat16, with the vision tower's layer norms and GELU in float32 (see gap 3 below).
  • The export is two programs: vision.pte (one method per camera patch grid) and text.pte with prefill, decode and expert_step. The three text methods share one static key/value (KV) cache in GPU memory, and every engine writes its part of the cache in place, with no copies.
  • The tuned PyTorch path needs flash-attn built for the GPU; on Thor that build took 14 minutes. The exported programs do not need it.
  • Thor shares one memory between CPU and GPU. Counted for the whole board, the gap there is 11.8 against 9.4 GiB.
  • Jetson Orin Nano (8 GB) does not fit yet: the programs alone are larger than its memory (see gap 2).
  • All rows ran on pre-release revisions of the pull requests below, with ExecuTorch built from main. The branches under "How to reproduce" gave the same times on A100 (267 to 273 ms) and the same tokens.

Compared with NVIDIA's TensorRT Edge-LLM recipe

NVIDIA's Alpamayo2-Edge recipe for TensorRT Edge-LLM, built unmodified and run on the same Jetson AGX Thor with the same weights, prompt, pixels and noise, and TensorRT 11.4 on both sides. Its draft model is not public, so both sides decode greedily. Both timers run from the first vision call to the last expert step. Median of 21 warm runs.

Settings: 1 trajectory, 10 expert steps, all 22 frames encoded every call.

Stage, ms ExecuTorch + Torch-TensorRT, bfloat16 Edge-LLM recipe, FP16
Vision 148.5 116.6
Prefill 113.4 119.2
Reasoning tokens 102.8 98.5
Action expert 126.4 48.9
Total 491.7 383.5
Peak GPU memory per process 10.8 GB 12.6 GB
Largest path error vs PyTorch 0.8 cm 8.9 cm

On A100 the same comparison gives 266 ms against 200 ms. Both sides produce the same tokens as PyTorch.

  • Prefill and reasoning tokens are even. The gap is in vision (vision attention, gap 6 below) and in the action expert. The recipe runs all expert steps in one engine call and the example calls one engine per step, but that is not the main cost: exporting all 10 steps as one engine saves only 10.6 ms on Thor (126.4 to 115.8 ms), and nothing with 6 trajectories and 5 steps. The rest is the work inside each step, mostly gaps 1 and 4.
  • With its published settings except the draft model (FP8, 6 trajectories, 5 steps, cached frames, reduced vocabulary), the recipe takes 206 ms on Thor. The same settings without FP8 take 322 ms. FP8 calibration needs real camera frames, so its accuracy on our synthetic sample is not meaningful. With the same settings in bfloat16 the ExecuTorch side takes about 355 ms on Thor; FP8 through TensorRT Model Optimizer and Torch-TensorRT does not lower it yet (gap 6).

What it needs on top of the releases

Torch-TensorRT 2.15.0, plus one stack of changes, each building on the one before:

And in its ExecuTorch runtime, only for CUDA graphs:

ExecuTorch 1.6.0, plus one pull request, so that the three text methods share one cache in GPU memory:

With only the released packages, the export stops at prefill: expected one TensorRT engine: the cache writes fall back to PyTorch and prefill splits into 57 pieces.

How to reproduce

Everything is on public branches, pinned by commit. They carry earlier versions of the pull requests above, split differently, plus a few changes the example does not need. They were built and run on A100:

Project Branch Commit
Torch-TensorRT alpamayo-repro-2.15 (on v2.15.0) 9189b9fe5e
ExecuTorch alpamayo-repro-1.6 (on v1.6.0) a42737b505
Alpamayo 2 Edge NVlabs/alpamayo2-edge#13 6047e7585d

The first two are on github.com/shoumikhin/TensorRT and github.com/shoumikhin/executorch.

1. Build ExecuTorch, with the CUDA 13.2 toolkit in CUDA_HOME and its nvcc on PATH (the checkout folder must be named executorch):

git clone --recurse-submodules --shallow-submodules https://github.com/shoumikhin/executorch -b alpamayo-repro-1.6 executorch
git -C executorch checkout a42737b505
pip install torch==2.15.0 numpy "cmake>=3.29,<4.0" pyyaml setuptools wheel ninja pybind11 zstd tomli packaging ruamel.yaml patchelf certifi flatbuffers
CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON" TORCH_CUDA_ARCH_LIST="8.0;9.0" BUILD_VERSION=1.6.0+alpamayo \
  pip wheel ./executorch --no-build-isolation --no-deps -w dist

2. Build Torch-TensorRT and its ExecuTorch runtime. On x86_64, inside pytorch/manylinux2_28-builder:cuda13.2 with bazel 8.4.2, with the ExecuTorch wheel from step 1 in ../dist:

git clone https://github.com/shoumikhin/TensorRT -b alpamayo-repro-2.15 && cd TensorRT && git checkout 9189b9fe5e
export PATH=/opt/python/cp312-cp312/bin:/usr/local/cuda-13.2/bin:$PATH CUDA_HOME=/usr/local/cuda-13.2
pip install --index-url https://download.pytorch.org/whl/test/cu132 torch==2.15.0+cu132
pip install "setuptools>=77" wheel ninja pyyaml packaging numpy "pybind11==2.6.2" cffi
export TORCH_INSTALL_PATH=$(python -c 'import torch,os;print(os.path.dirname(torch.__file__))')
export CU_VERSION=cu132 CHANNEL=test BUILD_VERSION=2.15.0+alpamayo \
  TENSORRT_CUDA_VERSION_UPPER_BOUND=13.4 TENSORRT_RTX_CUDA_VERSION_UPPER_BOUND=13.4
envsubst < toolchains/ci_workspaces/MODULE.bazel.tmpl > MODULE.bazel
export CI_BUILD=1 RELEASE=1 TORCH_TENSORRT_EXECUTORCH_RUNTIME_VERSION=0.2.1 TORCH_TENSORRT_EXECUTORCH_RUNTIME_CHANNEL=pypi
python setup.py bdist_wheel --release
pip install dist/torch_tensorrt-*.whl tensorrt-cu13==11.4.0.106 patchelf
pip install --no-deps --force-reinstall ../dist/executorch-1.6.0+alpamayo-*.whl
TORCH_TENSORRT_ALLOW_UNPINNED_EXECUTORCH=1 pip wheel --no-build-isolation --no-deps -w dist py/torch-tensorrt-executorch-runtime

For Jetson AGX Thor and DGX Spark, build both on the board, with TORCH_CUDA_ARCH_LIST="11.0;12.1" for ExecuTorch.

3. Install, export and run, with Python 3.12 and nvcc (CUDA 12.8 or newer) on PATH. The first export takes about 6 to 7 minutes on an A100 and writes about 10 GB.

# from the folder that holds dist/ (step 1) and TensorRT/ (step 2)
pip install torch==2.15.0 torchvision "TensorRT/dist/torch_tensorrt-2.15.0+alpamayo-<platform>.whl[executorch]" \
  TensorRT/dist/torch_tensorrt_executorch_runtime-0.2.1-*.whl dist/executorch-1.6.0+alpamayo-*.whl
git clone https://github.com/NVlabs/alpamayo2-edge && cd alpamayo2-edge
git fetch origin pull/13/head && git checkout FETCH_HEAD
pip install --no-deps -e . && pip install -r examples/executorch_tensorrt/requirements.txt
python examples/executorch_tensorrt/export.py --model-id <model dir>
python examples/executorch_tensorrt/run.py --model-id <model dir> --runs 21 --cuda-graphs --check

run.py prints the time of each stage and, with --check, compares the tokens and the path with the PyTorch model.

Where to improve next

These are open, measured on A100 unless noted, and ranked by what they would gain. Gaps 1 to 4 and 6 need work in TensorRT or Torch-TensorRT; gap 5 is ExecuTorch and example work.

1. Attention for a few queries over a long cache. This is the whole gap against tuned PyTorch on A100.

  • In the decode engine, TensorRT's fused attention takes 194 µs per layer for 1 query over the 4096-slot cache; FlashAttention's split-KV kernel takes 27 µs. For the expert step (64 queries) it is 150 against 34 µs. Over 28 layers that is 28 ms of decode and 32 ms of expert time per prediction.
  • With 1 query, TensorRT picks a kernel that runs one thread block per query head. It has a kernel that splits the cache, and forcing it with the valid length given as key_value_lengths makes this attention 5x to 8x faster, but TensorRT does not pick it for bfloat16, and it gives wrong results with a bool mask (bf16 decode attention picks _gemv_mha_v1, 5x to 8x slower than _gemv_mha_v2, and _gemv_mha_v2 is wrong with a bool mask NVIDIA/TensorRT#4947). With 64 queries there is no split kernel.
  • Splitting the cache by hand into chunks with a log-sum-exp combine makes decode attention 2.3x and expert attention 1.3x faster, with the same tokens.
  • Wanted: TensorRT picks its split kernel for 1 query and gets the mask right, and adds a split path for a few dozen queries; Torch-TensorRT passes the valid length as key_value_lengths. Our estimate is about 210 ms total on A100, below tuned PyTorch.

2. Weights stored once per engine. This costs memory.

  • prefill and decode each hold the language model weights (about 4 GB), so text.pte is 8.3 GB; vision.pte is 2.0 GB; the checkpoint is 5.3 GB. This is most of why ExecuTorch uses more memory than tuned PyTorch.
  • Wanted: build or refit several engines from one set of named weights in the .ptd file, or put prefill and decode into one engine with two optimization profiles. Either could bring memory near the checkpoint size, and one of them is needed for Jetson Orin Nano, where building the decode engine also ran out of memory.

3. Precision of normalization inside bfloat16 engines.

  • In plain bfloat16 the path drifts several times more than PyTorch's own noise: Torch-TensorRT builds GELU and layer norm as bfloat16 layers and TensorRT computes them in bfloat16, while PyTorch computes them in float32 internally. In float16, TensorRT's matrix multiplications move the path too far.
  • Forcing the vision tower's layer norms and GELU to float32 matches float32 accuracy at half the vision time; full float32 costs about 95 ms more on A100. Torch-TensorRT's autocast setting did not reach the same result.
  • Wanted: Torch-TensorRT's converters compute GELU and normalization in float32 inside bfloat16 engines, as PyTorch does, without forcing whole layers to float32 (bfloat16 layer norm and GELU round more than PyTorch: the converters do not keep PyTorch's float32 math TensorRT#5083).

4. Attention with several queries copies the cache on every call, and an expanded mask slows it further.

  • With more than one query, TensorRT copies each layer's keys and values into another layout on every call (about 50 µs per layer at 4096 slots). This happens with or without grouped-query attention. Separately, the expert step's mask, made with .expand(1, 1, 64, -1) in the example's code, makes the attention kernel about 20% slower in TensorRT 11.4 than a broadcast mask of shape [1, 1, 1, S], which gives the same result; TensorRT 11.5 no longer shows this. Switching to the broadcast mask saves 6.6 ms per prediction end to end. The example will switch to it.
  • Wanted: multi-query attention reads the cache where it is, as the single-query kernel already does.

5. Host copies between programs.

  • The image embeddings go from vision to host memory and back into prefill (about 13 MB), through pageable memory. Pinned memory and stacking during prompt preparation saved about 6 ms.
  • Wanted: keep the vision outputs on the GPU for prefill, using device-memory inputs and outputs in the ExecuTorch runtime.

6. Lower precision and vision attention. FP8 weights and activations (TensorRT Model Optimizer, the same layers as the Edge-LLM recipe) on Thor make prefill 30% faster, leave decoding and the expert about the same, and make the vision tower twice as slow, so the total does not change. NVFP4 is untried; INT8 weight-only gave no gain on A100. An FP8 KV cache, as the Edge-LLM recipe uses, is also untried: the cache is a bfloat16 buffer that each engine updates in place, and that update has not been tried with an FP8 buffer. Vision attention (head size 72) takes 14.5 ms in TensorRT against about 8.7 ms in FlashAttention at the same shapes.

Speculative decoding and other caching in the graph

The pieces these need are in place: one KV cache shared by several methods in GPU memory, and engines that write many tokens into it in place.

  • Speculative decoding: a draft model can be one more method on the same cache. The verify step is a multi-token write like expert_step; rejected tokens need no rollback, since the attention mask hides them and the next write overwrites them.
  • Other caches, such as vision embeddings kept across frames or a reused prompt prefix, can be more shared buffers between methods, in GPU memory.

Which scheme (draft model, Eagle, multi-token prediction) and which caches matter most for this model? We can add them to the example.

Questions, and results on other GPUs, are welcome here.

cc @narendasan

Activity

  1. narendasan commented on Nov 19, 2026

    @narendasan

    Drafters we have evaluated include domino and DFlash2

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