-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[https://nvbugs/6572800][fix] Added _use_fused_ln(fp4_scale) and gated each of the three norm sites on its…
#17509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,10 +122,6 @@ examples/visual_gen/test_visual_gen_qwen_image.py::test_qwenimage_feature_accura | |
| examples/visual_gen/test_visual_gen_qwen_image.py::test_qwenimage_feature_accuracy_against_golden[nvfp4] SKIP (https://nvbugs/6572800) | ||
| examples/visual_gen/test_visual_gen_wan.py::test_fastwan_lpips_against_golden SKIP (https://nvbugs/6572800) | ||
| examples/visual_gen/test_visual_gen_wan.py::test_wan22_t2v_lpips_against_golden SKIP (https://nvbugs/6535765) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| examples/visual_gen/test_visual_gen_wan.py::test_wan_feature_accuracy_against_golden[wan21-nvfp4] SKIP (https://nvbugs/6572800) | ||
| examples/visual_gen/test_visual_gen_wan.py::test_wan_feature_accuracy_against_golden[wan22-cuda-graph] SKIP (https://nvbugs/6572800) | ||
| examples/visual_gen/test_visual_gen_wan.py::test_wan_feature_accuracy_against_golden[wan22-fp8-blockwise] SKIP (https://nvbugs/6572800) | ||
| examples/visual_gen/test_visual_gen_wan.py::test_wan_feature_accuracy_against_golden[wan22-nvfp4] SKIP (https://nvbugs/6572800) | ||
| full:A100/accuracy/test_llm_api_pytorch.py::TestQwen3_5_35B_A3B::test_bf16_mtp SKIP (https://nvbugs/6275856) | ||
| full:A100/accuracy/test_llm_api_pytorch_multimodal.py::TestExaone4_5_33B::test_auto_dtype[forced_chunked_prefill] SKIP (https://nvbugs/6597570) | ||
| full:A100/accuracy/test_llm_api_pytorch_multimodal.py::TestExaone4_5_33B::test_auto_dtype[full_budget] SKIP (https://nvbugs/6597570) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,10 @@ | |
| DiffusionPipelineConfig, | ||
| VisualGenArgs, | ||
| ) | ||
| from tensorrt_llm._torch.visual_gen.models.wan.transformer_wan import WanTransformer3DModel | ||
| from tensorrt_llm._torch.visual_gen.models.wan.transformer_wan import ( | ||
| WanBlock, | ||
| WanTransformer3DModel, | ||
| ) | ||
| from tensorrt_llm.models.modeling_utils import QuantConfig | ||
|
|
||
|
|
||
|
|
@@ -163,14 +166,16 @@ def _load_models(checkpoint_dir: str): | |
| } | ||
|
|
||
|
|
||
| def _make_model_config(config_dict: dict) -> DiffusionModelConfig: | ||
| def _make_model_config( | ||
| config_dict: dict, *, skip_create_weights: bool = False | ||
| ) -> DiffusionModelConfig: | ||
| return DiffusionModelConfig( | ||
| pretrained_config=SimpleNamespace(**config_dict), | ||
| quant_config=QuantConfig(), | ||
| quant_config_dict=None, | ||
| dynamic_weight_quant=False, | ||
| force_dynamic_quantization=False, | ||
| skip_create_weights_in_init=False, | ||
| skip_create_weights_in_init=skip_create_weights, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -341,6 +346,32 @@ def test_allclose_to_hf(self): | |
|
|
||
| torch.testing.assert_close(trt_out, hf_out, atol=0.4, rtol=0.4) | ||
|
|
||
| @pytest.mark.parametrize("num_heads,shape_supported", [(40, True), (12, False)]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test only exercises the predicate, not |
||
| def test_fused_layernorm_requires_its_quantize(self, num_heads, shape_supported): | ||
| """The fused LN kernel is only taken where a quantize exists to fold in. | ||
|
|
||
| The kernel derives the LayerNorm statistics itself and is not bit-exact | ||
| with F.layer_norm, so taking it with no downstream NVFP4 quantize costs | ||
| accuracy for nothing (nvbugs/6535765, nvbugs/6572800). Off the supported | ||
| hidden size (40 heads x 128 = 5120) it is never taken, scale or not. | ||
| """ | ||
| cfg = { | ||
| **WAN_1_3B_CONFIG, | ||
| "num_layers": 1, | ||
| "num_attention_heads": num_heads, | ||
| "hidden_size": num_heads * WAN_1_3B_CONFIG["attention_head_dim"], | ||
| } | ||
| block = WanBlock( | ||
| model_config=_make_model_config(cfg, skip_create_weights=True), _layer_idx=0 | ||
| ) | ||
| assert block._fused_ln_shape_supported is shape_supported | ||
|
|
||
| # An unquantized checkpoint leaves every norm's fp4 scale unset. | ||
| assert block._norm1_fp4_scale is None | ||
| assert not block._use_fused_ln(block._norm1_fp4_scale) | ||
| # With a scale present, the fusion is taken iff the shape supports it. | ||
| assert block._use_fused_ln(torch.empty(1)) is shape_supported | ||
|
|
||
|
|
||
| # ============================================================================ | ||
| # T2V correctness test — Wan2.1-T2V-1.3B | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this gate, the fused kernel is reached only when hidden==5120 and the checkpoint carries a static NVFP4
input_scale(get_nvfp4_input_scalereturnsNonefor dynamic quant, AWQ pre-quant-scale, and group size != 16). None of thetest_wan_feature_accuracy_against_goldenprofiles meet that — they all quantize at runtime — so the fused path is now unexercised by the tests this PR un-waives, and a future regression that turns the gate permanently off would not be caught. Worth adding a positive check on a statically-quantized NVFP4 Wan2.2 checkpoint that the fused path is actually taken.