Skip to content

feat: Add an INT8 Gemma 4 PLE runtime sidecar - #249

Closed
mihai-chiorean wants to merge 2 commits into
NVIDIA:mainfrom
mihai-chiorean:feat/int8-ple-sidecar
Closed

mihai-chiorean wants to merge 2 commits into
NVIDIA:mainfrom
mihai-chiorean:feat/int8-ple-sidecar

Conversation

@mihai-chiorean

Copy link
Copy Markdown

What does this PR do?

Type of change: new feature

This is the second of the two PRs for #188. It is stacked on #235 (the INT8 token-embedding sidecar), so until that PR lands the diff here shows two commits: cadb959 belongs to that PR and only 33b7272 belongs to this one. The second commit alone can be read at https://github.com/mihai-chiorean/TensorRT-Edge-LLM/pull/1/files (13 files). I will rebase onto main once the first PR lands, and I am keeping this one a draft until then.

Overview: Extends --int8-embedding to the Gemma 4 per-layer embedding (PLE) table.

  • Export: for a Gemma 4 E-model, --int8-embedding now also writes ple_embedding.safetensors as symmetric INT8 (weight, [vocab, layers * ple_hidden]) with FP32 scales weight_scale of shape [vocab, layers]: one scale per vocabulary row and per layer input, kept two-dimensional also for a single layer. A PLE row is the concatenation of every layer's input, so a single row scale would let an outlier in one layer cost precision in all the others. The quantizer gains a keyword-only num_groups parameter; the token embedding keeps the one-scale-per-row contract and metadata format (int8_symmetric_per_row) of feat: Add an INT8 token-embedding runtime sidecar #235, the PLE sidecar records int8_symmetric_column_groups_per_row. Unlike --fp8-embedding, which stores FP8 values with block scales for the token embedding only, this format covers the per-layer table, which has no FP8 option.
  • Runtime: Gemma4EmbeddingPreprocessor loads weight plus weight_scale, validates the scale dtype (FP32) and shape ([vocab, num_ple_inputs]) against the table at construction, and keeps its FP16 output buffer. gemma4PleGather takes an optional scales tensor as a new last parameter with a default (existing callers compile unchanged) and dispatches to gemma4PleGatherInt8Kernel, which dequantizes only the gathered rows into the FP16 per-layer inputs. As in the FP16/BF16 PLE gather, every image/audio placeholder position and out-of-vocabulary id is written as zeros (the PLE table has no multimodal rows; this differs from the token-embedding lookup, where placeholders receive encoder features). pleHiddenSize must be a multiple of 8, which the launcher checks. FP16/BF16 PLE sidecars load and gather exactly as before: an FP16/BF16 table with a weight_scale tensor, or an INT8 table without one, is rejected. A checkpoint-backed INT8 PLE table (direct checkpoint builder path) is rejected because that path owns no scales.
  • Tests: Python unit tests for the grouped quantizer (independent per-group scales, chunking, invalid groups), the PLE sidecar contract and metadata, the artifact writer producing both INT8 tables for a Gemma 4 model, two-dimensional scales for a one-layer model, and FP16 PLE without the flag; CUDA unit tests for the INT8 gather against a CPU reference that rounds through FP16 exactly as the kernel does (a small case, the Gemma 4 E4B geometry of 42 layers x 256 elements with ordinary, repeated, invalid and placeholder ids, and a 2056-element case that needs a partial final iteration), zero-fill and untouched padding, loading an INT8 sidecar through the preprocessor (two layers and one layer), the preprocessor's rejection messages (INT8 without scales, FP16 with scales, INT32 table, 1-D scales, wrong scale columns, non-FP32 scales) and gemma4PleGather's rejections (scales with an FP16 table, INT8 without scales, 1-D scales, wrong columns, non-FP16 output).
  • CI: the export verification in tests/defs also checks the INT8 PLE sidecar for Gemma 4 E-models, and the test lists gain test_checkpoint_export[gemma-4-E2B-it-fp16-int8emb] in l0_onnx_export_1.yml plus the matching test_engine_build and test_inference[...-int8emb-llm_basic] cases next to the existing Gemma 4 E2B FP16 smoke cases in l0_pipeline_thor_2_trt11.yml. I cannot run NVIDIA's CI, so these entries are untested there; the same export -> build -> inference sequence was run manually on a Jetson AGX Orin with Gemma 4 E4B and E2B (below).
  • Docs: the feature page gains the PLE rows of the sidecar contract, the per-layer-scale rationale and the PLE and combined memory rows; the "PLE stays FP16" limitation from the first PR is removed.

