Skip to content

rebias uint8 to int8 on models with mixed datatypes#5075

Draft
kahmed10 wants to merge 2 commits into
developfrom
int8_fixes
Draft

rebias uint8 to int8 on models with mixed datatypes#5075
kahmed10 wants to merge 2 commits into
developfrom
int8_fixes

Conversation

@kahmed10

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Follow the LLVM AI Tool Use Policy for contributions using AI.

Comment on lines +393 to +395
auto q1 = add_quantize_op(m1, "quantizelinear", x, scale, zero);
auto rs = m1.add_instruction(migraphx::make_op("reshape", {{"dims", {1, 1024}}}), q1);
auto d1 = add_quantize_op(m1, "dequantizelinear", rs, scale, zero);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[format.py] reported by reviewdog 🐶

Suggested change
auto q1 = add_quantize_op(m1, "quantizelinear", x, scale, zero);
auto rs = m1.add_instruction(migraphx::make_op("reshape", {{"dims", {1, 1024}}}), q1);
auto d1 = add_quantize_op(m1, "dequantizelinear", rs, scale, zero);
auto q1 = add_quantize_op(m1, "quantizelinear", x, scale, zero);
auto rs = m1.add_instruction(migraphx::make_op("reshape", {{"dims", {1, 1024}}}), q1);
auto d1 = add_quantize_op(m1, "dequantizelinear", rs, scale, zero);

Comment on lines +41 to +42
auto scale = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {0.05f}});
auto zp = mm->add_literal(migraphx::literal{migraphx::shape::uint8_type, {0}});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[format.py] reported by reviewdog 🐶

Suggested change
auto scale = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {0.05f}});
auto zp = mm->add_literal(migraphx::literal{migraphx::shape::uint8_type, {0}});
auto scale = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {0.05f}});
auto zp = mm->add_literal(migraphx::literal{migraphx::shape::uint8_type, {0}});

// Rebias to int8 by subtracting 128 through int32 (same IR as rebias_uint8_to_int8).
auto q_i32 = mm->add_instruction(
migraphx::make_op("convert", {{"target_type", migraphx::shape::int32_type}}), q);
auto k128 = mm->add_literal(migraphx::literal{migraphx::shape::int32_type, {128}});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[format.py] reported by reviewdog 🐶

Suggested change
auto k128 = mm->add_literal(migraphx::literal{migraphx::shape::int32_type, {128}});
auto k128 = mm->add_literal(migraphx::literal{migraphx::shape::int32_type, {128}});

// Stop when crossing a type category boundary (e.g., int or fp8 to float)
if(not same_category(precision{output->get_shape().type()}, target))
continue;
if(not inputs_match_category(output, target))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add unit tests for these changes?

TEST_CASE(simplify_concat_dequantizelinear)
{
// dequantizelinear must not be pulled back through the concat: that would leave the concat
// operating on integer values, which some backends (e.g. rocMLIR) cannot fuse.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

rocMLIR doesnt fuse concat either way. I dont really understand why we arent fusing the dequantizelinear.

@gh-app-migraphx-bot-pr-write

Copy link
Copy Markdown
Test Batch New Rate (b45086) Old Rate (1a5bb6) Diff Status
torchvision-resnet50 64 3,286.92 3,265.81 0.65%
torchvision-resnet50_fp16 64 7,622.36 7,548.56 0.98%
torchvision-densenet121 32 2,502.03 2,481.85 0.81%
torchvision-densenet121_fp16 32 5,032.22 4,975.40 1.14%
torchvision-inceptionv3 32 2,064.72 2,060.05 0.23%
torchvision-inceptionv3_fp16 32 4,429.64 4,414.40 0.35%
cadene-inceptionv4 16 822.04 584.00 40.76% 🔆
cadene-resnext64x4 16 785.86 782.84 0.39%
slim-mobilenet 64 8,426.87 7,190.62 17.19% 🔆
slim-nasnetalarge 64 229.86 222.84 3.15%
slim-resnet50v2 64 3,205.32 2,017.65 58.86% 🔆
bert-mrpc-onnx 8 1,170.74 1,168.85 0.16%
bert-mrpc-tf 1 485.89 487.56 -0.34%
pytorch-examples-wlang-gru 1 500.20 477.33 4.79%
pytorch-examples-wlang-lstm 1 388.19 387.83 0.09%
torchvision-resnet50_1 1 1,030.67 1,038.23 -0.73%
cadene-dpn92_1 1 453.29 449.51 0.84%
cadene-resnext101_1 1 366.15 365.36 0.22%
onnx-taau-downsample 1 851.82 844.73 0.84%
dlrm-criteoterabyte 1 32.59 17.44 86.83% 🔆
dlrm-criteoterabyte_fp16 1 52.68 31.21 68.80% 🔆
agentmodel 1 8,261.73 5,880.42 40.50% 🔆
unet_fp16 2 59.17 52.15 13.46% 🔆
resnet50v1_fp16 1 1,351.97 1,385.99 -2.45%
resnet50v1_int8 1 1,660.83 1,657.40 0.21%
bert_base_cased_fp16 64 1,105.00 1,022.83 8.03% 🔆
bert_large_uncased_fp16 32 347.53 339.30 2.42%
bert_large_fp16 1 205.29 205.64 -0.17%
distilgpt2_fp16 16 2,096.03 2,086.12 0.47%
yolov5s 1 560.46 560.85 -0.07%
tinyllama 1 46.08 45.80 0.59%
vicuna-fastchat 1 44.18 44.03 0.35%
whisper-tiny-encoder 1 414.88 328.75 26.20% 🔆
whisper-tiny-decoder 1 411.75 214.20 92.23% 🔆
llama2_7b 1 21.03 14.70 43.04% 🔆
qwen1.5-7b 1 23.71 23.49 0.94%
phi3-3.8b 1 26.90 26.78 0.47%
llama3-8b 1 21.83 21.70 0.59%
whisper-large-encoder 1 10.24 8.77 16.72% 🔆
whisper-large-decoder 1 104.79 109.89 -4.64%
mistral-7b 1 23.89 23.65 0.99%
FLUX.1-schnell 1 771.44 172.94 346.08% 🔆

Check flagged results 🔆

@gh-app-migraphx-bot-pr-write

Copy link
Copy Markdown
Test Status Result
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
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
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-encoder PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants