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 Shrink ONNX operator #2240

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

gyulaz-htec
Copy link
Collaborator

Note: depends on #2179, until it's merged marked as Draft

This PR adds support for Shrink ONNX operator.

Resolves migraphx-benchmark#118

@gyulaz-htec gyulaz-htec marked this pull request as draft September 25, 2023 15:00
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Merging #2240 (15ee110) into develop (5139b93) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 15ee110 differs from pull request most recent head 5377305. Consider uploading reports for the commit 5377305 to get more accurate results

@@             Coverage Diff             @@
##           develop    #2240      +/-   ##
===========================================
+ Coverage    91.35%   91.36%   +0.01%     
===========================================
  Files          438      439       +1     
  Lines        16465    16493      +28     
===========================================
+ Hits         15041    15069      +28     
  Misses        1424     1424              
Files Coverage Δ
src/onnx/parse_shrink.cpp 100.00% <100.00%> (ø)

@pfultz2
Copy link
Collaborator

pfultz2 commented Sep 25, 2023

A new migraphx operator should not be created for this. This should use existing operators that should be inserted during parse_onnx.

@gyulaz-htec
Copy link
Collaborator Author

Thanks @pfultz2 I've changed the PR according to that.

@gyulaz-htec gyulaz-htec force-pushed the shrink_op_support branch 2 times, most recently from ce152e5 to c5b573f Compare October 3, 2023 14:21
@gyulaz-htec gyulaz-htec marked this pull request as ready for review October 3, 2023 14:21
@gyulaz-htec gyulaz-htec force-pushed the shrink_op_support branch 2 times, most recently from a30cc59 to fdc4caa Compare October 3, 2023 14:46
@gyulaz-htec gyulaz-htec requested a review from pfultz2 October 4, 2023 07:36
@gyulaz-htec gyulaz-htec added the onnx issues related to onnx support label Oct 4, 2023
Comment on lines 94 to 96
auto filtered =
info.add_instruction(migraphx::make_op("where"), condition_1, x_plus_bias, mb_zero);
return info.add_instruction(migraphx::make_op("where"), condition_2, x_min_bias, filtered);
Copy link
Collaborator

Choose a reason for hiding this comment

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

ONNX spec is unclear to me if they want:

if(x < -lambd){ y = x + bias )
if(x > lambd){ y = x -bias }
else { y = 0}

or

if(x < -lambd){ y = x + bias )
else if(x > lambd){ y = x -bias }
else { y = 0}

It looks like this implements the else if version

Copy link
Collaborator Author

@gyulaz-htec gyulaz-htec Oct 11, 2023

Choose a reason for hiding this comment

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

Good question for example x=0 and lamd=-5 satisfies both conditions . I will check the reference implementation and come back with an answer.

Copy link
Collaborator Author

@gyulaz-htec gyulaz-htec Oct 12, 2023

Choose a reason for hiding this comment

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

Seems like onnxruntime uses the if,else if,else solution (they are using return in each branch): https://github.com/microsoft/onnxruntime/blob/25bbd8d4ebed60c28f702a9fe6b0e6a12c19de9c/onnxruntime/core/providers/cpu/nn/shrink.cc#L37-L47

@gyulaz-htec
Copy link
Collaborator Author

gyulaz-htec commented Oct 16, 2023

@umangyadav I've added the requested test cases to check the conversion handling.
@CharlieL7 as I mentioned above the onnxruntime uses the if elseif else approoach, but my previous solution had some flaws and didn't handle overlapping conditions properly.
I've fixed that and added two verify test cases where the first two conditions can overlap, but the result is picked according to the the first (if) condition.

@causten
Copy link
Collaborator

causten commented Oct 18, 2023

There is a CI failure

@causten
Copy link
Collaborator

causten commented Oct 18, 2023

[ RUN ] test_shrinkmigraphx::shape::uint64_type

/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:342:20: runtime error: -3 is outside the range of representable values of type 'unsigned long'

#0 0xf3c8a0 in migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long> std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m<float const*, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>>(float const*, float const*, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:342:20

#1 0xf39174 in migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long> std::__copy_move_a<false, float const*, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>>(float const*, float const*, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:403:14

#2 0xf39174 in migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long> std::__copy_move_a2<false, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:441:3

#3 0xf39174 in migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long> std::copy<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, migraphx::version_1::basic_iota_iterator<migraphx::version_1::tensor_view_iterator_read<migraphx::version_1::tensor_view<unsigned long>>, unsigned long>) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:473:14

#4 0xf39174 in auto void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::operator()<migraphx::version_1::shape::as<unsigned long>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>) const /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/literal.hpp:118:13

#5 0xf35c15 in void migraphx::version_1::shape::visit<void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>), void migraphx::version_1::shape::visit<void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)>(migraphx::version_1::shape::type_t, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'()>(migraphx::version_1::shape::type_t, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, void migraphx::version_1::shape::visit<void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)>(migraphx::version_1::shape::type_t, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'()) /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/shape.hpp:366:13

#6 0xf359d9 in void migraphx::version_1::shape::visit<void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)>(migraphx::version_1::shape::type_t, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>) /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/shape.hpp:375:16

#7 0xf359d9 in void migraphx::version_1::shape::visit_type<void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)>(void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)::'lambda'(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>)) const /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/shape.hpp:381:9

#8 0xf359d9 in void migraphx::version_1::literal::fill<__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>>(__gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>, __gnu_cxx::__normal_iterator<float const*, std::vector<float, std::allocator<float>>>) /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/literal.hpp:116:17

#9 0xf35799 in migraphx::version_1::literal::literal<float>(migraphx::version_1::shape const&, std::vector<float, std::allocator<float>> const&) /var/jenkins/workspace/AMDMIGraphX_PR-2240/src/include/migraphx/literal.hpp:65:9

#10 0x19c8b9f in test_shrink<(migraphx::version_1::shape::type_t)11>::create_program() const /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/test_shrink.cpp:44:41

#11 0x19c8695 in void register_verify_program_action::apply<test_shrink<(migraphx::version_1::shape::type_t)11>>()::'lambda'()::operator()() const /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/verify_program.hpp:65:45

#12 0x19c8695 in std::_Function_handler<migraphx::version_1::program (), void register_verify_program_action::apply<test_shrink<(migraphx::version_1::shape::type_t)11>>()::'lambda'()>::_M_invoke(std::_Any_data const&) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:285:9

#13 0x1243a2e in std::function<migraphx::version_1::program ()>::operator()() const /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:688:14

#14 0x1243a2e in run_verify::run(int, char const**) const::$_0::operator()() const /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/run_verify.cpp:276:58

#15 0x1243a2e in std::_Function_handler<void (), run_verify::run(int, char const**) const::$_0>::_M_invoke(std::_Any_data const&) /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:300:2

#16 0x125cfb6 in std::function<void ()>::operator()() const /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:688:14

#17 0x125cfb6 in test::driver::run_test_case(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::function<void ()> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>> const&) /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/../include/test.hpp:601:17

#18 0x125535e in test::driver::run(int, char const**) /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/../include/test.hpp:668:25

#19 0x124333e in run_verify::run(int, char const**) const /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/run_verify.cpp:284:7

#20 0xf7fb33 in main /var/jenkins/workspace/AMDMIGraphX_PR-2240/test/verify/main.cpp:81:8

#21 0x7f1af6ca8082 in __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:308:16

#22 0xde1a1d in _start (/var/jenkins/workspace/AMDMIGraphX_PR-2240/build/bin/test_verify+0xde1a1d)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_algobase.h:342:20 in

CMake Error at gdb/test_test_verify_general/run.cmake:16 (message):

Test failed

@gyulaz-htec
Copy link
Collaborator Author

@causten the CI fail should be fixed now

@causten causten merged commit c399062 into ROCm:develop Oct 18, 2023
14 of 15 checks passed
@causten causten deleted the shrink_op_support branch October 18, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
onnx issues related to onnx support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shrink operator is unsupported
5 participants