Commit ab0eba9
authored
### What does this PR do?
Type of change: New feature
Adds `nodes_to_exclude` regex support to the QDQ-aware
`convert_to_f16()` API, matching the node-name exclusion semantics
already supported by `convert_to_mixed_precision()`.
This allows callers to keep selected numerically sensitive subgraphs in
FP32 while converting the rest of a quantized ONNX graph to FP16 or
BF16. Existing `op_block_list` and `tensor_block_dict` behavior remains
unchanged.
The regression test reuses the existing conversion fixture and verifies
that:
- op_block_list continues to preserve matching operations in FP32.
- nodes_to_exclude preserves regex-matching nodes in FP32.
- Non-matching computation is converted to FP16.
- The resulting ONNX model passes full validation.
### Usage
```python
import onnx
from modelopt.onnx.autocast import convert_to_f16
model = onnx.load("model.onnx", load_external_data=True)
converted_model = convert_to_f16(
model,
low_precision_type="fp16",
# Preserve Q/DQ operations using the existing op-type policy.
op_block_list=["QuantizeLinear", "DequantizeLinear"],
# Keep the numerically sensitive RMSNorm calculation in FP32.
nodes_to_exclude=[
r"^/rms/(Pow|ReduceMean|Add|Sqrt|Div)$",
],
)
onnx.save(converted_model, "model_fp16.onnx")
### Testing
```bash
pytest tests/unit/onnx/autocast/test_precisionconverter.py
```
Result: 185 tests passed.
Added focused coverage for combining operation-type and node-name exclusions. The test also includes a non-excluded FP16 conversion control.
### 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?: ✅
- If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: N/A — no copied code or new dependency.
- 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?: ❌ — pending /claude review.
### Additional Information
This addresses QDQ-aware mixed-precision conversion of numerically sensitive named subgraphs without requiring callers to expand an entire operation type into op_block_list.
No new runtime or PIP dependencies are introduced.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
* **New Features**
* Added Muse Glimmer AutoQuantize, Alpamayo QAD, and streaming Kimi-K3 conversion.
* Added layerwise checkpoint export and ONNX Q/DQ node-name exclusion support.
* Added temporary quantization contexts and improved CUDA capability handling.
* **Bug Fixes**
* Fixed NVFP4 calibration and export issues.
* Ensured excluded nodes and blocked operators remain in FP32 during FP16 conversion.
* Improved strict ONNX model validation.
* **Documentation**
* Documented new quantization contexts and CUDA capability behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: Jai Prajapati <jprajapati@nvidia.com>
1 parent 029c67f commit ab0eba9
3 files changed
Lines changed: 35 additions & 3 deletions
File tree
- modelopt/onnx/autocast
- tests/unit/onnx/autocast
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
| 228 | + | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
| |||
240 | 245 | | |
241 | 246 | | |
242 | 247 | | |
| 248 | + | |
243 | 249 | | |
244 | 250 | | |
245 | 251 | | |
| |||
303 | 309 | | |
304 | 310 | | |
305 | 311 | | |
306 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
307 | 319 | | |
308 | | - | |
| 320 | + | |
309 | 321 | | |
310 | 322 | | |
311 | 323 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2220 | 2220 | | |
2221 | 2221 | | |
2222 | 2222 | | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
2223 | 2242 | | |
2224 | 2243 | | |
2225 | 2244 | | |
| |||
0 commit comments