Commit 1dfee8b
authored
Fix DQ1 output type error in DQ1->DQ2 for FP4 weights in NVFP4 model (#513)
## What does this PR do?
**Type of change:** Bug Fix
**Overview:**
- In post-processing after NVFP4 PTQ and ONNX Export, we convert FP4-QDQ
into DQ1->DQ2 for FP4 weights of the MatMuls. The output of DQ1 is of
the original weight-type (FP16 for FP16 base model) but its scale is in
FP32. There is a cast-to-fp16 after DQ2.
- In above setting, with FP16 base model weights, DQ1 has x_scale in
FP32 but its output type is set to FP16. This hybrid precision mode is
not allowed up to opset-21, and thereby it leads to error when run with
Onnxruntime.
- Note that such hybrid precision mode is allowed in opset-23+ but they
are not fully supported with onnxruntime EPs today, and even in future
we would want to support opset < 23 too.
- So, in this change, setting output of DQ1 to FP32 since its scale is
in FP32. There is already a cast-to-fp16 after DQ2 (before Gemm).
## Testing
- Checked with trtexec binary and onnxruntime-trt-rtx ep - using
sd3.5-medium model, on Windows RTX 5090.
## Before your PR is "*Ready for review*"
<!-- If you haven't finished some of the above items you can still open
`Draft` PR. -->
- **Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CONTRIBUTING.md)**
and your commits are signed.
- **Is this change backward compatible?**: Yes/No <!--- If No, explain
why. -->
- **Did you write any new necessary tests?**: Yes/No
- **Did you add or update any necessary documentation?**: Yes/No
- **Did you update
[Changelog](https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/main/CHANGELOG.rst)?**:
Yes/No <!--- Only for new features, API changes, critical bug fixes or
bw breaking changes. -->
## Additional Information
<!-- E.g. related issue. -->
---------
Signed-off-by: vipandya <[email protected]>1 parent 6a8d6da commit 1dfee8b
1 file changed
+14
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1317 | 1317 | | |
1318 | 1318 | | |
1319 | 1319 | | |
1320 | | - | |
1321 | 1320 | | |
1322 | 1321 | | |
1323 | 1322 | | |
| |||
1331 | 1330 | | |
1332 | 1331 | | |
1333 | 1332 | | |
1334 | | - | |
1335 | 1333 | | |
1336 | 1334 | | |
1337 | 1335 | | |
| |||
1391 | 1389 | | |
1392 | 1390 | | |
1393 | 1391 | | |
1394 | | - | |
1395 | | - | |
| 1392 | + | |
| 1393 | + | |
1396 | 1394 | | |
1397 | 1395 | | |
1398 | 1396 | | |
1399 | | - | |
| 1397 | + | |
1400 | 1398 | | |
1401 | 1399 | | |
1402 | 1400 | | |
1403 | | - | |
1404 | | - | |
| 1401 | + | |
| 1402 | + | |
1405 | 1403 | | |
1406 | 1404 | | |
1407 | | - | |
1408 | | - | |
| 1405 | + | |
| 1406 | + | |
1409 | 1407 | | |
1410 | 1408 | | |
1411 | 1409 | | |
1412 | 1410 | | |
1413 | 1411 | | |
1414 | | - | |
| 1412 | + | |
1415 | 1413 | | |
1416 | | - | |
1417 | | - | |
| 1414 | + | |
| 1415 | + | |
1418 | 1416 | | |
1419 | | - | |
| 1417 | + | |
1420 | 1418 | | |
1421 | 1419 | | |
1422 | 1420 | | |
1423 | | - | |
1424 | | - | |
| 1421 | + | |
| 1422 | + | |
1425 | 1423 | | |
1426 | | - | |
| 1424 | + | |
1427 | 1425 | | |
1428 | 1426 | | |
1429 | 1427 | | |
| |||
1522 | 1520 | | |
1523 | 1521 | | |
1524 | 1522 | | |
1525 | | - | |
1526 | 1523 | | |
1527 | 1524 | | |
1528 | 1525 | | |
| |||
0 commit comments