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

Change auto contiguous to always insert contiguous #2038

Closed
wants to merge 85 commits into from

Conversation

kahmed10
Copy link
Collaborator

@kahmed10 kahmed10 commented Aug 4, 2023

No description provided.

@migraphx-bot
Copy link
Collaborator

migraphx-bot commented Aug 4, 2023

Test Batch Rate new
e75181
Rate old
368d59
Diff Compare
torchvision-resnet50 64 2,830.77 2,831.78 -0.04%
torchvision-resnet50_fp16 64 6,501.60 6,493.90 0.12%
torchvision-densenet121 32 2,095.86 2,095.43 0.02%
torchvision-densenet121_fp16 32 3,657.68 3,663.28 -0.15%
torchvision-inceptionv3 32 1,595.17 1,594.90 0.02%
torchvision-inceptionv3_fp16 32 2,561.50 2,560.92 0.02%
cadene-inceptionv4 16 721.53 721.62 -0.01%
cadene-resnext64x4 16 693.84 690.65 0.46%
slim-mobilenet 64 8,437.92 8,320.61 1.41%
slim-nasnetalarge 64 189.10 231.48 -18.31% 🔴
slim-resnet50v2 64 2,693.74 2,662.58 1.17%
bert-mrpc-onnx 8 812.17 813.41 -0.15%
bert-mrpc-tf 1 376.71 386.87 -2.62%
pytorch-examples-wlang-gru 1 350.52 301.62 16.21% 🔆
pytorch-examples-wlang-lstm 1 321.02 313.73 2.32%
torchvision-resnet50_1 1 601.66 605.31 -0.60%
torchvision-inceptionv3_1 1 340.44 345.94 -1.59%
cadene-dpn92_1 1 402.28 401.41 0.22%
cadene-resnext101_1 1 328.20 327.72 0.15%
slim-vgg16_1 1 380.60 458.12 -16.92% 🔴
slim-mobilenet_1 1 2,039.68 2,054.76 -0.73%
slim-inceptionv4_1 1 194.87 214.67 -9.22% 🔴
onnx-taau-downsample 1 285.74 303.28 -5.78% 🔴
dlrm-criteoterabyte 1 23.49 21.58 8.87% 🔆
dlrm-criteoterabyte_fp16 1 41.04 40.64 0.97%
agentmodel 1 6,387.25 6,036.02 5.82% 🔆
unet_fp16 2 54.56 54.73 -0.31%
resnet50v1_fp16 1 929.40 928.82 0.06%
bert_base_cased_fp16 64 924.06 923.61 0.05%
bert_large_uncased_fp16 32 290.39 290.25 0.05%
bert_large_fp16 1 167.69 171.90 -2.45%
distilgpt2_fp16 16 1,514.84 1,512.92 0.13%

This build is not recommended to merge 🔴

@migraphx-bot
Copy link
Collaborator

migraphx-bot commented Aug 4, 2023


     ✅ 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

     ✅ torchvision-inceptionv3_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-dpn92_1: PASSED: MIGraphX meets tolerance

     ✅ cadene-resnext101_1: PASSED: MIGraphX meets tolerance

     ✅ slim-vgg16_1: PASSED: MIGraphX meets tolerance

     ✅ slim-mobilenet_1: PASSED: MIGraphX meets tolerance

     ✅ slim-inceptionv4_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: PASSED: MIGraphX meets tolerance

     ✅ bert_large: PASSED: MIGraphX meets tolerance

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

if(not ins->module_inputs().empty())
m.replace_instruction(ins, ins->get_operator(), new_args, ins->module_inputs());
else
m.replace_instruction(ins, ins->get_operator(), new_args);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You shouldn't replace the input arguments as that can cause multiple contiguous operators to be inserted when its used in multiple places. This should just do:

if(contains({"layout", "contigous"}, ins->name()))
    continue;
// for last instruction that is NOT a return
if(ins->outputs().empty() and ins != last)
    continue;
shape s = ins->get_shape();
if(s.dynamic())
    continue;
if(s.type() == shape::tuple_type)
    continue;
if(s.standard() and ins->name() == "@literal")
    continue;
auto c = m.insert_instruction(std::next(ins), make_op("contiguous"), ins);
m.replace_instruction(ins, c);

return in;
}
return m.insert_instruction(ins, make_op("contiguous"), in);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should still have this until reshape copy is implemented.

@@ -59,17 +60,24 @@ void auto_contiguous::apply(module& m) const
auto last = std::prev(m.end());
for(auto ins : iterator_for(m))
{
if(ins->name() == "layout")
if(contains({"layout", "contiguous", "@return", "@param", "@outline"}, ins->name()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't be skipping @param, is there a test that fails for that?

I dont think @outline is used anywhere.

@@ -161,6 +162,18 @@ static void remove_contiguous(const std::string& op_name, module& m, F f)
}
}

static void remove_contiguous_noops(const std::string& op_name, module& m)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would spell it nop with one o.

auto r = m2.add_instruction(migraphx::make_op("reshape", {{"dims", {2, 1, 12, 5}}}), ca);
m2.add_return({r});
// extra contiguous coming from reshape logic which has "requires_std_shape" attribute
auto cb = m2.add_instruction(migraphx::make_op("contiguous"), ca);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldnt have two contiguous. Maybe we should check that the outputs are all contiguous operators before inserting it in.

continue;
if(s.standard() and ins->name() == "@literal")
continue;
if(s.scalar() and not contains(ins->name(), "broadcast"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would think this would be if(s.scalar() and s.standard()).

@pfultz2 pfultz2 mentioned this pull request Aug 21, 2023
@TedThemistokleous TedThemistokleous self-requested a review August 21, 2023 19:33
@kahmed10 kahmed10 closed this Aug 30, 2023
Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (9941849) 91.43% compared to head (e751814) 91.30%.
Report is 4 commits behind head on develop.

Files Patch % Lines
src/propagate_constant.cpp 40.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2038      +/-   ##
===========================================
- Coverage    91.43%   91.30%   -0.14%     
===========================================
  Files          461      461              
  Lines        17419    17451      +32     
===========================================
+ Hits         15927    15933       +6     
- Misses        1492     1518      +26     

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

@kahmed10 kahmed10 closed this Jan 15, 2024
@TedThemistokleous
Copy link
Collaborator

Why close this out? Guessing rebase and push forward or not needed anymore?

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.

Non-standard reshape fail during reshape_lazy lowering
6 participants