Skip to content

Commit f63db93

Browse files
authored
[TRTLLM-17209][feat] Qualify FP8 block-scale weights for MX (Qwen3 dense) (#20766)
Signed-off-by: Michal Guzek <mguzek@nvidia.com>
1 parent 306b42f commit f63db93

12 files changed

Lines changed: 1186 additions & 53 deletions

File tree

‎docs/source/features/model-express.md‎

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ profiles:
2727
|---------|------------|-----------------|-------|----------|----------------------|-------------|
2828
| `llama-for-causal-lm-target-v1` | `LlamaForCausalLM` | `LlamaForCausalLM` / `llama` | Target model | 1 | `trtllm-llama-target-layout-v1` | Single-node dense BF16, unquantized weights and KV cache, TRTLLM attention, default fused RoPE, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
2929
| `qwen2-for-causal-lm-bf16-target-v1` | `Qwen2ForCausalLM` | `Qwen2ForCausalLM` / `qwen2` | Target model | 1 | `trtllm-qwen2-dense-target-layout-v1` | Single-node dense BF16, unquantized weights and KV cache, TRTLLM attention, default fused RoPE, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
30+
| `qwen3-for-causal-lm-fp8-block-sm90-target-v1` | `Qwen3ForCausalLM` | `Qwen3ForCausalLM` / `qwen3` | Target model | 1 | `trtllm-qwen3-dense-fp8-block128-fp32scale-target-layout-v1` | Single-node dense BF16, FP8 block-scale (128x128) weights and unquantized KV cache, SM90 only, TRTLLM attention, default fused QK-norm/RoPE, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
3031
| `qwen3-for-causal-lm-bf16-target-v1` | `Qwen3ForCausalLM` | `Qwen3ForCausalLM` / `qwen3` | Target model | 1 | `trtllm-qwen3-dense-target-layout-v1` | Single-node dense BF16, unquantized weights and KV cache, TRTLLM attention, default fused QK-norm/RoPE, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
3132
| `mistral-for-causal-lm-bf16-target-v1` | `MistralForCausalLM` | `MistralForCausalLM` / `mistral` | Target model | 1 | `trtllm-mistral-dense-target-layout-v1` | Single-node dense BF16, unquantized weights and KV cache, TRTLLM attention, default fused RoPE, no sliding window, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
3233
| `phi3-for-causal-lm-bf16-target-v1` | `Phi3ForCausalLM` | `Phi3ForCausalLM` / `phi3` | Target model | 1 | `trtllm-phi3-dense-target-layout-v1` | Single-node dense BF16, unquantized weights and KV cache, TRTLLM attention, default fused RoPE, untied embeddings, TP=1 or 2, PP/CP=1, no LoRA, sparse attention, attention DP, speculative mode, or separately loaded draft model |
@@ -36,9 +37,12 @@ profiles:
3637
The registry matches the exact root class, the architecture/model type captured
3738
from the resolved config before model construction, the transfer scope that
3839
`ModelLoader` derives from the constructed root, and any runtime constraints
39-
declared by the profile. An unregistered subclass, config alias, or undeclared
40-
runtime variant does not inherit support. It falls back to the standard Hugging
41-
Face checkpoint path before any P2P transfer starts.
40+
declared by the profile. Profiles whose post-transform layout depends on the GPU
41+
architecture also constrain the SM version of the device that runs the load. An
42+
unregistered subclass, config alias, or undeclared runtime variant does not
43+
inherit support. It falls back to the standard Hugging Face checkpoint path
44+
before any P2P transfer starts, and a donor that does not qualify does not
45+
publish its weights.
4246

4347
The Scope column names the part of the model that one transfer carries. A
4448
text-only root transfers the target model. A multimodal root transfers the
@@ -125,41 +129,61 @@ TP=2 the profile admits MoE TP=2 (the default) and MoE EP=2
125129
(`moe_expert_parallel_size: 2`), so MoE TP x MoE EP always equals TP. MoE
126130
cluster parallelism, the MoE load balancer, and DWDP fall back.
127131

132+
The Qwen3 FP8 block-scale identity covers `Qwen3ForCausalLM` / `qwen3`
133+
checkpoints whose quantization resolves to `FP8_BLOCK_SCALES`, whose Hugging
134+
Face quantization config declares `weight_block_size: [128, 128]`, and that run
135+
with an unquantized KV cache; Qwen3-8B-FP8 (`quant_method: fp8`, dynamic
136+
activations) is the qualified canary. Sources that resolve to the same algorithm
137+
without declaring that block size, such as static-activation FP8 checkpoints or
138+
ModelOpt and compressed-tensors block FP8 exports, do not match this profile,
139+
and neither do per-tensor FP8 checkpoints (ModelOpt `FP8`), an FP8 KV cache, or
140+
any GPU other than SM90. On SM100-family GPUs (by default) and SM120/121 GPUs,
141+
`transform_weights()` resmooths the weights to power-of-two scales and repacks
142+
the scales for DeepGEMM, and SM107 can use a CuTe DSL scale layout, so the SM90
143+
tensors are not valid there. Such loads fall back to the Hugging Face path.
144+
`SourceIdentity` does not record the SM version, so this profile constraint is
145+
what keeps the SM90 layout on SM90.
146+
128147
TensorRT LLM applies two independent compatibility gates:
129148

130149
- The qualification profile records that a model/config/lifecycle combination
131150
has passed full-load versus staged-load equivalence testing.
132-
- `SourceIdentity` format version 3 binds two concrete runs to the same
151+
- `SourceIdentity` format version 4 binds two concrete runs to the same
133152
checkpoint artifact, runtime layout choices, local shard layout, and
134-
transform-layout ABI.
153+
transform-layout ABI. Quantization exclusion patterns compare as a set, so
154+
their order in the checkpoint's config does not matter.
135155

136156
The transfer protocol version identifies the staged receiver protocol. The
137157
transform-layout ABI identifies the meaning of the transferred tensor names,
138-
layouts, aliases, and receiver finalization. A pre-version-3 identity, a
139-
missing ABI, or a different ABI is rejected rather than treated as compatible.
158+
layouts, aliases, and receiver finalization. An identity of another format
159+
version, a missing ABI, or a different ABI is rejected rather than treated as
160+
compatible.
140161

141162
Loads that require a separately loaded draft model also fall back to the
142163
standard checkpoint path. Target-plus-draft post-transform transfer remains
143164
disabled until layout state is tracked and qualified independently for each
144165
submodel.
145166

146-
The Llama, Qwen2, Qwen3, Mistral, Phi3, and Qwen3 MoE profiles are text-only
147-
and do not enable reward-model, embedding, or vision-language roots; Qwen3 MoE
148-
is the only qualified MoE root. FP16, quantized weights or KV cache, alternate
149-
attention backends, YaRN or LongRoPE scaling, tied embeddings, TP greater than
150-
2, PP greater than 1, CP greater than 1, LoRA, sparse attention, attention DP,
151-
multi-node transfer, and speculative decoding require separate qualification
152-
rows. Each profile also pins its qualified RoPE realization: Llama, Qwen2,
153-
Mistral, and Phi3 require the default fused RoPE path, so unfused RoPE requires
154-
separate qualification for them, while Qwen3 and Qwen3 MoE fuse RoPE into the
155-
QK-norm kernel and therefore require `rope_fusion=False` in the realized
156-
configuration. The Mistral profile additionally pins the realized attention
157-
window: every attention layer must run without a sliding window, so
158-
sliding-window checkpoints such as Ministral fall back to the Hugging Face path
159-
until they are qualified separately. The dense profiles do not constrain
160-
MoE-only backend and mapping settings because dense roots do not consume them;
161-
the Qwen3 MoE profile pins them as the table above lists.
162-
`SourceIdentity` still requires donor and receiver configurations to match.
167+
The Llama, Qwen2, Qwen3, Mistral, Phi3, and Qwen3 MoE profiles are text-only and
168+
do not enable reward-model, embedding, or vision-language roots; Qwen3 MoE is
169+
the only qualified MoE root. FP16, quantized weight formats other than SM90 FP8
170+
block scales on Qwen3, a quantized KV cache, alternate attention backends, YaRN
171+
or LongRoPE scaling, tied embeddings, TP greater than 2, PP greater than 1, CP
172+
greater than 1, LoRA, sparse attention, attention DP, multi-node transfer, and
173+
speculative decoding require separate qualification rows. The Qwen3 FP8
174+
block-scale profile is pinned to SM90 because its realized weight and scale
175+
layout differs on other GPU architectures. Each profile also pins its qualified
176+
RoPE realization: Llama, Qwen2, Mistral, and Phi3 require the default fused RoPE
177+
path, so unfused RoPE requires separate qualification for them, while Qwen3 and
178+
Qwen3 MoE fuse RoPE into the QK-norm kernel and therefore require
179+
`rope_fusion=False` in the realized configuration. The Mistral profile
180+
additionally pins the realized attention window: every attention layer must run
181+
without a sliding window, so sliding-window checkpoints such as Ministral fall
182+
back to the Hugging Face path until they are qualified separately. The dense
183+
profiles do not constrain MoE-only backend and mapping settings because dense
184+
roots do not consume them; the Qwen3 MoE profile pins them as the table above
185+
lists. `SourceIdentity` still requires donor and receiver configurations to
186+
match.
163187

164188
The Qwen3.5 dense vision-language profile carries the vision encoder together
165189
with the language model and realizes interleaved M-RoPE (`rope_type=mrope`),
@@ -178,10 +202,12 @@ Support for another model family requires a focused qualification change:
178202
`cache_derived_state()`.
179203
2. Verify that every one-time transform is guarded by `_weights_transformed`
180204
and that the staged receiver can skip `transform_weights()` without
181-
changing aliases, derived state, tensor layout, or outputs. Declare the
182-
guard before any weight load: staged receivers mark only modules that
183-
already carry it, and a later transform walk would run any module left
184-
unmarked on already transformed bytes.
205+
changing aliases, derived state, tensor layout, or outputs. Declare the guard
206+
before any weight load: staged receivers mark only modules that already carry
207+
it, and a later transform walk would run any module left unmarked on already
208+
transformed bytes. For quantized rows, audit each quantization method's
209+
`transform_weights()` per GPU architecture and constrain `sm_versions` to the
210+
architectures whose realized layout the row's ABI describes.
185211
3. Add an exact qualification profile only after the reusable harness in
186212
`tests/unittest/utils/post_transform_qualification.py` proves tensor,
187213
alias, transform-guard, derived-state, and deterministic output
@@ -256,7 +282,7 @@ byte:
256282
A row may list `final_manifest_exempt_patterns` on its `MxE2ECase` to exempt
257283
named tensors from the final-tier digest comparison. That is never a numeric
258284
tolerance and never applies to the transfer tier, and every pattern needs a
259-
code comment explaining why; no current row exempts anything.
285+
code comment explaining why; the current rows exempt nothing.
260286
Manifests carry a `manifest_format_version`, and manifests of different
261287
versions never compare.
262288

@@ -296,6 +322,10 @@ requires exact token equality. MoE rows also require every rank's routed-expert
296322
tensor shapes in the final manifests to match the row's MoE EP x MoE TP
297323
partition, so the comparisons cannot pass on a partition that all roles share
298324
but the row did not request.
325+
The Qwen3 FP8 block-scale profile rows use `qwen3-fp8-block-tp1` /
326+
`qwen3-fp8-block-tp2` with Qwen3-8B-FP8, overridable through
327+
`TRTLLM_MX_QWEN3_FP8_MODEL`; they run only on SM90 GPUs, which the H100 CI
328+
stages provide, and skip elsewhere.
299329
`TRTLLM_MX_E2E_REQUIRED=1` converts missing service, model, or NIXL
300330
prerequisites from skips into failures and must be set by a CI qualification
301331
stage. That stage must also allocate the GPUs declared by the selected test
@@ -362,12 +392,13 @@ A canary needs a bare BF16 reference for its task that was measured on the
362392
PyTorch backend. The Qwen3 GSM8K entry is the one gated by
363393
`tests/integration/defs/accuracy/test_disaggregated_serving.py::TestQwen3_8B`,
364394
so re-run that test to re-measure it if the value drifts. No in-envelope Llama,
365-
Qwen2, Mistral, Phi3, or Qwen3.5 checkpoint has such a reference today, so
366-
those families are covered by their smoke rows until one is added. The bare
367-
Qwen3-30B-A3B GSM8K and MMLU entries are shared with its quantized variants
368-
and have no recorded PyTorch-backend measurement, so Qwen3 MoE is covered by
369-
its smoke rows too. A Qwen3.5 canary must also size its donor exactly like its
370-
receiver, because `SourceIdentity` binds `max_num_tokens` for that root.
395+
Qwen2, Mistral, Phi3, or Qwen3.5 checkpoint has such a reference today, so those
396+
families are covered by their smoke rows until one is added. The bare
397+
Qwen3-30B-A3B GSM8K and MMLU entries are shared with its quantized variants and
398+
have no recorded PyTorch-backend measurement, so Qwen3 MoE is covered by its
399+
smoke rows too, and the Qwen3 FP8 block-scale profile has no accuracy canary
400+
either. A Qwen3.5 canary must also size its donor exactly like its receiver,
401+
because `SourceIdentity` binds `max_num_tokens` for that root.
371402

372403
The rows are registered as `stage: post_merge` entries in
373404
`tests/integration/test_lists/test-db/l0_model_express.yml`, so they run in
@@ -425,6 +456,11 @@ When adding an ABI ID:
425456
every profile that adopts the ID.
426457
4. Never reinterpret an already published ID. Supporting two ABIs requires an
427458
explicit compatibility decision and tests for each producer/receiver pair.
459+
5. When a quantization method realizes a different tensor layout per GPU
460+
architecture, give each realized layout its own ID and pin the profile's
461+
`sm_versions` to the architectures it was qualified on. `SourceIdentity`
462+
does not record the SM version, so the pin is what keeps a receiver from
463+
accepting bytes laid out for another architecture.
428464

429465
Routed-expert layouts differ per MoE implementation: the CUTLASS implementation
430466
for unquantized weights keeps the loaded layout, while the TRTLLM-Gen BF16
@@ -525,10 +561,11 @@ path.
525561
## Notes and Limitations
526562

527563
- Post-transform MX reception is currently limited to the exact Llama,
528-
Qwen2/Qwen2.5 dense, Qwen3 dense, Mistral dense, Phi3 dense, Qwen3.5 dense
529-
vision-language, and Qwen3 MoE profiles above. Other roots and variants that
530-
do not match the documented identity and runtime envelope safely fall back to
531-
Hugging Face loading until explicitly qualified.
564+
Qwen2/Qwen2.5 dense, Qwen3 dense (BF16 or SM90 FP8 block-scale), Mistral
565+
dense, Phi3 dense, Qwen3.5 dense vision-language, and Qwen3 MoE profiles
566+
above. Other roots and variants that do not match the documented identity and
567+
runtime envelope safely fall back to Hugging Face loading until explicitly
568+
qualified.
532569
- Mistral checkpoints served through the native `mistral` checkpoint format
533570
(`mistral_common` model type), sliding-window or Ministral `layer_types`
534571
variants, YaRN variants, Mistral3 vision-language roots, and Mistral Large 3

‎tensorrt_llm/_torch/pyexecutor/model_loader.py‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PHI3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2424
QWEN2_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2525
QWEN3_5_DENSE_VL_POST_TRANSFORM_LAYOUT_ABI_V1,
26+
QWEN3_DENSE_FP8_BLOCK128_FP32SCALE_POST_TRANSFORM_LAYOUT_ABI_V1,
2627
QWEN3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2728
QWEN3_MOE_CUTLASS_POST_TRANSFORM_LAYOUT_ABI_V1, ArtifactIdentity,
2829
IdentityCheckPolicy, LazyRootModelIdentity, PostTransformConfigIdentity,
@@ -156,6 +157,44 @@ def _reject_unsupported_model_llm_args(llm_args: TorchLlmArgs,
156157
raise ValueError(f"{name} is not supported by {model_cls.__name__}")
157158

158159

160+
def _with_fp8_block_scale_weights(
161+
constraints: PostTransformRuntimeConstraints,
162+
sm_versions: frozenset[int] | set[int],
163+
) -> PostTransformRuntimeConstraints:
164+
"""Admit FP8 block-scale (128x128) weights to an unquantized dense row.
165+
166+
FP8BlockScalesLinearMethod realizes a different weight and scale layout
167+
per GPU architecture: SM90 keeps checkpoint-layout E4M3 weights and FP32
168+
block scales, while other architectures can resmooth the weights and
169+
repack the scales in transform_weights(). Each FP8 row therefore pins the
170+
SM versions whose layout its transform-layout ABI describes. It also
171+
requires the checkpoint to declare 128x128 weight blocks in its Hugging
172+
Face quantization config, so a source that declares no block size or
173+
another one falls back. The KV cache, activation dtype, and every other
174+
dimension keep the base row's constraints, so `force_dynamic_quantization`
175+
stays excluded.
176+
177+
Args:
178+
constraints: An unquantized dense row's runtime constraints.
179+
sm_versions: SM versions that realize the row's FP8 layout.
180+
181+
Returns:
182+
The same constraints with declared 128x128 FP8 block-scale weights on
183+
`sm_versions`.
184+
"""
185+
return replace(
186+
constraints,
187+
quant_algorithms=frozenset({QuantAlgo.FP8_BLOCK_SCALES.value}),
188+
sm_versions=frozenset(sm_versions),
189+
weight_block_sizes=frozenset({(128, 128)}),
190+
)
191+
192+
193+
_MX_QWEN3_FP8_BLOCK_SM90_DENSE_RUNTIME_CONSTRAINTS = (
194+
_with_fp8_block_scale_weights(_MX_QWEN3_BF16_DENSE_RUNTIME_CONSTRAINTS,
195+
{90}))
196+
197+
159198
def _validate_and_adjust_mamba_snapshot_config(config: ModelConfig,
160199
llm_args: TorchLlmArgs) -> None:
161200
"""Validate snapshot reuse after the model and V2 setting are resolved."""
@@ -886,6 +925,24 @@ class ModelLoader:
886925
transfer_scope=PostTransformTransferScope.TARGET_MODEL,
887926
runtime_constraints=_MX_BF16_DENSE_RUNTIME_CONSTRAINTS,
888927
),
928+
# Ahead of the BF16 Qwen3 row: when both rows miss by one dimension,
929+
# qualify() reports the first, so an FP8 load on another SM reports
930+
# `sm_version` rather than `quant_algorithm`.
931+
PostTransformProfile(
932+
profile_id="qwen3-for-causal-lm-fp8-block-sm90-target-v1",
933+
root_model_class=LazyRootModelIdentity(
934+
"tensorrt_llm._torch.models.modeling_qwen3",
935+
"Qwen3ForCausalLM"),
936+
architecture="Qwen3ForCausalLM",
937+
model_type="qwen3",
938+
speculative_mode=None,
939+
protocol_version=_MX_STAGED_RECEIVER_TRANSFORM_PROTOCOL_VERSION,
940+
transform_abi_id=
941+
QWEN3_DENSE_FP8_BLOCK128_FP32SCALE_POST_TRANSFORM_LAYOUT_ABI_V1,
942+
transfer_scope=PostTransformTransferScope.TARGET_MODEL,
943+
runtime_constraints=
944+
_MX_QWEN3_FP8_BLOCK_SM90_DENSE_RUNTIME_CONSTRAINTS,
945+
),
889946
PostTransformProfile(
890947
profile_id="qwen3-for-causal-lm-bf16-target-v1",
891948
root_model_class=LazyRootModelIdentity(
@@ -1917,7 +1974,7 @@ def _qualify_post_transform_profile(
19171974
transfer_scope=cls._post_transform_transfer_scope(model),
19181975
enabled_features=frozenset(enabled_features),
19191976
runtime_config=PostTransformRuntimeConfig.from_model_config(
1920-
model.model_config, model=model),
1977+
model.model_config, model=model, sm_version=get_sm_version()),
19211978
)
19221979

19231980
def _dump_final_weight_manifest(

‎tensorrt_llm/_torch/weight_sharing/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
PHI3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2525
QWEN2_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2626
QWEN3_5_DENSE_VL_POST_TRANSFORM_LAYOUT_ABI_V1,
27+
QWEN3_DENSE_FP8_BLOCK128_FP32SCALE_POST_TRANSFORM_LAYOUT_ABI_V1,
2728
QWEN3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1,
2829
QWEN3_MOE_CUTLASS_POST_TRANSFORM_LAYOUT_ABI_V1,
2930
LazyRootModelIdentity,
@@ -75,6 +76,7 @@
7576
"PHI3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1",
7677
"QWEN2_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1",
7778
"QWEN3_5_DENSE_VL_POST_TRANSFORM_LAYOUT_ABI_V1",
79+
"QWEN3_DENSE_FP8_BLOCK128_FP32SCALE_POST_TRANSFORM_LAYOUT_ABI_V1",
7880
"QWEN3_DENSE_POST_TRANSFORM_LAYOUT_ABI_V1",
7981
"QWEN3_MOE_CUTLASS_POST_TRANSFORM_LAYOUT_ABI_V1",
8082
"SOURCE_IDENTITY_FORMAT_VERSION",

0 commit comments

Comments
 (0)