Skip to content

Add in stash type attr for layernorm and additional test coverage #4147

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

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

TedThemistokleous
Copy link
Collaborator

@TedThemistokleous TedThemistokleous commented Jul 18, 2025

Gets rid of "Stash type not supported" warnings in models whenever there is layernorm present

default behavior of layernorm op is stash_type = 1 for this attribute. Without this we throw the warning for every graph. Proper way is to upconvert first input for stash and then downconvert to type for the second scale and bias stage.

https://onnx.ai/onnx/operators/onnx__LayerNormalization.html

Added additional tests to validate and ensure we're using the proper types for input, scale and bias as well as the outputs are within the proper types for this parser.

Had to update gen_onnx and generate a few more cases to ensure layernorm is being parsed in with the correct inputs before we do any sort of calculations which would propagate through the graph

@TedThemistokleous TedThemistokleous self-assigned this Jul 18, 2025
@TedThemistokleous TedThemistokleous added the simple small or simple changes label Jul 18, 2025
@TedThemistokleous TedThemistokleous requested review from kahmed10, ahsan-ca and kentqian and removed request for causten July 18, 2025 15:10
@TedThemistokleous TedThemistokleous added Cleanup Cleans up code from stale bits/warnings/previous changes for a previous feature PR Onnx Operators Adding or modifying an Onnx Operator in the MIGraphX codebase labels Jul 18, 2025
Copy link

codecov bot commented Jul 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4147      +/-   ##
===========================================
- Coverage    92.23%   92.23%   -0.00%     
===========================================
  Files          548      549       +1     
  Lines        25187    25332     +145     
