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

Fix dequantizelinaer simple case with no zero point present #3526

Closed
wants to merge 2 commits into from

Conversation

TedThemistokleous
Copy link
Collaborator

Dequantielinear was failing when only two inputs were given (input, scale) as the zero point type check was applied always instead of when there's 3 inputs. Missed due to missing test cases in verify which would have exercised compute_shape() for the op

Reused existing generated onnx files in parser.

Arose when adding changes for #3445 which uses dequantizelinear before the final dot is produced.

@TedThemistokleous TedThemistokleous added bugfix Fixes a bug found in the code. simple small or simple changes labels Oct 11, 2024
@TedThemistokleous TedThemistokleous self-assigned this Oct 11, 2024
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.17%. Comparing base (c1f4371) to head (0629540).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3526   +/-   ##
========================================
  Coverage    92.17%   92.17%           
========================================
  Files          512      512           
  Lines        21385    21386    +1     
========================================
+ Hits         19712    19713    +1     
  Misses        1673     1673           

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

shivadbhavsar
shivadbhavsar previously approved these changes Oct 11, 2024
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.

Approving this. If you want to fix something additional (left a comment) if that is an issue, please feel free to fix it as well.

{
MIGRAPHX_THROW("DEQUANTIZELINEAR: Zero point and input should be the same type.");
check_shapes{inputs, *this}.same_dims().has(2, 3);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this moved down here? We should still check that the inputs are the same dims even when 2 inputs are given. It makes sense up at the top.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That wont be the case though in this operator would it? I guess we broadcast out scale if its a scalar or its 1-d for the case of scale being a tensor

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's where the issue was coming from when invoking dequantize_linear, zero points weren't present and resulted in an error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What was the error specifically? This allows either 2 or 3 inputs so it shouldn't throw an error for 2 inputs.

Copy link
Collaborator Author

@TedThemistokleous TedThemistokleous Oct 14, 2024

Choose a reason for hiding this comment

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

image

would invoke

terminate called after throwing an instance of 'migraphx::version_1::exception'
  what():  /code/AMDMIGraphX/src/include/migraphx/check_shapes.hpp:220: same_dims: dequantizelinear: Dimensions do not match'''
  

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless you want us to always broadcast the scale dimensions (even if its 1-d) but then that means we're inserting a broadcast to remove later. For the scale here, we're never supposed to have the same dimensions between input and scale vectors. Its why I gated this check by input size.

Copy link
Contributor

@shivadbhavsar shivadbhavsar Oct 14, 2024

Choose a reason for hiding this comment

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

Actually it looks like the op is intended to work this way where the scales and zero points should already be broadcasted. The parser for dequantizelinear also puts this broadcast in. I dont think this is a bug, your test case should have a broadcast for the scales.

Im not sure what you mean by remove later?

Copy link
Collaborator

@pfultz2 pfultz2 left a comment

Choose a reason for hiding this comment

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

We should still check that all inputs have the same dimensions even when 2 parameters are used.

@migraphx-bot
Copy link
Collaborator

Test Batch Rate new
062954
Rate old
bdbe34
Diff Compare
torchvision-resnet50 64 3,259.59 3,258.84 0.02%
torchvision-resnet50_fp16 64 6,990.62 6,981.91 0.12%
torchvision-densenet121 32 2,436.07 2,436.52 -0.02%
torchvision-densenet121_fp16 32 4,076.14 4,070.78 0.13%
torchvision-inceptionv3 32 1,639.43 1,640.50 -0.07%
torchvision-inceptionv3_fp16 32 2,762.31 2,764.39 -0.08%
cadene-inceptionv4 16 776.92 777.25 -0.04%
cadene-resnext64x4 16 807.97 809.84 -0.23%
slim-mobilenet 64 7,539.24 7,537.85 0.02%
slim-nasnetalarge 64 211.83 211.79 0.02%
slim-resnet50v2 64 3,506.73 3,504.89 0.05%
bert-mrpc-onnx 8 1,147.37 1,152.66 -0.46%
bert-mrpc-tf 1 470.65 463.93 1.45%
pytorch-examples-wlang-gru 1 422.96 485.39 -12.86% 🔴
pytorch-examples-wlang-lstm 1 395.65 384.58 2.88%
torchvision-resnet50_1 1 810.67 817.62 -0.85%
cadene-dpn92_1 1 402.30 399.06 0.81%
cadene-resnext101_1 1 382.46 382.30 0.04%
onnx-taau-downsample 1 343.07 343.08 -0.00%
dlrm-criteoterabyte 1 33.35 33.33 0.05%
dlrm-criteoterabyte_fp16 1 52.72 52.74 -0.04%
agentmodel 1 8,491.13 8,377.88 1.35%
unet_fp16 2 58.91 58.79 0.21%
resnet50v1_fp16 1 925.98 937.71 -1.25%
resnet50v1_int8 1 994.67 1,041.29 -4.48% 🔴
bert_base_cased_fp16 64 1,171.44 1,170.74 0.06%
bert_large_uncased_fp16 32 363.51 363.58 -0.02%
bert_large_fp16 1 198.68 199.03 -0.17%
distilgpt2_fp16 16 2,202.21 2,199.30 0.13%
yolov5s 1 532.26 540.42 -1.51%
tinyllama 1 43.50 43.45 0.11%
vicuna-fastchat 1 173.63 169.65 2.35%
whisper-tiny-encoder 1 418.71 418.63 0.02%
whisper-tiny-decoder 1 434.40 430.21 0.97%

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

@TedThemistokleous
Copy link
Collaborator Author

Not a bug. In MIGraphX we handle this as pointwise so we need to have everything broadcasted to the input to avoid index operations

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. simple small or simple changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants