Repository navigation
Preserve runtime reduction axes in AdaScale ONNX conversion - #4123
Closed
cherry77-cloud (taking-lying-flat) wants to merge 1 commit into
Closed
cherry77-cloud (taking-lying-flat) wants to merge 1 commit into
cherry77-cloud (taking-lying-flat) wants to merge 1 commit into
Conversation
Co-authored-by: Codex <noreply@openai.com> Signed-off-by: taking-lying-flat <1615405@qq.com>
Contributor
|
Thanks cherry77-cloud (@taking-lying-flat) for your contribution. Your commit has been merged into develop now - here db50a5c with some additional changes. Closing this PR now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The opset-18 ReduceMean and ReduceL2 converters discard
axeswhen constant resolution fails. An axes graph input, or an initializer routed through Identity, therefore becomes a reduction over every dimension. A following broadcast division can hide the error because the final shape is unchanged.Preserve unresolved axes in the converted input mapping and read them in
forward. Keep conversion-time folding for direct constants, so their existing path does not gain a runtime tensor-to-list conversion. Missing optional inputs still use the existing default semantics. Also correct ReduceL2 with empty axes andnoop_with_empty_axes=1to return the elementwise magnitude, as required by its square/sum/sqrt definition (ONNX ReduceL2-18).With
x = [[1,2,3],[4,5,6]]andaxes = [1],x / ReduceMean(x, axes)previously returns[0.285714, 0.571429, 0.857143]in the first row. It now returns[0.5, 1, 1.5], exactly matching ONNX Runtime. The initializer control remains exact. Graph-input and Identity axes also match ONNX Runtime for ReduceL2.Validation: 275 checks passed.
get_pt_blockAPI: 98 CPU + 98 CUDA passed. Covers both operators, graph inputs, Identity inputs, initializer/Constant controls, positive/negative/multiple axes, keepdims, omitted/empty axes and no-op behavior, changing axes between calls, normalization input gradients, and converted MatMul weight gradients and one SGD update against native PyTorch. The initial 92-case matrix on unchanged source gives 51 failures and 41 passes.pytest TrainingExtensions/onnx/test/python/test_onnx2torch.py TrainingExtensions/onnx/test/python/test_model_converter.py -q -ra -k 'not round_trip_with_qwen': 70 passed, 7 deselected. Those seven tests requireQwen/Qwen2.5-0.5B/backbone/model_sldynamic_cl32.onnx, which is absent locally; running them on both original and patched source produces the same FileNotFoundError before conversion.pytest TrainingExtensions/onnx/test/python/test_adascale.py::TestRequiredExtraBlockInputs TrainingExtensions/onnx/test/python/test_adascale.py::TestUpcastFp16BlockToBf16 TrainingExtensions/onnx/test/python/test_adascale.py::TestAdascaleQuantizer::test_block_level_api -q -ra: 9 passed.git diff --check: passed. The pre-commit interpreter setting was adapted locally to Python 3.12; hook definitions were unchanged.Environment: Python 3.12, PyTorch 2.13.0+cu130, onnx2torch 1.5.15, RTX A1000 Laptop GPU. Tests use generated small graphs and source AIMET code; this does not claim a full pretrained-model PTQ evaluation. Additional validation scripts are outside the production-only diff.
Open PR searches for ReduceMean, ReduceL2, dynamic axes, and axes AdaScale found no duplicate. Implementation and validation were assisted by Codex.
Minimal graph-input reproducer