Repository navigation
Emit VisualGen-compatible sparse_attention_config for diffusers skip-softmax export - #2868
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2868 +/- ##
==========================================
+ Coverage 70.16% 78.91% +8.75%
==========================================
Files 659 659
Lines 74081 74092 +11
==========================================
+ Hits 51979 58473 +6494
+ Misses 22102 15619 -6483
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Nudge: the fix is small and looks correct, but nobody has run the tests or tried loading the checkpoint in VisualGen, so a human should check before merge.
Needs action:
- Confirm CI passes on
test_sparse_attention_conversion.pyandtest_wan22_calibrated_export. The PR says pytest was never run. - Confirm with the TRT-LLM VisualGen owners (TRT-LLM PR #14687) that a Wan2.2 checkpoint with
coefficientsand a scalartarget_sparsityloads. - Fix the
next(iter(ratio.values()))default inconversion.py. Python evaluates it even whenprefillis present, and it raisesStopIterationon an empty dict (see inline comment).
No action needed:
- The design review fired only because the PR touches 6 directories. The change is just a keyword-only
for_diffusionflag on the existing exporter, not a new system. The LLM path and the vLLM path throughexport_threshold_scale_factorare unchanged. - The edit to the existing test in
tests/examples/diffusers/sparsity/test_sparsity.pyis justified. Its assertions now checkcoefficientsinstead ofprefill, matching the schema change, and it gains a check thattarget_sparsityis a scalar. - The CodeRabbit summary in the PR body lists unrelated features (GGML, ONNX Runtime). It looks stale, not like an injection attempt.
| tsf["coefficients"] = phases.get("prefill") or next(iter(phases.values())) | ||
| ratio = skip_group.get("target_sparsity") | ||
| if isinstance(ratio, dict): | ||
| skip_group["target_sparsity"] = ratio.get("prefill", next(iter(ratio.values()))) |
There was a problem hiding this comment.
Bot comment.
Python evaluates the dict.get default eagerly, so next(iter(ratio.values())) runs even when prefill exists, and an empty dict raises StopIteration. Suggest ratio["prefill"] if "prefill" in ratio else next(iter(ratio.values()), None). If the result is None, drop the key, since VisualGen needs a scalar.
There was a problem hiding this comment.
Good catch, verified: the eager default evaluated next(iter(...)) even when prefill was present and would raise on an empty dict. Fixed in 98511f6: uses ratio["prefill"] when present, else the first value, and drops target_sparsity if there is none.
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Nudge: the eager-default bug is fixed and the code looks correct, but the tests still haven't been run and nobody has confirmed the checkpoint loads in VisualGen.
Needs action:
- Confirm CI passes on
test_sparse_attention_conversion.pyandtest_wan22_calibrated_export. The PR says pytest was never run locally. - Confirm with the TRT-LLM VisualGen owners (TRT-LLM PR #14687) that a Wan2.2 checkpoint with
threshold_scale_factor.coefficientsand a scalartarget_sparsityloads.
No action needed:
- ✔️ Resolved since the last review: the eagerly evaluated
next(iter(ratio.values()))default inconversion.py. It now usesratio["prefill"]when present, falls back to the first value, and dropstarget_sparsitywhen the dict is empty. - Design review: the PR only adds a keyword-only
for_diffusionflag to the existing exporter, not a new system. The other callers inplugins/sparse_attn_config.pyandplugins/sparse_attn_calibration.pyuse the default and are unchanged. - The edit to the existing test in
tests/examples/diffusers/sparsity/test_sparsity.pyis justified. It now checkscoefficientsinstead ofprefill, which matches the schema change. - The CodeRabbit summary in the PR body lists unrelated features. It looks stale, not like an injection attempt.
…softmax export Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]>
98511f6 to
cb0cc62
Compare
### What does this PR do? Type of change: CI (test runtime, tests only) PR runs of the `hf_ptq` example lane use 4 pytest-xdist workers on the runner's one GPU (#2771). Small-model tests share the GPU, and tests that need it alone take an exclusive lock (`tests/examples/hf_ptq/conftest.py`). While an exclusive test runs, the other three workers can only run tests that need no GPU. Four tests were exclusive: `test_ptq_t5`, `test_ptq_mixtral` and the two `test_qwen_vl` cases. Their calls took 25 s, 114 s, 114 s and 82 s, 335 s in total, one after the other, in a lane whose pytest time is 547 s (job 852 s; run 39662683232, job 119443637479, on a 1-GPU PR runner, 238 passed). T5 (t5-small) and Mixtral (`TinyLlama-1.1B-Chat-v1.0-x2-MoE`, a 2B two-expert MoE) do not need the GPU alone. The reason they did is the calibration batch size: without one, `hf_ptq.py` runs a forward pass sized to fill all free GPU memory. The TinyLlama tests already pass a batch size equal to the calibration size and share the GPU. This PR gives T5 and Mixtral the same treatment through one helper (`_run_sharing_the_gpu`), used by all three tests. Test ids are unchanged. The two Qwen3-VL tests keep the exclusive lock: the TRT-LLM multimodal deploy reserves 60% of the free GPU memory for its KV cache (60 GiB on a 96 GiB GPU, measured in #2771). Measured in CI in two pairs of runs of the `hf_ptq` job (table below): pytest -77 s (-14%) on equally fast runners, and -24 s (-4%) after the rebase, where this PR's runner was about 10% slower than the baseline's (roughly -70 s scaled by that). The simulation had predicted -92 s. ### Time improvement (measured in CI) Seconds, from the `--durations` lines and the result-line timestamps of the `hf_ptq` job on a 1-GPU runner (`COVERAGE_CORE=sysmon`), in two pairs of runs. - Pair 1: before = the run of PR #2868 (run 39662683232), which has the unchanged test file and 238 tests; after = this PR's first run (run 39686597553). - Pair 2, after the rebase onto main f983619: before = the `hf_ptq` job of #2924's run (run 39737194943; main's unchanged test file, started within 10 s of the other); after = this PR's run (run 39737199847). Both have 241 tests: the three extra ones (`test_convert_ggml_to_int8.py`) came with main, take no GPU lock and cost both runs alike. | | before 1 | after 1 | change 1 | before 2 | after 2 | change 2 | |---|---|---|---|---|---|---| | `test_ptq_t5` call (exclusive, now shared) | 25.3 | 27.4 | +2.2 | 43.9 | 57.9 | +14.0 | | `test_ptq_mixtral` call (exclusive, now shared) | 114.0 | 122.4 | +8.4 | 114.3 | 133.3 | +19.0 | | `test_qwen_vl[fp8]` call (exclusive, unchanged) | 114.0 | 111.7 | -2.2 | 113.9 | 124.1 | +10.2 | | `test_qwen_vl[nvfp4]` call (exclusive, unchanged) | 81.6 | 81.0 | -0.6 | 80.9 | 89.5 | +8.6 | | the 15 `test_ptq_llama` calls, summed (they now run next to T5 and Mixtral) | 516.8 | 573.7 | +56.9 | 511.3 | 582.0 | +70.7 | | the exclusive tests' calls, summed (time the GPU is held alone) | 334.8 | 192.7 | -142.1 | 353.0 | 213.6 | -139.3 | | `setup` durations pytest lists for the LLM and VLM tests, summed (waiting for the GPU lock) | 644.5 | 351.1 | -293.4 | 852.2 | 337.2 | -515.0 | | first to last test result | 532.0 | 455.3 | -76.7 | 561.6 | 532.8 | -28.8 | | **pytest** | **547.5** | **470.3** | **-77.2 (-14%)** | **576.9** | **552.5** | **-24.3 (-4%)** | | test step (`Run tests`; `Example 1: hf_ptq` in #2924's run) | 560 | 483 | -77 | 606 | 568 | -38 | | job | 852 | 788 | -64 | 883 | 877 | -6 | The job also includes the container start and the dependency install, which this PR does not change (237 and 26 s before, 251 and 28 s after in pair 1; 243 and 17 s, 255 and 29 s in pair 2). In pair 1 the unchanged exclusive tests (Qwen3-VL) took the same time in both runs within 2%, so the runners were equally fast. In pair 2 the runner of the "after" run was about 10% slower (the same two tests took 9% and 11% longer), which hides part of the gain: scaled by that slowdown, the pytest saving is roughly 70 s instead of 24 s. In both pairs the mechanism shows the same way: the GPU is held alone for about 140 s less, and the workers wait 293 s and 515 s less in total for the lock. T5 and Mixtral take longer (+2 to +19 s each) because they now run next to the TinyLlama workers, but they no longer block them. Mixtral's call stays under the 300 s per-test cap in both runs, and no test failed or ran out of memory. The two Qwen3-VL tests still hold the GPU alone for about 200 s, which bounds what is left to save. ### Usage Nothing user-facing. ### Testing - Collection gives the same 21 node ids for `test_llm_ptq.py` and `test_vlm_ptq.py` as main. `--setup-plan` shows `shared_gpu` for t5, mixtral and llama and `exclusive_gpu` for qwen_vl. - `tests/examples/hf_ptq/test_gpu_lock.py` (the lock itself) passes: 3 tests. - Scheduling simulation on CPU, with the real lock and `-n 4`: a plugin (not part of this PR) fakes the GPU facts and replaces `run_hf_ptq_command` with a sleep of the measured call time of each test (from the 1-GPU run above, scaled by 0.1). On main the exclusive tests never overlap another test, and the first-to-last-test span is 486 s at real scale. On this branch they still never overlap, t5 and mixtral run alongside the llama cases, and the span is 394 s (-92 s). Every fake run of t5, mixtral and llama received `calib_batch_size=16` (4 for the AutoQuantize case, as before), and qwen_vl received none. - Pre-commit passes. Not run on a GPU locally; the real lane ran in this PR's own CI (below). What this PR's own GPU run confirmed, and what is left: - Confirmed by this PR's own `trtllm (hf_ptq)` runs on the 1-GPU runner (before and after the rebase): T5 and Mixtral stay within the GPU's memory next to the TinyLlama workers (no failure or out-of-memory) and Mixtral's call takes 122 s and 133 s, under the 300 s per-test cap. Peak GPU memory was not logged; to measure it, a cluster agent (lyris, hecate or ptyche) can run `pytest tests/examples/hf_ptq/test_llm_ptq.py -n 4` at this SHA in the TRT-LLM `release:1.3.0rc20` container on one GPU while logging `nvidia-smi --query-gpu=memory.used`, and compare with main. - The nightly is unaffected except that T5 and Mixtral now use a fixed calibration batch of 16 instead of the memory probe. ### 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?: N/A (CI and tests) - If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: no new dependency - Did you write any new necessary tests?: N/A (existing tests change their GPU lock; the lock has its own tests) - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: N/A (CI and tests) - Did you get Claude approval on this PR?: ✅ (`/claude review` approved 456b2ed, no findings) ### Additional Information Left out on purpose, each needs a real GPU run or the owners' call: - **Qwen3-VL deploys sharing the GPU (up to 196 s of the remaining serial chain).** The deploy is TRT-LLM's `quickstart_multimodal.py` from the container (`/app/tensorrt_llm/examples/llm-api/`), called from `huggingface_example.sh` with only `--model_dir` and `--modality image`, so it uses the script's default KV fraction. Capping it needs a flag whose name for `release:1.3.0rc20` I could not check here (the image pins rc20 because newer releases break the script), plus a proof that a smaller KV cache does not OOM or slow the deploy while three other workers run. `KV_CACHE_FREE_GPU_MEMORY_FRACTION` in `parser.sh` is a different knob (the lm_eval path, default 0.8). - **xdist on the 2-GPU nightly (it runs serially, 1,260-1,620 s before the sysmon core).** The lock treats the machine as one GPU, so it would allow it, but `modelopt.deploy.llm.LLM` sets `tp = torch.cuda.device_count()`, so on 2 GPUs every deploy test runs with tensor parallel 2 and several would overlap on both GPUs. That needs a 2-GPU run to trust. - Dropping or moving to nightly the nvfp4 Qwen3-VL case (82 s), or the six IQ/q8_0 recipe cases (about 50 s of wall time): coverage trade-offs for the owners. - The comment in `_example_tests_runner.yml` ("small-model tests share it and the rest run alone on it") is now slightly stale (only the Qwen3-VL tests run alone). Editing the workflow would make every example lane run on this PR, so I left it for the next workflow change. Related: #2771 (the GPU lock and `-n 4`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Updated post-training quantization test runs for T5, Mixtral, and TinyLlama to share GPU resources and apply calibration batch-size defaults consistently. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Shengliang Xu <[email protected]>
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072) ## Cherry-picked PRs - #2817 - #2671 - #2892 - #2876 - #2910 - #2911 - #2919 - #2904 - #2937 - #2928 - #2885 - #2908 - #2929 - #2950 - #2972 - #2877 - #2951 - #2816 - #3005 - #3012 - #2971 - #3015 - #3006 - #3026 - #2988 - #3028 - #1860 - #3030 - #2612 - #3033 - #2653 - #2599 - #2655 - #2618 - #2868 - #3032 - #3027 - #2869 - #2984 - #2975 - #2345 - #3020 - #2997 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Diffusion exports now offer more control over attention-quantizer metadata and preserve sparse-attention settings in a format compatible with downstream tooling. * Model loading better handles select bundled model implementations, and Docker guidance now covers writable CUDA-extension cache locations. * **Bug Fixes** * Improved reliability for model export and checkpoint saving, quantization across devices, ONNX processing, and calibration. * Temporary TensorRT and autotuning artifacts now use private directories by default. * **Documentation** * Updated installation guidance, compatibility notes, and links; corrected typos across guides and examples. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: LinCanNerd <[email protected]> Signed-off-by: Keval Morabia <[email protected]> Signed-off-by: weimingc <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Kai Xu <[email protected]> Signed-off-by: Zhehao Hu <[email protected]> Signed-off-by: noeyy-mino <[email protected]> Signed-off-by: joe-nv <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: Shengliang Xu <[email protected]> Signed-off-by: Chenjie Luo <[email protected]> Signed-off-by: anmaurya001 <[email protected]> Signed-off-by: Connor Baker <[email protected]> Signed-off-by: wiederse <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: Pratik Gandhi <[email protected]> Signed-off-by: Michael Rusu <[email protected]> Signed-off-by: Michael-Rusu <[email protected]> Signed-off-by: namgyu-youn <[email protected]> Signed-off-by: Sylvester Kaczmarek <[email protected]> Signed-off-by: Javier de Jesus <[email protected]> Signed-off-by: javierdejesusda <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Juhi Mittal <[email protected]> Signed-off-by: Dmitry Rantovov <[email protected]> Signed-off-by: h-guo18 <[email protected]> Co-authored-by: Chad Voegele <[email protected]> Co-authored-by: LinCanNerd <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Keval Morabia <[email protected]> Co-authored-by: Wei-Ming Chen <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: kaix-nv <[email protected]> Co-authored-by: Zhehao Hu <[email protected]> Co-authored-by: joe <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Shengliang Xu <[email protected]> Co-authored-by: Chenjie Luo <[email protected]> Co-authored-by: anmaurya001 <[email protected]> Co-authored-by: Connor Baker <[email protected]> Co-authored-by: Jiao Mingyang <[email protected]> Co-authored-by: Vu Dinh <[email protected]> Co-authored-by: Pratik Gandhi <[email protected]> Co-authored-by: Michael R <[email protected]> Co-authored-by: Michael-Rusu <[email protected]> Co-authored-by: namgyu-youn <[email protected]> Co-authored-by: Sylvester Kaczmarek <[email protected]> Co-authored-by: Javier De Jesus <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Juhi Mittal <[email protected]> Co-authored-by: Dmitry Rantovov <[email protected]> Co-authored-by: h-guo18 <[email protected]>
What does this PR do?
Type of change: Bug fix
The diffusers skip-softmax HF export wrote the LLM phase-keyed schema (
threshold_scale_factor.prefilland a{phase: ratio}target_sparsity). TRT-LLM VisualGen (PR #14687) expectsthreshold_scale_factor.coefficientsand a scalartarget_sparsity, so the exported Wan2.2 checkpoint fails to load (float() ... not 'dict'). NVBug 6927804.export_sparse_attention_config(model, *, for_diffusion=False): withfor_diffusion=True, emit onecoefficientsblock and a scalartarget_sparsity. The LLM path and the vLLM calibration plugin are unchanged._export_diffusers_checkpointpassesfor_diffusion=True.resolve_for_target_sparsity.Based on #1816 (closed, approved). Deliberately dropped its
initial_disabled_steps->disabled_until_timesteprename:initial_disabled_stepsshipped in 0.46 and the vLLM calibration path now depends on it, so the rename is a separate, breaking change.Usage
Testing
test_sparse_attention_conversion.py(diffusion schema) and the Wan calibrated-export example test.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
NVBug 6927804; supersedes #1816.
🤖 Generated with Claude Code
Summary by CodeRabbit