Memory for Gemma 4 E4B (vocabulary 262,144): PLE [262144, 10752] 5,637,144,576 bytes FP16 -> 2,862,612,480 bytes INT8 plus scales; together with the token embedding from the first PR, 6,979,321,856 -> 3,534,749,696 bytes.

Usage

tensorrt-edgellm-export /path/to/gemma-4-E4B-it /path/to/onnx --int8-embedding

ple_embedding.safetensors then holds:

Tensor dtype Shape
weight INT8 [vocab, layers * ple_hidden]
weight_scale FP32 [vocab, layers]

The runtime selects the INT8 path from the weight dtype; no runtime flag is needed.

Validation

Jetson AGX Orin 32 GB (SM87), JetPack 7.2 (L4T R39.2.1), CUDA 13.2.86, TensorRT 10.16.2.10, power mode MAXN with unlocked GPU clocks; candidate 33b727203027e3ffbc54d5833042ca568561a48a (on top of the first PR's cadb9590) built natively with -DBUILD_UNIT_TESTS=ON, baseline 0f52705 where stated.

  • Unit tests. The 12 unitTest* binaries were last run in full at 93f0582 (11 of 12 exit 0: unitTestCommon 149 passed; unitTestContextCache 203; unitTestCuteDslKernels 59; unitTestExamples 3; unitTestKernelsAttention 108 passed, 24 skipped (FP8 decode kernels); unitTestKernelsMisc 340 passed, 23 skipped, 1 failed; unitTestKernelsMoe 41 passed, 24 skipped; unitTestKernelsSpeculative 114; unitTestPlugins 17 passed, 1 skipped; unitTestRuntime 594 passed, 1 skipped; unitTestRuntimeState 113; unitTestScheduler 59). The one failure, RopePackedFusedNorm.PostRopeAccuracy, is a pre-existing flaky test with unseeded random inputs (0 failures in 30 repeats on this binary, 1 in 30 on the first PR's; posEncoding is untouched by both PRs). The only binary whose sources changed since then is unitTestKernelsMisc; at the final head it was rebuilt and run in full: 347 passed, 23 skipped, 0 failed (370 ran; the flaky RoPE test passed in this run). The embedding/PLE filter (--gtest_filter='*Embedding*:*Int8*:*Ple*:*Fp16Lookup*:*SidecarLoader*:*GatherRejects*'): 40 passed, including DequantizesInt8RowsAndZeroFillsSpecialTokens, DequantizesInt8RowsAtGemma4E4BGeometry (42 layers x 256, exact FP16 comparison), DequantizesInt8RowsWithPartialFinalIteration (2056), Int8SidecarLoadsThroughPreprocessor, Int8SidecarWithOneLayerLoadsThroughPreprocessor, Int8PleSidecarLoaderRejectsMalformedFiles and GatherRejectsMismatchedScalesAndOutputTypes.
  • Export -> build -> inference: google/gemma-4-E4B-it, W4A16 AWQ checkpoint (quant_algo W4A16_AWQ, group size 128, LM head FP16), text model exported on the device twice with this branch's exporter, with and without --int8-embedding (--skip-visual); model.onnx SHA256 b4c5c5897652d1761b2d41d75fd53f6e486a832899b45caf4b129b372985eefa and model.onnx.data SHA256 2033965e65ec6bc3d4af8c047d94e2c3945eb8d3bd4735f01a993ad2029a7172 identical for both exports; only the two sidecars differ. Both built with llm_build --maxBatchSize 1 --maxInputLen 2048 --maxKVCacheCapacity 4096 and run with llm_inference (temperature 0, 64 new tokens). INT8 engine log: Loaded INT8 embedding: [262144, 2560], scales: [262144] and Initialized Gemma4 PLE preprocessor: table=[262144, 10752] outputBuffer=[42, 1, 2048, 256]. The vision tower was exported separately (--skip-llm) and built with visual_build for the image runs below.
  • Output equivalence, 24 text prompts (22 short, one ~250 tokens, one ~500 tokens), 1218 (FP16) / 1216 (INT8) generated tokens, 1207 positions compared pairwise: 21 of 24 prompts token-identical; the three others first differ at token 8 (a haiku), 54 and 38 and continue with equivalent content. Image prompts (the four sample pictures under examples/multimodal/pics x 2 questions, greedy, 48 new tokens, accuracy engines plus the visual engine): 7 of 8 token-identical, 261 (FP16) / 258 (INT8) generated tokens; the one divergence is a different wording of the same description. Image placeholder positions in the PLE gather are zero-filled in both arms.
  • Baseline vs candidate on the same FP16 engine and sidecars (Qwen2.5-0.5B, 24 prompts): 0f52705 runtime vs this branch 24 of 24 identical.
  • MMLU (N=500, stratified by subject with proportional allocation from the full 14,042-question test set, seed 0; 5-shot prompts from examples/accuracy/scripts/prepare_dataset.py, chat template, greedy, 64 new tokens, engines built with --maxInputLen 8192 --maxKVCacheCapacity 10240 --maxBatchSize 1, the sentence "Answer with the option's letter from the given choices directly." appended to the end of each user message; scored with calculate_correctness.py as shipped): FP16 53.0 % (265/500), INT8 53.0 % (265/500); identical predictions on 489/500; flips 1 (FP16-only correct) / 1 (INT8-only correct), exact McNemar p = 1.0; 428/500 (FP16) and 429/500 (INT8) answers parsed to a letter, the rest are explanations cut by the budget. At 8 new tokens the same subset gives 254 / 255 with 497/500 identical (389/500 parsed). Wall time per arm 437 s / 412 s.
  • MMLU re-run with the letter instruction as a system turn (same 500 questions, same engines and build 33b7272; the instruction "Answer with the option's letter from the given choices directly. Reply with the letter only." moved from the end of the user message to a system turn, 16 new tokens instead of 64): FP16 64.6 % (323/500), INT8 64.6 % (323/500); identical predictions and identical output text on 500/500; flips 0 / 0, exact McNemar p = 1.0; 500/500 answers parsed in both arms. Wall time per arm 212 s. In this form the model answers with the letter instead of starting an explanation, which is where the parse misses and the 11 differing predictions of the run above came from.
  • MMStar (N=300, stratified by category from the full 1,500-item set, seed 0; upstream's prompt from prepare_dataset.py --dataset MMStar with the instruction "Answer with the option's letter from the given choices directly. Reply with the letter only." as a system turn, chat template, thinking off (the template's default), greedy, 32 new tokens, visual engine from this branch's exporter; scored with calculate_correctness.py as shipped): FP16 38.7 % (116/300), INT8 38.3 % (115/300); identical predictions on 299/300; flips 1 (FP16-only correct) / 0, exact McNemar p = 1.0; the parser scores 299/300 answers in both arms. With the same instruction appended to the user message instead, the model answers two thirds of the items with reasoning that reaches no letter within 8 or 128 new tokens (177/300 and 178/300 scored; FP16 87, INT8 86, identical 295/300 and 256/300). Wall time per arm 151 s.
  • Load-time rejection, llm_inference exit 1 before any request: INT32 PLE table -> gemma4EmbeddingPreprocessor.cpp:91: PLE table must be FP16, BF16, or INT8; INT8 PLE without scales -> :73: INT8 ple_embedding.safetensors must contain exactly weight and weight_scale; FP16 PLE with a weight_scale tensor -> :79: FP16/BF16 ple_embedding.safetensors must contain exactly one tensor named weight; INT8 PLE with [vocab] scales -> :97: INT8 PLE scales must be 2D [vocab, num_layers].
  • Soak, 300 requests x 16 tokens on the INT8 engine, sampled every 0.5 s: VmRSS 8519 MiB at 10 % of the run, 8523 MiB at 50 %; system RAM above baseline 6042 MiB -> 5891 MiB; 300 of 300 responses.
  • llm_bench cannot run Gemma 4 engines (binding ple_token_embeds_0 is not handled; the same failure for FP16 and INT8, llm_bench crashes on Gemma-4 engines due to missing PLE bindings (ple_token_embeds_0) #230), so speed comes from llm_inference --dumpProfile.
  • Python unit tests, host: tests/python-unittests/test_embedding_quantization.py and test_export_embedding_flags.py, 35 passed; the 9 cases added by this PR fail against the first PR's sources, the 26 shared cases pass there.

Memory, Gemma 4 E4B (0.5 s sampler of MemTotal - MemAvailable, MemFree and process VmRSS during the 24-prompt run; --dumpProfile peaks; the run was repeated with both sidecar sets already in the page cache, which is the state reported here):

FP16 INT8
embedding.safetensors 1,342,177,376 B 672,137,536 B
ple_embedding.safetensors 5,637,144,664 B 2,862,612,824 B
both sidecars 6,979,322,040 B 3,534,750,360 B (-3,444,571,680 B, 3.21 GiB)
peak system RAM above baseline during run 7698 MiB 4653 MiB (-3045 MiB)
profile peak_gpu_memory (cudaMemGetInfo free-memory delta, tool unit "MB") 7620 4567 (-3053)
peak process VmRSS 16061 MiB 10261 MiB

The profiler's figure is the drop of cudaMemGetInfo free memory from the start of the run to its minimum; on unified memory that drop also contains the page cache filled while the mmap'd sidecar files are first read, so a cold first run reported 10156 (FP16) vs 4536 (INT8). The warm-cache repeat above and the MemAvailable-based system figure agree with each other and with the file-size difference.

Second model, Gemma 4 E2B (W4A16 AWQ, 35 layers, hidden 1536, PLE 256 per layer; same device, same engine parameters, candidate 93f0582 build; cosine over all 262,144 token rows and 8,192 seeded PLE rows):

FP16 INT8
both sidecars 5,502,927,024 B 2,789,212,824 B (-2,713,714,200 B, 2.53 GiB)
prompts token-identical (of 24; 1231 / 1231 generated tokens) 23 (the other first differs at token 30)
MMLU-500, system turn, 16 new tokens, one engine built with --maxInputLen 8192 --maxKVCacheCapacity 10240 239 (47.8 %) 238 (47.6 %); FP16-only / INT8-only correct 2 / 1, identical predictions 497/500, 491/500 parsed in each arm, exact McNemar p = 1.0
token-embedding row cosine mean / min 0.999954 / 0.998866
PLE row cosine mean / min; per-layer-slice min 0.999973 / 0.999937; 0.999621
system RAM above baseline at "Runtime initialized" / peak 5,187 / 5,433 MiB 2,383 / 2,706 MiB (-2,727 MiB)
process VmRSS at "Runtime initialized" / peak 9,058 / 12,741 MiB 6,469 / 8,194 MiB
load time to "Runtime initialized", 3 runs (run 1 cold) 9.10 s then 5.50 / 5.27 s 4.81 s then 4.36 / 4.35 s

Quality of the E4B sidecars (FP16 table vs dequantized INT8, product rounded to FP16):

token embedding (all 262,144 rows) PLE (8,192 rows, seed 0, 42 layers)
row cosine mean / min / 1st percentile 0.999943 / 0.998034 / 0.999582 0.999970 / 0.999890 / 0.999963
per-layer-slice cosine mean / min 0.999969 / 0.999422
max / mean abs error (max abs weight) 0.11041 / 0.010122 (28.06) 0.06079 / 0.006712 (15.50)

Speed, E4B (llm_inference --dumpProfile, 20 identical requests after 2 warmup, GPU stage times; separately built engines):

FP16 INT8
short prompt (19 tok): prefill per run (TTFT) / decode median / p95 72.70 ms / 25.542 ms / 25.988 ms (40.0 tok/s) 67.20 ms / 25.693 ms / 26.099 ms (39.8 tok/s)
long prompt (846 tok): prefill per run (TTFT) / decode median / p95 376.00 ms (2250 tok/s) / 26.413 ms / 26.722 ms 366.05 ms (2311 tok/s) / 26.552 ms / 26.889 ms

Load time, E4B, process start to "Runtime initialized", 5 runs (run 1 after other work on the device, runs 2-5 warm): FP16 15.77 s then 6.93-7.61 s; INT8 9.40 s then 5.34-5.57 s.

Reproduce:

tensorrt-edgellm-quantize llm --model_dir google/gemma-4-E4B-it --output_dir gemma-4-E4B-w4a16-awq --quantization int4_awq
tensorrt-edgellm-export gemma-4-E4B-w4a16-awq onnx/e4b-fp16 --skip-visual
tensorrt-edgellm-export gemma-4-E4B-w4a16-awq onnx/e4b-int8emb --int8-embedding --skip-visual
tensorrt-edgellm-export gemma-4-E4B-w4a16-awq onnx/e4b-visual --skip-llm
sha256sum onnx/e4b-*/llm/model.onnx onnx/e4b-*/llm/model.onnx.data
for v in fp16 int8emb; do
  ./build/examples/llm/llm_build --onnxDir onnx/e4b-$v/llm --engineDir engines/e4b-$v/llm --maxBatchSize 1 --maxInputLen 2048 --maxKVCacheCapacity 4096
  ./build/examples/llm/llm_inference --engineDir engines/e4b-$v/llm --inputFile prompts24.json --outputFile out24-$v.json --dumpProfile --profileOutputFile prof24-$v.json
done
./build/examples/multimodal/visual_build --onnxDir onnx/e4b-visual/visual --engineDir engines/e4b-visual
./build/unittests/unitTestKernelsMisc --gtest_filter='*Embedding*:*Int8*:*Ple*:*Fp16Lookup*:*SidecarLoader*:*GatherRejects*'
# accuracy harness: prepare full MMLU and MMStar; draw seeded stratified subsets (500 by subject, 300 by category, seed 0);
# MMLU: append "Answer with the option's letter from the given choices directly." to each user message, max_generate_length 64;
# MMStar: add a system message "Answer with the option's letter from the given choices directly. Reply with the letter only.",
# keep the user message as prepared, max_generate_length 32; temperature 0 for both; engines built with --maxInputLen 8192 --maxKVCacheCapacity 10240
python3 examples/accuracy/scripts/prepare_dataset.py --dataset MMLU --output_dir mmlu_full
python3 examples/accuracy/scripts/prepare_dataset.py --dataset MMStar --output_dir mmstar_full
./build/examples/llm/llm_inference --engineDir engines/e4b-<v>-acc/llm --inputFile mmlu500_letter64.json --outputFile mmlu500-<v>.json
./build/examples/llm/llm_inference --engineDir engines/e4b-<v>-acc/llm --multimodalEngineDir engines/e4b-visual --inputFile mmstar300_sys.json --outputFile mmstar300-<v>.json
python3 examples/accuracy/scripts/calculate_correctness.py --predictions_file <pred>.json --answers_file <set>.json

Validation on a 16 GB Jetson Orin NX

Jetson Orin NX 16 GB, JetPack 7.2 (L4T R39.2.1), CUDA 13.2.86, TensorRT 10.16.2.10, 40 W power mode, 2 GB swap; binaries and plugin from this branch at 33b727203027e3ffbc54d5833042ca568561a48a, built natively on a Jetson AGX Orin. The Gemma 4 E4B W4A16 engine (llm_build --maxBatchSize 1 --maxInputLen 2048 --maxKVCacheCapacity 4096, llm.engine 3,432,620,228 bytes, the one validated above) was also built on the AGX Orin and copied over; one engine served both sidecar sets, since the ONNX graph does not contain the tables. TensorRT accepted it with two warnings on every load, quoted verbatim:

[WARNING] [TensorRT] The current device only supports 8 multiprocessors but the engine file requires 16. Deadlocking is likely.
[WARNING] [TensorRT] Using an engine plan file across different models of devices is not supported and is likely to affect performance or even cause errors or deadlock.

No deadlock or error followed in any of the 16 runs, and the generated text is identical to the AGX Orin's for every prompt that completed (12 of 12, both sidecar sets), so the INT8-vs-FP16 comparison on this device is on equal footing; the absolute latency figures are from a plan built for another device and should be read as provisional until an engine is built on an Orin NX (llm_build for E4B peaked near 12 GiB on the AGX Orin, which this device could not spare safely during the window).

The device was in use by another deployment: two other inference services kept running throughout (about 2 GB of RAM between them), and that deployment's own 10.7 GB LLM service was stopped for the 17-minute test window. Memory figures are therefore "with about 2 GB of other inference load present". Every test process ran with oom_score_adj 1000 under a 0.5 s watchdog that kills it below 500 MB MemAvailable or at 92 C junction temperature.

Memory (MiB; MemAvailable from /proc/meminfo, process VmRSS, profile peak_gpu_memory_mb = cuda_free_memory_delta):

INT8 sidecars (this PR) FP16 sidecars
sidecar bytes (token + PLE) 672,137,536 + 2,862,612,824 1,342,177,376 + 5,637,144,664
MemAvailable before the process 10,336 12,756 (page cache had been dropped by the previous runs)
drop at "Runtime initialized" 6,093 (avail 4,243) 10,844 (avail 1,911)
peak drop during the run 6,388 (min avail 3,947) 11,573 (min avail 1,182)
peak VmRSS 10,285 12,490
profile peak GPU / CPU 6,277 / 10,596 MB 11,543 / 12,505 MB
headroom above the 500 MB guard at peak 3.4 GB 0.7 GB
swap used during the run 782 → 788 MB (unchanged) 1,163 → 1,281 MB
fits yes, 3.9 GB available at the minimum yes, 1.2 GB available at the minimum

Both sets fit. The difference in peak drop between the two runs (5.2 GB) is larger than the 3.2 GiB difference between the sidecar files: the FP16 run started from a cold page cache and read 7 GB of sidecar files for the first time, and on the AGX Orin the same comparison with a warm cache gave 3.0 GB. I did not separate the two effects on this device, so the figure to rely on here is the minimum available memory observed, 3,947 MiB with INT8 and 1,182 MiB with FP16. The FP16 run was not stopped by memory: the 500 MB guard never fired and cudaMalloc never failed.

Latency (same engine, greedy, 64 new tokens; profile JSON after 2 warm-up runs where stated):

INT8, 24 prompts (76 prompt tokens/run avg) INT8, 19-token prompt x20 (2 warm-up) FP16, 12 prompts (24 prompt tokens/run avg)
prefill per run 208.7 ms (362 tok/s) 146.2 ms (130 tok/s) 148.4 ms (165 tok/s)
generation 59.91 ms/token, 16.7 tok/s 60.03 ms/token, 16.7 tok/s 60.00 ms/token, 16.7 tok/s
decode step median / p95 60.97 / 65.84 ms 60.93 / 65.45 ms 61.02 / 65.32 ms
end-to-end wall 15.6 tok/s 15.9 tok/s 15.8 tok/s

No decode-speed difference between the two sidecar sets at this resolution (the sidecar is read once per token for a handful of rows). The long-prompt profile (20 x 2,000-token prompt) and the FP16 short-prompt profile could not be completed: the device started every run at 79–81 C junction temperature and reached the 92 C guard after 25–130 s of sustained generation (INT8 long x20 stopped at 1/20, INT8 100-request soak at 40/100 after 63 s with no errors, FP16 24 prompts at 14/24, FP16 short x20 at 18/20). The AGX Orin numbers above remain the only long-prompt and soak figures.

Output agreement, FP16 vs INT8, 12 prompts (both completed on this device): 10 of 12 identical; the two divergences are at token 8 (prompt 7: 23 vs 21 tokens) and token 54 (prompt 9: 64 vs 64), 581 re-tokenized positions compared, 588 vs 586 tokens generated. The AGX Orin gave the same 10 of 12 on these prompts, and the text from this device is identical to the AGX Orin's for all 12 prompts with the FP16 set and all 12 with the INT8 set. Of the remaining 12 prompts, FP16 completed 11 before the thermal guard and the file was not written; INT8 completed all 24.

Load time (first log line to "Runtime initialized", 3 runs each, warm page cache): INT8 10.5 / 11.4 / 11.5 s (process wall 14.1–15.9 s); FP16 21.7 / 23.7 / 24.8 s (wall 27.1–35.7 s). The FP16 PLE table alone is 5.6 GB to read and stage.

Temperatures: junction 74 C before the window, 79–81 C between runs with the two other inference services, 91–94 C under sustained generation (the guard fired at 92 C, 94.4 C was the highest sample). Power mode 40 W throughout, not changed.

Scope of this section. Both sidecar sets fit a 16 GB Orin NX with about 2 GB of other inference load present: INT8 with 3.9 GB available at the minimum, FP16 with 1.2 GB. Not covered here: the long-prompt profile, a completed soak (the thermal guard ended both), and an engine built on the Orin NX itself (the AGX-built plan ran correctly but with the TensorRT device-mismatch warning quoted above). The FP16-vs-INT8 agreement set is 12 prompts on this device; the other 12 are covered on the AGX Orin.

Orin NX 16 GB, second run: engines built on the device

Jetson Orin NX 16 GB, JetPack 7.2 (L4T R39.2.1), CUDA 13.2.86, TensorRT 10.16.2.10, 40 W power mode, this branch at 33b7272. Unlike the earlier Orin NX numbers above (engine built on an AGX Orin, about 2 GB of other inference load present), here llm_build and visual_build ran on the Orin NX itself and no other inference load was on the device. Gemma 4 E4B W4A16, --maxInputLen 3072 --maxKVCacheCapacity 3328. One engine served both sidecar sets; the two arms differ only in the two sidecar files.

Build on the device: llm_build 227 s, peak RSS 12,250 MiB; visual_build 533 s, peak RSS 3,080 MiB.

Memory and load

INT8 sidecars FP16 sidecars
sidecar bytes (token + PLE) 672,137,536 + 2,862,612,824 1,342,177,376 + 5,637,144,664
minimum MemAvailable during any run 6,358 MiB 3,115 MiB
load to "Runtime initialized" (3 runs, warm page cache) 8.6–8.9 s 21.5–22.6 s

Speed (greedy, 19-token prompt x20, 2 warm-up runs)

INT8 sidecars FP16 sidecars
prefill 101.4 ms 101.4 ms
generation 41.18 ms/token (24.3 tok/s) 41.14 ms/token (24.3 tok/s)

The engine built on the device decodes about 1.46x faster than the AGX-built plan used in the earlier Orin NX run (41.1 vs 60.0 ms/token), so the earlier absolute speed figures should not be read as this device's speed.

Accuracy, paired (same seeded subsets and harness as the AGX Orin section, letter instruction in a system turn, 16 new tokens, greedy)

FP16 INT8 FP16-only / INT8-only correct identical predictions parsed McNemar exact p
MMLU-500, Orin NX 323 (64.60 %) 323 (64.60 %) 0 / 0 499 / 500 500 / 500 each 1.000
MMLU-500, AGX Orin, same prompts 323 (64.60 %) 323 (64.60 %) 0 / 0 500 / 500 500 / 500 each 1.000
MMStar-300, Orin NX 116 (38.67 %) 116 (38.67 %) 0 / 0 300 / 300 299 / 300 each 1.000

On the one MMLU question where the arms differ, both are wrong. The Orin NX INT8 predictions equal the AGX Orin INT8 predictions on all 500 MMLU questions.

Method: MMLU and MMStar are the public benchmarks, prepared with examples/accuracy/scripts/prepare_dataset.py and scored with the letter parser from examples/accuracy/scripts/calculate_correctness.py. The subsets are the stratified, seed-0 samples described in the AGX Orin section. On the Orin NX the requests were sent through the Python binding by a small driver that keeps the model loaded and pauses for cooling, not through llm_inference; the request files are the same.

Output agreement, 24 greedy prompts, 64 new tokens: 22 of 24 identical between the FP16 and INT8 sets.

Other INT8 runs that completed: 846-token prompt x20 (prefill 778.7 ms), and a 100-request soak with no errors.

Not covered: the FP16 long-prompt profile and FP16 soak. At 40 W the board reaches my 88 C stop limit under sustained generation, so the accuracy runs were paced with cooling pauses and those two FP16 runs were cut short by heat, not memory.

Scope and remaining validation

  • The INT8 unit tests also pass on a Jetson Orin Nano 8 GB with CUDA 12.6 / TensorRT 10.3 (embedding and PLE filter 34 passed, unitTestKernelsMisc 341 passed, 47 skipped, at 93f0582); no engine could be built on that device with its TensorRT, so no inference numbers from it.
  • Top-1 next-token logit agreement is not measured; llm_inference does not expose logits.
  • The Qwen3-Omni Talker guard inherited from the first PR has no unit test: constructing Qwen3OmniTTSRuntime needs engines.
  • The PLE gather kernel was not timed in isolation; its share of an 846-token prefill is below the run-to-run noise of the TTFT numbers above, which also come from two separate engine builds.
  • llm_bench prefill/decode micro-benchmarks are not available for Gemma 4 engines (llm_bench crashes on Gemma-4 engines due to missing PLE bindings (ple_token_embeds_0) #230).
  • The l0_pipeline_thor_2_trt11.yml and l0_onnx_export_1.yml entries were not run in NVIDIA's CI; the commands above are their manual equivalent.
  • Absolute accuracies are for a W4A16 AWQ model answering with a bare letter and no reasoning; they are below published full-precision figures for 4B-class Gemma models and are not comparable to them. The MMLU parser misses 14 % of the 64-token answers (explanations cut by the budget), so the MMLU accuracies of that run are lower bounds; the system-turn re-run parses all 500. The paired agreement on all items is the primary result.
  • An earlier version of this description said the FP8 token-embedding path cannot run on SM87. That was wrong: --fp8-embedding ran end to end on the AGX Orin (see feat: Add an INT8 token-embedding runtime sidecar #235). It covers the token embedding only; there is no FP8 option for the PLE table.

🚀 Pull Request Checklist

✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit.
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues. (Every file changed by this PR passes all hooks. On current main, yapf and clang-format reformat 13 files that this PR does not touch, and the same 13 are the only files reformatted on this branch.)

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing. (Host Python tests and the device unit tests above, with the pre-existing flaky RopePackedFusedNorm.PostRopeAccuracy noted; the three new CI test-list entries have not run in NVIDIA's CI.)

📄 Documentation

  • Updated any necessary documentation

⚙️ Compatibility

  • The change is backward compatible. FP16 and BF16 PLE sidecars and all existing calls are unchanged (gemma4PleGather gains a trailing defaulted parameter; quantize_embedding_to_int8 gains a keyword-only one). Behaviour that does change, all verified: an FP16/BF16 PLE table with a stray weight_scale tensor now fails at construction where the extra tensor was previously rejected by the "exactly one tensor" check with a different message; an INT8 PLE table is accepted where it was previously rejected; a checkpoint-backed INT8 PLE table is rejected; gemma4PleGather rejects scales passed with an FP16/BF16 table.

Additional Information

Related issue: #188. The first PR is #235.

Two implementation notes:

  • The INT8 gather launcher sizes its block to the layer slice (pleHiddenSize / 8 vectors rounded up to whole warps, at most 256 threads) instead of a fixed 256 threads, because for Gemma 4 E4B a slice is 256 elements, i.e. 32 vectors, and a 256-thread block would leave seven of its eight warps idle. The existing FP16/BF16 launcher is not changed.
  • The --fp8-embedding pass-through that my fork added to tests/defs/test_checkpoint_export.py is not included; it is unrelated to this change.

Alternatives considered: extending --fp8-embedding to the per-layer table would be the other way to quantize it; per-row, per-layer INT8 scales match that table's structure and reconstructed more closely on the token table measured in the first PR, and FP8 on the per-layer table was not measured.

Add `--int8-embedding` to tensorrt-edgellm-export. It writes
embedding.safetensors as symmetric INT8 with one FP32 scale per row,
mutually exclusive with `--fp8-embedding`. The runtime dequantizes only
the gathered rows in the embedding lookup kernel, so the table never
expands to FP16 in device memory.

loadEmbeddingTable now validates the table dtype at load: FP16, FP8 and
INT8 are accepted, anything else is rejected with the dtype and path,
and an embedding_scale tensor beside an FP16 table is an error. The
Qwen3-Omni talker rejects a quantized thinker embedding sidecar because
it reads that table as dense FP16.

Signed-off-by: Mihai Chiorean <[email protected]>
With `--int8-embedding`, a Gemma 4 E-model export also writes
ple_embedding.safetensors as symmetric INT8 with one FP32 scale per
vocabulary row and layer input, so an outlier in one layer does not cost
precision in the others. Gemma4EmbeddingPreprocessor loads `weight` plus
`weight_scale`, validates the scale dtype and shape against the table,
and gemma4PleGather dequantizes only the gathered rows into the FP16
per-layer inputs. FP16 and BF16 PLE sidecars load and gather unchanged.

Signed-off-by: Mihai Chiorean <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nvluxiaoz

Copy link
Copy Markdown
Collaborator

Thanks @mihai-chiorean . This MR is recognized in our latest release/0.12.0 notes. We have integrated both quantize time embedding quantization and build time embedding quantization, and disk offloading to support PLE well. Thanks a lot for your contribution!

@mihai-chiorean

Copy link
Copy Markdown
Author

Thanks @nvluxiaoz, and thank you for the credit in the 0.12.0 release notes. I appreciate it.

I tried 0.12.0 on a Jetson AGX Orin with Gemma 4 E2B. The cached PLE residency does what this PR was after: the per-layer table no longer sits in memory (about 5.4 GiB down to 2.0 GiB of system memory during a run, same replies), and --fp8-embedding halves the token table on Orin as well. That covers the need behind this PR, so I'm closing it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants