Repository navigation
Conversation
Co-Authored-By: Codex <[email protected]> Signed-off-by: ajrasane <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2415 +/- ##
==========================================
+ Coverage 71.72% 76.66% +4.94%
==========================================
Files 642 642
Lines 71409 75365 +3956
==========================================
+ Hits 51218 57780 +6562
+ Misses 20191 17585 -2606
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 (claude-opus-5) — DM the bot to share feedback.
Nudge: the branch change itself is sound, but the new tests mock out both converters so nothing verifies the actual mixed-dtype fix, and the FP16 NVFP4 path now skips AutoCast's opset upgrade.
Needs action:
- Confirm the opset regression in
modelopt/torch/_deploy/utils/torch_onnx.py:convert_to_f16bumped NVFP4 graphs to opset 23 (get_min_opset_for_precisions), theconvert_float_to_float16branch does not, so default exports now ship opset-20 metadata over opset-23 FP4DequantizeLinear— fix it here or say why it's acceptable. - Add an end-to-end check that the exported FP16 NVFP4 graph has no mixed float-type elementwise inputs;
tests/unit/torch/quantization/test_onnx_export_cpu.py::test_nvfp4_exported_onnx_is_topologically_sortedshows a CPU-feasible NVFP4 export pattern. - Explain whether
weights_dtype="bf16"+ NVFP4 still hits the same TensorRT parse failure, since it keeps routing throughconvert_to_f16→GraphSanitizer.find_custom_nodes.
No action needed:
- The added
weights_dtype == "fp16"guard is a no-op for BF16 (the earlierValueErroralready covers FP8/other quantizers), so the BF16 path is genuinely preserved. - PR body notes the change is Codex-authored without Claude approval, so a human pass is warranted regardless.
Co-Authored-By: Codex <[email protected]> Signed-off-by: ajrasane <[email protected]>
|
@cjluo-nv Addressed the three review items in
Validation: 128 affected CPU tests passed; the public Swin NVFP4 reproducer exported an opset-23 graph with zero mixed floating-type elementwise operations and completed a strongly typed TensorRT 11.1 engine build on Blackwell.
|
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (claude-opus-5) — DM the bot to share feedback.
Nudge: all three prior concerns are fixed with real code and real CPU coverage, but the PR quietly turns two previously-working NVFP4 conversions into hard errors and the agent-authored change still wants a human pass.
Needs action:
- Document the new hard failures in
CHANGELOG.rst:weights_dtype="bf16"with FP32 params + NVFP4, andweights_dtype="fp16"with BF16 params + NVFP4, previously ran throughconvert_to_f16and now raiseValueErrorinmodelopt/torch/_deploy/utils/torch_onnx.py. The PR body still marks this backward compatible. - Confirm the
weights_dtype="fp32"NVFP4 path: the newif uses_fp4:opset block runs there too andnvfp4_exporter.post_processnow stamps MatMul outputs as FP16, so that graph can still carry mixed FP16/FP32 elementwise inputs — say whether it is out of scope or add it totest_nvfp4_deploy_export_has_consistent_elementwise_types. - Have a human review the Codex-authored commits before merge.
No action needed:
- ✔️ Resolved since the last review: the opset-23 upgrade before precision conversion, the real CPU NVFP4 export test asserting no mixed-float elementwise inputs, and the BF16 no-op routing.
- Refactor of
test_nvfp4_exported_onnx_is_topologically_sortedinto_make_cpu_nvfp4_modelkeeps coverage intact.
Co-Authored-By: Codex <[email protected]> Signed-off-by: ajrasane <[email protected]>
Co-Authored-By: Codex <[email protected]> Signed-off-by: ajrasane <[email protected]>
|
Addressed the current-head review items in
The PR is now conflict-free. Current-head Blackwell/TensorRT acceptance has not been rerun, and human approval remains external.
|
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (claude-opus-5) — DM the bot to share feedback.
Nudge: the two prior code concerns are resolved with real CPU coverage, but hardware acceptance is stale on current head and one BF16 branch in the exporter is unexplained.
Needs action:
- Rerun or explicitly waive the Blackwell/TensorRT engine build for the current head; the PR body says it was not repeated after the final exporter change.
- Explain (ideally as a code comment) why the BF16 branch in
modelopt/onnx/export/nvfp4_exporter.py::_cast_input_dtypesre-stamps the node output value_info to BF16 instead of inserting a boundary Cast like the FP16 path — on a graph with any BF16 initializer this silently retypes outputs whose consumers are still FP32. - Have a human review the Codex-authored commits and the declared backward-incompatible
ValueErrorbehavior before merge.
No action needed:
- ✔️ Resolved since the last review: the
CHANGELOG.rstentry for the new FP32→BF16 / BF16→FP16 hard failures, and theweights_dtype="fp32"mixed-type path (Gemm bias cast + output boundary cast, covered by the new parameterizedelementwise/gemmCPU tests). - The output cast is skipped when a node output has no value_info (e.g. after a failed shape inference), which just restores pre-PR behavior rather than regressing.
Signed-off-by: ajrasane <[email protected]>
|
@cjluo-nv Addressed the current-head review items in
Human approval remains external.
|
Signed-off-by: ajrasane <[email protected]>
Signed-off-by: ajrasane <[email protected]>
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (claude-opus-5) — DM the bot to share feedback.
Nudge: both prior code concerns are now fixed with real CPU coverage, but the Blackwell acceptance was waived rather than run and the backward-incompatible ValueError behavior in agent-authored code still needs a human call.
Needs action:
- Have a human sign off on the Codex-authored commits and the new
ValueErrors inmodelopt/torch/_deploy/utils/torch_onnx.py(FP32→BF16 and BF16→FP16 NVFP4 now hard-fail); CHANGELOG documents it, the PR body still needs the compatibility flag to match. - Decide whether the waived current-head Blackwell/TensorRT engine build is acceptable, or rerun it once a B100/B200/SM120 host is available.
- Confirm the BF16 re-stamp in
nvfp4_exporter.py::_cast_input_dtypesis safe when a BF16-weighted node output is a graph output underweights_dtype="fp32"— that path changes the declared model output dtype with no Cast and isn't covered bytest_nvfp4_deploy_export_preserves_mixed_precision_boundaries.
No action needed:
- ✔️ Resolved since the last review: the global-precision BF16 retyping bug (now derived per quantized weight, with an inline comment) and the new mixed FP32/BF16 export regression test.
- Refactor into
_make_cpu_nvfp4_modelkeeps the original topological-sort test coverage intact.
Support FP32 or mixed sources exported to BF16 and BF16 or mixed sources exported to FP16, including accompanying FP8 layers. Preserve fixed FP4/FP8 dynamic-quantizer output types before conversion so missing intermediate shapes do not trigger TensorRT parsing of mixed compute dtypes. Cover LayerNorm, Gemm, graph I/O, and FP8 scale boundaries. Signed-off-by: ajrasane <[email protected]>
Use AutoCast policies for supported NVFP4 FP16 and BF16 exports, preserve native BF16 no-op and unrelated quantizer routes, and preserve the sign of tiny initializer values. Consolidate regression setup and verify packed payloads, dynamic converted shapes, and numerical limits. Signed-off-by: ajrasane <[email protected]>
Signed-off-by: ajrasane <[email protected]>
cjluo-nv
left a comment
There was a problem hiding this comment.
Bot review (claude-opus-5) — DM the bot to share feedback.
Nudge: prior code findings are fixed, but the new AutoCast-wide changes in this round plus the still-open BF16 re-stamp question need an owner's call before merge.
Needs action:
- 💬 Author replied that the BF16 re-stamp is required because
TRT_FP4QDQlacks shape inference — still needs the graph-output case: innvfp4_exporter.py::_cast_input_dtypes, a BF16-weighted node whose output is a graph output is retyped with no Cast underweights_dtype="fp32". Confirm it is unreachable or cover it intest_nvfp4_deploy_export_preserves_mixed_precision_boundaries. - Justify hard-coding
TRT_FP4DynamicQuantizeand its exact FP4/FP8 output signature insidegraphsanitizer.find_custom_nodes, or pass the skip as an explicit flag from the NVFP4 caller — this changes TRT inference for every AutoCast user with that plugin. - Add AutoCast coverage for the widened input retype in
precisionconverter.convert(elem_type in ONNX_TYPES): an FP16 graph input is now silently declared BF16 whenkeep_io_types=False. - Have a human sign off on the Codex-authored commits and decide whether the waived current-head Blackwell engine build is acceptable.
No action needed:
- ✔️ Resolved since the last review: the per-weight precision derivation, the mixed FP32/BF16 export regression, the CHANGELOG policy entry, and the sign-preserving initializer clamp (now tested).
- 207 core-logic lines — under the size budget.
Signed-off-by: ajrasane <[email protected]>
|
Follow-up to the review, implemented in 03b814c1a:
|
|
Blackwell validation update for 03b814c, following the existing review and the prior numbered reply:
Passing level-0 run: SHA256 evidence manifest
|
|
Swin runtime follow-up to the existing review:
|
Retain the NVFP4 compatibility warning and the independent upstream changelog entries. Validated with the seven-file CPU regression suite (420 passed) and changelog pre-commit checks. Signed-off-by: ajrasane <[email protected]>
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: every earlier code concern is fixed and tested, but the original Swin bug still fails at runtime. With default TensorRT optimization level 3, the Swin engines produce NaNs, and the only workaround found is still unpushed.
Needs action:
- Decide whether a fix that clears ONNX/TRT parsing is enough to merge while default level-3 Swin engines still output NaNs on B200 (TRT 11.1 and 11.2.1.2). If it isn't, land the GELU-boundary workaround with this PR or as a linked follow-up.
- Have a human sign off on the Codex-authored commits and the backward-incompatible numerics. NVFP4 FP16 exports now follow AutoCast's clamping and
Divpolicy;CHANGELOG.rstdocuments this. - Confirm the PR body's testing claims match what's on the branch. The 13/13 pass was measured on local tree
ff2313b, which has not been pushed. Only the level-0 run and the failing level-3 run cover public head03b814c.
No action needed:
- ✔️ Resolved since the last review:
- the BF16 graph-output re-stamp (now covered by
test_nvfp4_deploy_export_preserves_bf16_graph_outputs) - the
TRT_FP4DynamicQuantizehard-coding (now behind an opt-indefer_nvfp4_trt_inferenceflag that is off by default) - the FP16→BF16 input retype (
test_bf16_conversion_accepts_fp16_initializernow uses FP16 I/O throughconvert_to_f16)
- the BF16 graph-output re-stamp (now covered by
- The existing-test edits are justified. The
find_custom_nodestest keeps its default-path assertions and adds parametrized cases, and the BF16 test moved to the public API with stronger assertions. - Design is settled: this extends AutoCast and the existing exporter rather than adding a new system. About 191 core-logic lines, under the size budget.
|
Swin on Blackwell: TensorRT runtime blocker The ModelOpt-side fix for the original mixed-dtype The failure was reduced to an NVFP4 MLP using native TensorRT APIs, with no ModelOpt export or ONNX parsing. With the same engine and finite inputs, changing the initial contents of valid, aligned workspace memory changes outputs between zeros, finite values, and NaNs; the level-0 control is stable. This points to a read-before-write or unwritten-workspace defect in TensorRT's fused GEMM/GELU/requantization path. The exact faulty kernel instruction remains unconfirmed. Opened TensorRT NVBug 6906055 with the reproducer and diagnostic evidence. The remaining runtime issue requires a TensorRT-side fix before end-to-end Swin validation can pass. Current PR head d48e98cfe has 420 passing CPU tests, but no fresh Blackwell validation. The observations above are from the prior GPU investigation, not a validation of this head. No failure is waived; human maintainer sign-off remains outstanding.
|
### What does this PR do? Type of change: Bug fix #1289 (in 0.44.0 through #1350) registered `nn.LayerNorm` in `QuantModuleRegistry` so that FP8 MHA recipes can quantize its output. As a side effect, presets and recipes that import `configs/ptq/units/default_disabled_quantizers` and enable a bare `*input_quantizer` (`INT8_DEFAULT_CFG`, `FP8_DEFAULT_CFG`, `NVFP4_DEFAULT_CFG`, ...) also quantize every LayerNorm *input*, i.e. the residual stream (49 extra NVFP4 quantizers in XLM-R large). In ONNX export this becomes a dynamic quantize in front of `LayerNormalization` that no GEMM consumes. Weight-only and layer-scoped presets are not affected. This adds a `parent_class: 'nn.LayerNorm'` exclusion to `default_disabled_quantizers`, in the same form as the existing `nn.BatchNorm*`, `nn.LeakyReLU` and `nn.Embedding` entries. LayerNorm quantization stays opt-in: the FP8 MHA override in `examples/torch_onnx/torch_quant_to_onnx.py`, appended after the preset, enables the LayerNorm output quantizer and already disables the input quantizer, so its result is unchanged. As with the BatchNorm entries, an `nn.LayerNorm` subclass registered as its own quant class is not covered. #2402 fixed the same regression for the diffusers NVFP4 presets with the same entry; those presets do not import this unit. Out of scope: `NVFP4_FP8_MHA_CONFIG`, `model_type/vit/ptq/fp8.yaml` and the diffusers `fp8`, `int8` and `nvfp4_fp8_conv` presets also skip this unit and still quantize LayerNorm inputs. Effect on `BAAI/bge-reranker-v2-m3` (XLM-R large), NVFP4 W4A4 fake quant (ModelOpt 0.47.0, same as main here), 60 queries × 100 candidates each: | NVFP4_DEFAULT_CFG (classifier excluded) | Ko-StrategyQA Recall@10 | same top-1 as FP32 | mean \|logit − FP32\| | MIRACL-ko Recall@10 | same top-1 | mean \|logit − FP32\| | |---|---|---|---|---|---|---| | as is (LayerNorm inputs quantized) | 87.6% | 80% | 0.94 | 91.1% | 80% | 1.05 | | LayerNorm quantizers disabled (this PR) | 90.6% | 90% | 0.61 | 94.5% | 87% | 0.66 | | FP32 | 88.9% | | | 93.4% | | | ### Usage No API change. A config that wants LayerNorm input quantization adds the entry after the default exclusions: ```python cfg = copy.deepcopy(mtq.FP8_DEFAULT_CFG) cfg["quant_cfg"].append( {"parent_class": "nn.LayerNorm", "quantizer_name": "*input_quantizer", "cfg": {"num_bits": (4, 3), "axis": None}} ) ``` ### Testing - New `test_default_presets_keep_layernorm_inputs_unquantized` (`INT8_DEFAULT_CFG`, `FP8_DEFAULT_CFG`, `NVFP4_DEFAULT_CFG`): fails on main, passes here. - `pytest tests/unit/torch/quantization tests/unit/recipe`: 1912 passed, 1 skipped. - `pytest tests/examples/torch_onnx/test_torch_quant_to_onnx.py -k "vit_tiny or swin"` (RTX PRO 6000, TensorRT 11.3): the 12 FP8, INT8, MXFP8 and auto cases pass. The 3 NVFP4 cases fail the same way on main, in the FP32 NVFP4 export that #2415 fixes, and pass with a local fix for it. - `pre-commit run --files` on the changed files: pass. - End to end: `bge-reranker-v2-m3` with `NVFP4_DEFAULT_CFG` has 0 LayerNorm input quantizers enabled, and its TensorRT engine matches fake quant (Recall@10 89.8% for both) with the #2415 export fix applied locally. ### 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?: ❌ New `mtq.quantize` calls with these presets no longer add LayerNorm input quantizers, as before 0.44. Saved checkpoints restore unchanged, because restore replays their stored config. Usage shows how to re-enable them. - 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)?: ✅ Under 0.49.0; I can move the entry if this should go into 0.48.0. - Did you get Claude approval on this PR?: N/A ### Additional Information Found while quantizing `BAAI/bge-reranker-v2-m3` to NVFP4; its TensorRT engine also needs the FP32 NVFP4 export fix in #2415. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Default quantization presets no longer quantize inputs to `LayerNorm` modules, avoiding added error in residual streams. * Re-quantize models affected by this change. Recipes that need `LayerNorm` input quantization can enable it after importing the relevant preset. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Hanjun Cho <[email protected]>
What does this PR do?
Type of change: Bug fix
Fixes NVFP4 ONNX export failing on mixed FP32/FP16 inputs by normalizing compute dtypes before TensorRT parsing.
Compatibility: NVFP4 FP16 exports now use AutoCast's precision and clamping policies. Numerical results can change; revalidate model accuracy.
Usage
NVFP4 deployment uses
keep_io_types=Falseand enables inference deferral internally. Ordinary AutoCast callers retain their existing inference behavior.Testing
Current head: d48e98cfe.
CPU coverage includes mixed-output dtypes, NVFP4 inference deferral, and FP16→BF16 interfaces.
Before your PR is "Ready for review"
Additional Information
The ModelOpt-side fix is complete, but Swin still fails on Blackwell/B200 during default level-3 TensorRT inference. The recorded Swin exports and engine builds succeed; execution fails for FP32→FP16, FP32→BF16, and BF16→FP16.
The remaining issue reproduces with native TensorRT APIs without ModelOpt or ONNX parsing. It requires a TensorRT-side fix, tracked in NVBug 6906055. End-to-end Swin validation remains blocked pending that fix and a fresh current-head run. No failure is waived; human maintainer sign-off remains outstanding.
weights_dtype="fp32"preserves existing boundaries; it does not request general BF16→FP32 conversion. Broaderkeep_io_types=True, aliased-output, and FP32-path dynamic-shape limitations remain outside this fix.