===========================================
+ Hits         23230    23363     +133     
- Misses        1957     1969      +12     
Files with missing lines Coverage Δ
src/onnx/parse_layernorm.cpp 98.95% <100.00%> (+2.87%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TedThemistokleous TedThemistokleous changed the title Add in stash time attr for layernorm Add in stash type attr for layernorm Jul 23, 2025
@migraphx-bot
Copy link
Collaborator

Test Batch Rate new
989161
Rate old
408b98
Diff Compare
torchvision-resnet50 64 3,248.96 3,249.84 -0.03%
torchvision-resnet50_fp16 64 6,928.24 6,927.96 0.00%
torchvision-densenet121 32 2,451.71 2,450.72 0.04%
torchvision-densenet121_fp16 32 4,183.96 4,199.41 -0.37%
torchvision-inceptionv3 32 1,636.14 1,638.39 -0.14%
torchvision-inceptionv3_fp16 32 2,754.42 2,755.49 -0.04%
cadene-inceptionv4 16 771.79 772.10 -0.04%
cadene-resnext64x4 16 814.57 818.89 -0.53%
slim-mobilenet 64 7,467.07 7,467.98 -0.01%
slim-nasnetalarge 64 211.15 211.20 -0.02%
slim-resnet50v2 64 3,334.83 3,342.30 -0.22%
bert-mrpc-onnx 8 1,150.01 1,148.63 0.12%
bert-mrpc-tf 1 456.18 457.81 -0.36%
pytorch-examples-wlang-gru 1 339.18 342.34 -0.92%
pytorch-examples-wlang-lstm 1 473.03 466.93 1.31%
torchvision-resnet50_1 1 788.81 793.10 -0.54%
cadene-dpn92_1 1 415.80 413.32 0.60%
cadene-resnext101_1 1 393.70 392.78 0.23%
onnx-taau-downsample 1 396.55 396.46 0.02%
dlrm-criteoterabyte 1 33.78 33.77 0.00%
dlrm-criteoterabyte_fp16 1 51.16 51.15 0.02%
agentmodel 1 10,434.62 10,131.48 2.99%
unet_fp16 2 60.71 60.68 0.05%
resnet50v1_fp16 1 1,032.58 1,037.89 -0.51%
resnet50v1_int8 1 1,054.54 1,046.81 0.74%
bert_base_cased_fp16 64 1,170.28 1,169.82 0.04%
bert_large_uncased_fp16 32 361.36 361.33 0.01%
bert_large_fp16 1 203.28 203.50 -0.11%
distilgpt2_fp16 16 2,241.02 2,239.25 0.08%
yolov5s 1 539.42 540.44 -0.19%
tinyllama 1 43.99 44.01 -0.03%
vicuna-fastchat 1 45.43 45.32 0.23%
whisper-tiny-encoder 1 418.87 419.11 -0.06%
whisper-tiny-decoder 1 402.49 402.75 -0.07%
llama2_7b 1 19.18 19.18 -0.00%
qwen1.5-7b 1 23.68 23.65 0.14%
phi3-3.8b 1 26.87 26.86 0.05%
mask-rcnn 1 12.86 12.82 0.35%
llama3-8b 1 21.85 21.84 0.05%
whisper-large-encoder 1 10.22 10.22 0.02%
whisper-large-decoder 1 104.59 103.52 1.04%
mistral-7b 1 23.87 23.83 0.15%
FLUX.1-schnell 1 763.09 767.72 -0.60%
nan nan nan nan nan%

This build is not recommended to merge 🔴

@migraphx-bot
Copy link
Collaborator


     ✅ bert-mrpc-onnx: PASSED: MIGraphX meets tolerance

❌bert-mrpc-tf: ERROR - check error outputerror: unknown warning option '-Wnrvo' [-Werror,-Wunknown-warning-option]

error: unknown warning option '-Wnrvo' [-Werror,-Wunknown-warning-option]

2025-07-23 02:26:22.732754: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1753255588.086925 181922 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 62973 MB memory: -> device: 0, name: AMD Instinct MI250X/MI250, pci bus id: 0000:b3:00.0
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1753255588.954264 181922 mlir_graph_optimization_pass.cc:401] MLIR V1 optimization pass is not enabled
2025-07-23 02:26:37.422681: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.422735: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.422852: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.422902: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.422954: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.422993: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.423047: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
2025-07-23 02:26:37.423103: E external/local_xla/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:250] bitcode module is required by this HLO module but was not found at ./opencl.bc
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
error: Failure when generating HSACO
2025-07-23 02:26:37.424362: E tensorflow/compiler/mlir/tools/kernel_gen/tf_framework_c_interface.cc:228] INTERNAL: Generating device code failed.
2025-07-23 02:26:37.425686: W tensorflow/core/framework/op_kernel.cc:1829] UNKNOWN: JIT compilation failed.
2025-07-23 02:26:37.425704: I tensorflow/core/framework/local_rendezvous.cc:405] Local rendezvous is aborting with status: UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
2025-07-23 02:26:37.425715: I tensorflow/core/framework/local_rendezvous.cc:405] Local rendezvous is aborting with status: UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
[[import/loss/output/_21]]
2025-07-23 02:26:37.425730: I tensorflow/core/framework/local_rendezvous.cc:424] Local rendezvous recv item cancelled. Key hash: 11217777527359497193
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1407, in _do_call
return fn(*args)
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1390, in _run_fn
return self._call_tf_sessionrun(options, feed_dict, fetch_list,
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1483, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
(0) UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
[[import/loss/output/_21]]
(1) UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
0 successful operations.
0 derived errors ignored.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 359, in
main()
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 335, in main
y_out = sess.run(y, feed_dict=tf_dict)
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 977, in run
result = self._run(None, fetches, feed_dict, options_ptr,
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1220, in _run
results = self._do_run(handle, final_targets, final_fetches,
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1400, in _do_run
return self._do_call(_run_fn, feeds, fetches, targets, options,
File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/client/session.py", line 1426, in _do_call
raise type(e)(node_def, op, message) # pylint: disable=no-value-for-parameter
tensorflow.python.framework.errors_impl.UnknownError: Graph execution error:

Detected at node 'import/bert/embeddings/LayerNorm/moments/SquaredDifference' defined at (most recent call last):
Node: 'import/bert/embeddings/LayerNorm/moments/SquaredDifference'
Detected at node 'import/bert/embeddings/LayerNorm/moments/SquaredDifference' defined at (most recent call last):
Node: 'import/bert/embeddings/LayerNorm/moments/SquaredDifference'
2 root error(s) found.
(0) UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
[[import/loss/output/_21]]
(1) UNKNOWN: JIT compilation failed.
[[{{node import/bert/embeddings/LayerNorm/moments/SquaredDifference}}]]
0 successful operations.
0 derived errors ignored.

Original stack trace for 'import/bert/embeddings/LayerNorm/moments/SquaredDifference':


     ✅ pytorch-examples-wlang-gru: PASSED: MIGraphX meets tolerance

     ✅ pytorch-examples-wlang-lstm: PASSED: MIGraphX meets tolerance

     ✅ dlrm-criteoterabyte: PASSED: MIGraphX meets tolerance

     ✅ agentmodel: PASSED: MIGraphX meets tolerance

🔴unet: FAILED: MIGraphX is not within tolerance - check verbose output


     ✅ resnet50v1: PASSED: MIGraphX meets tolerance

     ✅ bert_base_cased_fp16: PASSED: MIGraphX meets tolerance

🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output


     ✅ bert_large: PASSED: MIGraphX meets tolerance

     ✅ yolov5s: PASSED: MIGraphX meets tolerance

     ✅ tinyllama: PASSED: MIGraphX meets tolerance

     ✅ vicuna-fastchat: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-encoder: PASSED: MIGraphX meets tolerance

     ✅ whisper-tiny-decoder: PASSED: MIGraphX meets tolerance

     ✅ distilgpt2_fp16: PASSED: MIGraphX meets tolerance

     ✅ llama2_7b: PASSED: MIGraphX meets tolerance

     ✅ qwen1.5-7b: PASSED: MIGraphX meets tolerance

     ✅ phi3-3.8b: PASSED: MIGraphX meets tolerance

🔴mask-rcnn: FAILED: MIGraphX is not within tolerance - check verbose output


     ✅ llama3-8b: PASSED: MIGraphX meets tolerance

     ✅ whisper-large-decoder: PASSED: MIGraphX meets tolerance

     ✅ mistral-7b: PASSED: MIGraphX meets tolerance

     ✅ FLUX.1-schnell: PASSED: MIGraphX meets tolerance

Set inputs to be float, fp16 and bf16
Set outputs to be bf16 or float 32 based on stash type
- check for epsilon and stash type explicitly being parsed
- Check input type valid for X input
set these to ensure we're parsing in attributes explicitly.
@TedThemistokleous TedThemistokleous changed the title Add in stash type attr for layernorm Add in stash type attr for layernorm and additional test coverage Jul 24, 2025
This isn't needed as stash type specifies that those variables types are perserved after the first conversion, thus only the input is converted back
…f calculation

Cleaned this up to handle things appropriatley and be more readable since we had everything in parse() as just a large flattented piece of code. In reality the two stages to layer norm can be seperated out.

This allows us to reuse a bunch of items and checks while leveraging std::tuple() to handle input/attrs
Copy link
Contributor

@lakhinderwalia lakhinderwalia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I think you like parse tests more than verify tests :-)

@TedThemistokleous
Copy link
Collaborator Author

Approved. I think you like parse tests more than verify tests :-)

I can add some verify tests at a later point. Just wanted to fix this attribute that's always showing up in logs in a lot of the llms and bigger models we use. The other issue is we aren't checking types fully following OnnxRT spec with the previous parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Cleans up code from stale bits/warnings/previous changes for a previous feature PR Onnx Operators Adding or modifying an Onnx Operator in the MIGraphX codebase simple small or simple changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants