Skip to content

[None][feat] feat: VisualGen TE-FP8 attention backend + per-layer quant - #15668

Merged
chang-l merged 3 commits into
NVIDIA:feat/1.3-mlpinf-vgfrom
wu6u3tw:feat/1.3-mlpinf-vg-te-fp8-attn
Jun 29, 2026
Merged

[None][feat] feat: VisualGen TE-FP8 attention backend + per-layer quant#15668
chang-l merged 3 commits into
NVIDIA:feat/1.3-mlpinf-vgfrom
wu6u3tw:feat/1.3-mlpinf-vg-te-fp8-attn

Conversation

@wu6u3tw

@wu6u3tw wu6u3tw commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Two commits on top of feat/1.3-mlpinf-vg:

  • 358e7880da[feat] VisualGen: TE FP8 attention backend + fixed-latent env var

Changes

  • TE-FP8 attention backend (attention_backend/te.py): TEAttention using TransformerEngine DotProductAttention under fp8_autocast / DelayedScaling(fp8_dpa, fp8_mha). Registered as "TE" in AttentionConfig.backend.

Test plan

🤖 Generated with Claude Code

@wu6u3tw
wu6u3tw requested review from a team as code owners June 26, 2026 17:59
@wu6u3tw
wu6u3tw requested review from JunyiXu-nv, danielafrimi, syuoni and yuxianq and removed request for a team June 26, 2026 17:59
@wu6u3tw wu6u3tw changed the title feat: VisualGen TE-FP8 attention backend + fixed-latent env var (MLPerf v6.0) feat: VisualGen TE-FP8 attention backend + fixed-latent env var Jun 26, 2026
@wu6u3tw wu6u3tw changed the title feat: VisualGen TE-FP8 attention backend + fixed-latent env var feat: VisualGen TE-FP8 attention backend Jun 26, 2026
@wu6u3tw
wu6u3tw force-pushed the feat/1.3-mlpinf-vg-te-fp8-attn branch from 358e788 to b3361d9 Compare June 26, 2026 18:34
@wu6u3tw wu6u3tw changed the title feat: VisualGen TE-FP8 attention backend feat: VisualGen TE-FP8 attention backend + per-layer quant Jun 26, 2026
wu6u3tw added 2 commits June 26, 2026 12:05
torch.load inside __init__ triggers aten.set_.source_Storage_storage_offset
on a meta tensor when TRT-LLM initialises weights under MetaInitMode,
raising MetaInitException. Defer the load to the first real inference call
in generate() where the model is fully materialised.

Only the path is stored in __init__; the tensor is loaded and cached on
the first generate() invocation, then reused across requests (same
behaviour as before for steady-state throughput).

Fixes: FL1/FL2 (jobs 2140007/2140008) crash at server startup.
Validated: FL72 (job 2191174) DP72 GB300×72, Mean(6)=0.6946 ✅
Signed-off-by: Tin-Yin Lai <tinyinl@nvidia.com>
…ayer YAML key)

Add support for mixed-precision quantization in the VisualGen diffusion
pipeline via a `per_layer` key in quant_config YAML. Enables configs like:

  quant_config:
    quant_algo: NVFP4        # default for all layers
    per_layer:
      "blocks.*.attn1.*": FP8_BLOCK_SCALES  # attention linears use FP8
      "blocks.*.attn2.*": FP8_BLOCK_SCALES

Motivation: full-NVFP4 gives +6.3% throughput vs FP8_BLOCK_SCALES but
fails VBench accuracy (dynamic_degree 0.861 < 0.948 threshold). Keeping
attention linear projections at FP8 precision may recover accuracy while
retaining partial NVFP4 throughput gain from FFN layers.

Changes:
- config.py: parse `per_layer` dict in load_diffusion_quant_config() (fills
  existing TODO); switch get_quant_config() from exact-match to fnmatch
  pattern lookup; enable NVFP4 tunable quantize if any per-layer algo is NVFP4
- transformer_wan.py: apply per-layer quant config overrides to Linear modules
  in apply_quant_config_exclude_modules() before create_weights() is called
- loader.py: pass per-layer group_size to _maybe_dynamic_quantize() so
  FP8_BLOCK_SCALES attn layers use block_size=128 not the global NVFP4 value
- tests: 5 unit tests (no GPU) + integration smoke (verified on GB300)

New config: exp/configs/wan22_dp_te_fp8_attn_nvfp4_attnfp8block_gb300.yml
VBench accuracy job: 2108769 (x16 GB300, pending results)

Signed-off-by: Tin-Yin Lin <tinyinl@nvidia.com>
Signed-off-by: Tin-Yin Lai <tinyinl@nvidia.com>
@wu6u3tw
wu6u3tw force-pushed the feat/1.3-mlpinf-vg-te-fp8-attn branch from 402fc86 to 0f21d7e Compare June 26, 2026 19:05
@wu6u3tw wu6u3tw changed the title feat: VisualGen TE-FP8 attention backend + per-layer quant [None][feat] feat: VisualGen TE-FP8 attention backend + per-layer quant Jun 26, 2026
…NC/libx264 encode

## TE FP8 attention (attention_backend: TE)

Adds a new attention backend that routes through TransformerEngine's
DotProductAttention under fp8_autocast with DelayedScaling(fp8_dpa=True,
fp8_mha=True). On Blackwell (GB300), this dispatches to cuDNN Flash
Attention FP8, which is significantly more optimized for SM100a tensor
cores than the TRTLLM and Sage backends.

The module is decorated with @torch.compiler.disable because TE's
fp8_autocast context manager causes graph breaks under torch.compile.
Input layout is NHD (as used by WanPipeline); the backend reshapes to
the bshd layout expected by TE.

Wired as backend: "TE" in AttentionConfig; lazy-imported to avoid a hard
TransformerEngine dependency when the backend is not selected.

Measured on GB300 (Wan2.2-T2V-A14B offline, MLPerf):
  - Sage (TRTLLM kernel): 0.0254 QPS @ DP4 (-30.6% vs v6.0)
  - TE FP8 (cuDNN): 0.0368 QPS @ DP4 (+0.5% vs v6.0, parity)
Per-step time: 7.6 s (Sage) -> 5.4 s (TE), per-video: 155 s -> 110 s.

## NVENC + libx264 fallback (encoding.py)

Refactors _FfmpegCliEncoder to extract a _run_ffmpeg() helper, then adds
TRTLLM_VIDEO_NVENC=1 opt-in that attempts h264_nvenc first and falls back
to libx264 on failure (e.g. "unsupported device" on datacenter GPUs that
have no NVENC engine). Default behavior (libx264 only) is unchanged.

Also adds a "raw" output format that dumps uncompressed uint8 RGB bytes
to disk, bypassing ffmpeg entirely.

Signed-off-by: Tin-Yin Lai <tinyinl@nvidia.com>
@chang-l
chang-l merged commit 72b0fef into NVIDIA:feat/1.3-mlpinf-vg Jun 29, 2026
6 checks passed
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