-
Notifications
You must be signed in to change notification settings - Fork 534
[OMNIML-5613] Quantize ResNet residual adds in torch ONNX example #2024
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
664a7a3
28b2912
c15755c
d2a78de
77f2433
7cf4bf5
9cbcbbd
552ac54
edc43d4
7f3a6d7
4959049
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 |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| # when using 1/448 as the Q scale (single fixed value — softmax range is data-independent). | ||
| _FP8_E4M3_MAX = 448.0 | ||
| _FP8_E4M3_SOFTMAX_SCALE = 1.0 / _FP8_E4M3_MAX | ||
| _FP8_MIN_CONV_CHANNELS = 16 | ||
|
Contributor
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Are there grouped/depthwise convs in the FP8 export path's expected model set?
rg -nP -C3 '\bgroup\b|groups' modelopt/onnx/export/fp8_exporter.pyRepository: NVIDIA/Model-Optimizer Length of output: 160 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Map the relevant files and inspect the exporter + torch-side gate.
git ls-files 'modelopt/onnx/export/fp8_exporter.py' 'examples/torch_onnx/torch_quant_to_onnx.py'
wc -l modelopt/onnx/export/fp8_exporter.py examples/torch_onnx/torch_quant_to_onnx.py
ast-grep outline modelopt/onnx/export/fp8_exporter.py --view expanded
ast-grep outline examples/torch_onnx/torch_quant_to_onnx.py --view expandedRepository: NVIDIA/Model-Optimizer Length of output: 2528 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Read the relevant implementation slices.
sed -n '150,230p' modelopt/onnx/export/fp8_exporter.py
printf '\n----\n'
sed -n '190,225p' examples/torch_onnx/torch_quant_to_onnx.pyRepository: NVIDIA/Model-Optimizer Length of output: 4975 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find every place the FP8 conv channel threshold is applied.
rg -n -C3 '_FP8_MIN_CONV_CHANNELS|shape\[:2\]|in_channels|out_channels|groups' modelopt/onnx/export/fp8_exporter.pyRepository: NVIDIA/Model-Optimizer Length of output: 686 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the surrounding exporter logic to see how the skipped weight path is used.
sed -n '1,120p' modelopt/onnx/export/fp8_exporter.py
printf '\n----\n'
sed -n '120,190p' modelopt/onnx/export/fp8_exporter.py
printf '\n----\n'
sed -n '440,500p' modelopt/onnx/export/fp8_exporter.pyRepository: NVIDIA/Model-Optimizer Length of output: 11674 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Check whether grouped/depthwise convolutions are represented in tests/examples around FP8 export.
rg -n -C2 'depthwise|groups *= *[1-9]|grouped conv|grouped convolution|Conv2d\(.*groups' modelopt examples testsRepository: NVIDIA/Model-Optimizer Length of output: 22860 Grouped convs need a group-aware channel check 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| class FP8QuantExporter(ONNXQuantExporter): | ||
|
|
@@ -189,6 +190,10 @@ def _quantize_conv_weights_to_fp8(graph: gs.Graph) -> int: | |
| weight_input = node.inputs[1] | ||
| if not isinstance(weight_input, gs.Constant): | ||
| continue | ||
| if any( | ||
| channels <= _FP8_MIN_CONV_CHANNELS for channels in weight_input.values.shape[:2] | ||
| ): | ||
| continue | ||
|
|
||
| # Skip if weight already has a DQ producer | ||
| if any(out.op == "DequantizeLinear" for out in weight_input.outputs): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.