Repository navigation
[None][feat] FLUX.1-dev NVFP4 Static Quant with per-tensor FP8 quantized MHA (sm103 CUTEDSL) - #18396
Conversation
34fda79 to
9d93203
Compare
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
|
PR_Github #78612 [ run ] completed with state
|
|
/bot run |
|
PR_Github #78988 [ run ] triggered by Bot. Commit: |
|
PR_Github #78988 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #79029 [ run ] triggered by Bot. Commit: |
|
PR_Github #79029 [ run ] completed with state |
|
/bot run --stage-list "DGX_B200-PyTorch-Post-Merge-1,DGX_B200-PyTorch-Post-Merge-2" |
|
PR_Github #79044 [ run ] triggered by Bot. Commit: |
|
PR_Github #79044 [ run ] completed with state
|
44cc5cc to
4eb207a
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jhao-Ting Chen <[email protected]>
4eb207a to
724397d
Compare
|
/bot run --stage-list "DGX_B200-PyTorch-Post-Merge-1,DGX_B200-PyTorch-Post-Merge-2" |
|
PR_Github #79169 [ run ] triggered by Bot. Commit: |
|
PR_Github #79169 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #79249 [ run ] triggered by Bot. Commit: |
|
PR_Github #79249 [ run ] completed with state
|
|
/bot run |
|
PR_Github #79444 [ run ] triggered by Bot. Commit: |
|
PR_Github #79444 [ run ] completed with state |
|
✅ LFS objects already in storage (1 file) — no sync needed. These LFS-tracked files are already present in this repository's LFS storage:
|
### What does this PR do?
Type of change: ? Bug fix
Exporting Qwen-Image FP8 with --quantize-mha leaves internal
{q,k,v}_bmm_quantizer._amax buffers in the HF checkpoint, including
buffers from disabled quantizers. TRT-LLM rejects these unexpected keys.
Hide attention quantizers during HF export by default, except for
FLUX.1, which retains enabled Q/K/V quantizers for compatibility with
the static FP8 attention path in
[NVIDIA/TensorRT-LLM#18396](NVIDIA/TensorRT-LLM#18396).
An explicit option overrides this default. Disabled attention quantizers
are always omitted, and quantizers are restored on the live model after
saving.
Infer KV-cache metadata only for Transformers components. Diffusion
components, including the native LTX-2 transformer, no longer emit
KV-cache quantization metadata.
### Usage
Default exports omit attention quantizer state for Qwen-Image and other
diffusion components, while FLUX.1 retains enabled Q/K/V quantizers
without an additional flag:
```python
export_hf_checkpoint(pipe, export_dir="./hf_ckpt")
```
Explicitly retain enabled Q/K/V quantizers for a compatible runtime:
```python
export_hf_checkpoint(
pipe,
export_dir="./hf_ckpt",
export_attention_quantizers=True,
)
```
Set export_attention_quantizers=False to omit attention quantizers,
including for FLUX.1.
Equivalent diffusers CLI option:
```sh
--extra-param export_attention_quantizers=true
# Or explicitly omit them:
--extra-param export_attention_quantizers=false
```
### Testing
- 93 focused export and quantization-config tests passed.
- Regression cases run real FP8 calibration and sharded safetensors
export with tiny Qwen-Image and FLUX models. They verify clean Qwen
exports, FLUX’s default retention of enabled Q/K/V scales, explicit
overrides, omission of disabled buffers, and restoration of live
quantizers.
- Additional coverage verifies that the native diffusion save path used
by LTX-2 omits KV-cache metadata while a real Transformers model retains
it. This exercises the native export interface, not a full LTX-2 model.
- Regression tests reproduce the original buffer leak. The FLUX-default
and native-diffusion metadata checks also fail against the
implementation before the review fixes.
- Pre-commit checks passed.
- One optional ONNX example suite was skipped during earlier validation
because onnx_graphsurgeon was absent.
- Full B100/TRT-LLM generation and full LTX-2 deployment were not run;
the test host has no usable GPU.
### Before your PR is "*Ready for review*"
Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).
Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(...,
weights_only=False)`, `pickle`, etc.).
- Is this change backward compatible?: ❌ - Consumers of legacy attention
`_amax`
keys must enable `export_attention_quantizers=True`.
- If you copied code from any other sources or added a new PIP
dependency, did you follow guidance in `CONTRIBUTING.md`: N/A
- Did you write any new necessary tests?: ✅
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅
- Did you get Claude approval on this PR?: N/A - Not yet run
### Additional Information
Fixes NVBug 6927340.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
- **Breaking Changes**
- Hugging Face diffusion exports omit attention quantizer data by
default.
- FLUX.1 exports retain enabled Q/K/V quantizer values for runtime
compatibility.
- KV-cache metadata is excluded from native diffusion exports.
- **New Features**
- Added the `export_attention_quantizers` option to retain or omit
attention quantizers.
- Disabled quantizers remain excluded regardless of this option.
- Transformers exports continue to include KV-cache metadata.
- **Documentation**
- Added guidance on attention quantizer and KV-cache export behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Signed-off-by: Zhehao Hu <[email protected]>
Description
This PR improves FLUX.1-dev static-NVFP4 execution in TensorRT-LLM VisualGen on Blackwell:
qk_dtype: fp8,v_dtype: fp8, and Q/K/V block sizes0) using ModelOpt checkpointamaxvalues.The changes are API-compatible. Expanding the default NVFP4 candidate set may increase first-launch compilation/autotuning time.
Performance
FLUX.1-dev on NVIDIA GB300, TP1/Ulysses1/CFG1 with CUDA graphs. Each plot reports AIPerf concurrency-1 end-to-end mean latency divided by 96 inference steps.
The full static-NVFP4 + CUTEDSL FP8-MHA + all-block GELU-fusion configuration reduces step latency from 54.82 ms to 31.26 ms at 1024×1024 (43.0% lower, 1.75×) and from 278.63 ms to 163.46 ms at 2048×2048 (41.3% lower, 1.70×) versus BF16.
Optimization details
1. CUTEDSL NVFP4 GEMM+GELU fusion
The selected MLP span drops from 115.096 µs to 80.662 µs: 34.434 µs removed, or 1.43× faster. With shared activation quantization and automatic GELU fusion at both sites, full 512×512 step latency drops from 35 ms to 32 ms (3 ms / 8.6% lower).
Introducing the fusion does not show a large change in image quality for this case.
2. Per-tensor FP8 Q/K/V preprocessing fusion
The highlighted preprocessing span drops from 457.424 µs to 305.162 µs, removing 152.262 µs (1.50× / 33.3% lower) while directly producing statically scaled E4M3 Q/K/V tensors for attention.
3. FP8 attention backend selection and CUTEDSL FMHA deep dive
Same B300 replay and static per-tensor E4M3 Q/K/V values for all backends:
CUTEDSL is fastest for the tested FLUX 2048 workload. IKET places score-to-P production on the critical path: the softmax warps remain active while MMA repeatedly waits for P.
NCU confirms that MUFU.EX2 is not throughput-saturated: XU active is 63.70%, there are only 0.8667 eligible warps/scheduler, 46.63% of cycles have no eligible warp, and the 518 static EX2 PCs show 0% math-pipe throttle (sampled stalls: 63.74% wait, 34.25% MIO, 1.50% dispatch). Combined with IKET, this identifies a softmax/score-to-P bound at the current pipeline roofline: FP8 MMA completes too quickly to hide the softmax warp's dependency chain.
We tried FMA/CVT/EX2 regrouping, row-sum distance and parallel-chain changes, and one-Q/two-CTA plus split-P protocols; none produced better reproducible pipelining.
Test Coverage
wan21-nvfp4,wan22-nvfp4,qwenimage-nvfp4, andflux1-nvfp4all scored 0.000000.FLUX.1-dev-modelopt-NVFP4, a pinned CUTLASS NVFP4 GEMM backend, and new golden media. Revalidation after rebasing ontomainscored 0.000000 for both static NVFP4 and static NVFP4 + CUTEDSL FP8 MHA, below the 0.05 threshold.pre-commit run --all-filespassed, including the full mypy check.PR Checklist