Repository navigation
Fix LayerNormalization stats dtype in symbolic shape inference - #33983
Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Open
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Lanre Shittu (Shizoqua) wants to merge 1 commit into
Conversation
The symbolic shape inference handler for LayerNormalization and SimplifiedLayerNormalization derived the type of the Mean and InvStdDev outputs from the input X. These outputs use the stash_type attribute, which defaults to float. For a double input the tool wrote double, so a valid model failed to load in onnxruntime after shape inference with a type error. An explicit stash_type such as bfloat16 was ignored. Read stash_type instead, matching the ONNX schema and the onnxruntime kernels and contrib schemas.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change aligning normalization statistics type inference with stash_type.
No open issues 🎉
What changed in this PR
Fixes #33982 by aligning symbolic shape inference for normalization statistics with the schemas’ stash_type attribute, preventing incorrect output types for double-precision inputs.
Changes:
- Derives statistics output types from
stash_type, defaulting to float, for both normalization operators. - Adds regression coverage for double inputs and explicit bfloat16 statistics.
| File | Description |
|---|---|
onnxruntime/test/python/onnxruntime_test_python_symbolic_shape_infer.py |
Adds three cases checking inferred output types and shapes. |
onnxruntime/python/tools/symbolic_shape_infer.py |
Uses stash_type for statistics in the shared normalization handler. |
Review effort: Balanced
This branch has not been deployed
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.
Description
_infer_LayerNormalizationinsymbolic_shape_infer.pynow takes the type of theMeanandInvStdDevoutputs from thestash_typeattribute (default float) instead of from inputX. The same handler coversSimplifiedLayerNormalization, whoseinv_std_varoutput followsstash_typeas well.This matches the ONNX
LayerNormalizationschema (Uis float or bfloat16, set bystash_type), the onnxruntimeLayerNormalizationandSimplifiedLayerNormalizationschemas, and the CPU kernel, which registersUas float.Added
test_layer_norm_stats_type_follows_stash_typetoonnxruntime_test_python_symbolic_shape_infer.py. It covers double input with the defaultstash_type, float input withstash_type=bfloat16, andSimplifiedLayerNormalizationwith double input.Motivation and Context
Fixes #33982
For a double input the tool wrote
tensor(double)for these outputs, so a valid model failed to load in onnxruntime after shape inference:Testing, on Linux with the onnxruntime 1.31.1 CPU wheel as the runtime and the Python tooling from this branch:
stash_type=bfloat16ignored) and passes with the fix.python -m unittest onnxruntime_test_python_symbolic_shape_infer: 49 tests, 47 pass. The 2 failures (test_symbolic_step,test_symbolic_negative_step) also fail on main with sympy 1.14, which CI pins, and pass with sympy 1.13.3. They are unrelated to this change.onnxruntime/test/python/quantization: 541 passed, 18 skipped.lintrunneron the changed files: no issues