Skip to content
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

catch python buffer unsupported types #3701

Merged
merged 5 commits into from
Dec 12, 2024
Merged

catch python buffer unsupported types #3701

merged 5 commits into from
Dec 12, 2024

Conversation

shivadbhavsar
Copy link
Contributor

Issue:
New datatypes (fp8 and bf16) are not natively supported by the python buffer protocol. See https://docs.python.org/3/library/struct.html#format-characters

This can lead to some silly behavior since all unsupported types seem to give format string "z". Example:

import migraphx
p = migraphx.program()
mm = p.get_main_module()
s = migraphx.shape(type="bf16_type", lens=[16])
a = migraphx.generate_argument(s) 
l = mm.add_literal(a)
print(a.get_shape()) # bf16_type, {16}, {1}
print(l.shape()) # fp8e5m2fnuz_type, {16}, {2} ??????????

Fix:

  1. explicitly error out if the python buffer format string is "z".
  2. add add_literal_from_argument method that allows the user to directly add an argument to some module they may or may not be a recognized type by py buffer protocol.

@shivadbhavsar shivadbhavsar self-assigned this Dec 11, 2024
@shivadbhavsar shivadbhavsar added the bugfix Fixes a bug found in the code. label Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.23%. Comparing base (0860461) to head (fb0500a).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3701   +/-   ##
========================================
  Coverage    92.23%   92.23%           
========================================
  Files          514      514           
  Lines        21746    21746           
========================================
  Hits         20057    20057           
  Misses        1689     1689           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/py/migraphx_py.cpp Outdated Show resolved Hide resolved
@migraphx-bot
Copy link
Collaborator

Test Batch Rate new
fb0500
Rate old
086046
Diff Compare
torchvision-resnet50 64 3,257.31 3,255.59 0.05%
torchvision-resnet50_fp16 64 6,991.53 6,973.76 0.25%
torchvision-densenet121 32 2,434.46 2,432.94 0.06%
torchvision-densenet121_fp16 32 4,046.86 4,068.82 -0.54%
torchvision-inceptionv3 32 1,627.31 1,627.80 -0.03%
torchvision-inceptionv3_fp16 32 2,745.70 2,748.46 -0.10%
cadene-inceptionv4 16 765.46 764.89 0.07%
cadene-resnext64x4 16 812.00 813.14 -0.14%
slim-mobilenet 64 7,460.36 7,464.91 -0.06%
slim-nasnetalarge 64 209.02 208.99 0.01%
slim-resnet50v2 64 3,441.25 3,438.12 0.09%
bert-mrpc-onnx 8 1,145.53 1,144.42 0.10%
bert-mrpc-tf 1 479.26 469.74 2.03%
pytorch-examples-wlang-gru 1 415.68 423.59 -1.87%
pytorch-examples-wlang-lstm 1 397.75 378.46 5.10% 🔆
torchvision-resnet50_1 1 814.68 753.15 8.17% 🔆
cadene-dpn92_1 1 398.54 434.07 -8.18% 🔴
cadene-resnext101_1 1 382.82 381.61 0.32%
onnx-taau-downsample 1 345.38 345.60 -0.06%
dlrm-criteoterabyte 1 33.33 33.33 -0.00%
dlrm-criteoterabyte_fp16 1 52.75 52.71 0.07%
agentmodel 1 8,258.39 8,466.76 -2.46%
unet_fp16 2 58.74 58.76 -0.02%
resnet50v1_fp16 1 935.49 923.27 1.32%
resnet50v1_int8 1 1,017.41 1,005.45 1.19%
bert_base_cased_fp16 64 1,169.08 1,168.88 0.02%
bert_large_uncased_fp16 32 362.89 363.10 -0.06%
bert_large_fp16 1 198.52 198.60 -0.05%
distilgpt2_fp16 16 2,195.64 2,199.62 -0.18%
yolov5s 1 528.08 528.00 0.02%
tinyllama 1 43.60 43.67 -0.15%
vicuna-fastchat 1 174.17 171.38 1.63%
whisper-tiny-encoder 1 417.56 417.67 -0.03%
whisper-tiny-decoder 1 427.17 428.88 -0.40%

This build is not recommended to merge 🔴

@migraphx-bot
Copy link
Collaborator


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

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

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

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

     ✅ torchvision-resnet50_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-dpn92_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-resnext101_1: PASSED: MIGraphX meets tolerance

     ✅ dlrm-criteoterabyte: PASSED: MIGraphX meets tolerance

     ✅ agentmodel: PASSED: MIGraphX meets tolerance

     ✅ unet: PASSED: MIGraphX meets tolerance

     ✅ 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

@causten causten merged commit 6f6705c into develop Dec 12, 2024
43 of 45 checks passed
@causten causten deleted the py_buffer_issue branch December 12, 2024 03:45
apwojcik pushed a commit that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes a bug found in the code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants