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

Add support for the dilations attribute to Pooling ops #2105

Merged
merged 21 commits into from
Nov 22, 2023

Conversation

mirza-halilcevic
Copy link
Collaborator

@mirza-halilcevic mirza-halilcevic commented Aug 22, 2023

@umangyadav
Copy link
Member

umangyadav commented Aug 22, 2023

For such changes, it would require tests inside
ref_ops_test.cpp which tests whether reference implementation inside MIGraphX is correct or not.
op_shape_test.cpp. to test for the compute_shape() part
onnx_test.cpp to test whether MIGraphX is parsing operator correctly or not.

and verify tests. which would run the operator/program on GPU and compare it with the reference implementation. Looks like MIOpen doesn't support dilations so we won't have GPU implementation.

@pfultz2
Copy link
Collaborator

pfultz2 commented Aug 22, 2023

Looks like MIOpen doesn't support dilations so we won't have GPU implementation.

@umangyadav Is there a way we can insert some other operators to get the same dilation result on the GPU, similar to how we do for non-symmetrical padding? Like using step or reshape/broadcast/reshape?

@attila-dusnoki-htec
Copy link
Collaborator

We updated the test part where dilations where missing, and added new tests as well.
Note: this version does not support non-default dtilations on GPU yet.

@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

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

❗ No coverage uploaded for pull request base (develop@c7bae54). Click here to learn what that means.

❗ Current head 39491c4 differs from pull request most recent head 1e83d83. Consider uploading reports for the commit 1e83d83 to get more accurate results

Files Patch % Lines
src/include/migraphx/op/pooling.hpp 85.71% 3 Missing ⚠️
src/rewrite_pooling.cpp 98.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #2105   +/-   ##
==========================================
  Coverage           ?   91.39%           
==========================================
  Files              ?      440           
  Lines              ?    16591           
  Branches           ?        0           
==========================================
  Hits               ?    15162           
  Misses             ?     1429           
  Partials           ?        0           

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

@attila-dusnoki-htec
Copy link
Collaborator

cc @pfultz2
I looked at "step" op, but still did not managed to figure out what you meant. 😞
Instead I ended up collecting the axes, and creating the input with gather.
It works, but has a serious limitation: the axes is a vector and can become too large, which results in bad alloc.

@pfultz2
Copy link
Collaborator

pfultz2 commented Sep 8, 2023

I looked at "step" op, but still did not managed to figure out what you meant.

You would insert a step operator with the same value as the dilation, and using the axes for the image. Like `make_op("step", {{"axes", {2, 3}}, {"steps", {dilation_for_h, dilation_for_w}}}).

@mirza-halilcevic mirza-halilcevic marked this pull request as ready for review September 11, 2023 08:05
{
if(idx_w[axis] % dilations[axis])
{
pool_size -= 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

pool_size should be adjusted before calling shape_for_each.

@@ -390,7 +411,15 @@ struct pooling
// this is a padding element. Padding locations
// don't contribute to average or max pooling total but can play in
// lpnorm pooling.
output_val = op(output_val, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should just be output_val = op(output_val, op.template init<Type>());. Using 0 is a bug.


private:
void replace_with_reduce(module& m, instruction_ref ins) const;
void replace_dilations_with_gather_pooling(module& m, instruction_ref ins) const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be static functions defined in rewrite_pooling.cpp file.

for(const auto& d : op.dilations)
ss << d << ",";
ss << "]";
MIGRAPHX_THROW(ss.str());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just do MIGRAPHX_THROW("Unsupported dilations for pooling: [" + to_string_range(op.dilations) + "]") instead.

@attila-dusnoki-htec
Copy link
Collaborator

Addressed requested changes, except this:

pool_size should be adjusted before calling shape_for_each.

I tried to calculate it beforehand, but did not managed to resolve the dyn pad cases properly 😞 (avgpool_dyn_auto_pad_test, avgpool_dyn_pad_ceil_test)
The current approach is the most straighforward. But i can try again if that is a blocker.

@causten causten requested review from umangyadav and pfultz2 October 25, 2023 13:07
@@ -80,6 +81,483 @@ TEST_CASE(rewrite_pooling_test)
migraphx::make_op("reduce_max", {{"axes", {2, 3, 4}}}));
}

TEST_CASE(rewrite_pooling_dialtions_test)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
TEST_CASE(rewrite_pooling_dialtions_test)
TEST_CASE(rewrite_pooling_dilations_test)

auto result = p.eval({}).back();
std::vector<float> results_vector;
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold{0.7812, 1.0449, 2.7666, 2.6859};
Copy link
Collaborator

Choose a reason for hiding this comment

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

How are you getting these gold values? Want to make sure that we know these are correct.

@causten causten merged commit 19bd9c4 into ROCm:develop Nov 22, 2023
11 of 12 checks passed
@causten causten deleted the pooling_dilations branch November 22, 2023 18:59
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.

Pool dilations attribute
6 participants