-
Notifications
You must be signed in to change notification settings - Fork 128
Fix literal promotion #4826
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
base: develop
Are you sure you want to change the base?
Fix literal promotion #4826
Changes from 5 commits
49eb142
9391d24
106fd25
2f9b73d
4dce31f
0b6ff3c
1c1a60f
27e1629
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. | ||
| * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
|
|
@@ -61,7 +61,7 @@ | |
| { | ||
| std::vector<op_desc> operators() const { return {{"GRU"}}; } | ||
|
|
||
| std::vector<instruction_ref> parse(const op_desc& /*opd*/, | ||
| const onnx_parser& parser, | ||
| onnx_parser::node_info info, | ||
| std::vector<instruction_ref> args) const | ||
|
|
@@ -166,7 +166,12 @@ | |
| { | ||
| gru_transpose_inputs(info, args); | ||
| } | ||
|
|
||
| if(not args[5]->is_undefined() and | ||
| args[5]->get_shape().type() != args[1]->get_shape().type()) | ||
| { | ||
| args[5] = info.add_instruction( | ||
| make_op("convert", {{"target_type", args[1]->get_shape().type()}}), args[5]); | ||
| } | ||
|
Comment on lines
+169
to
+174
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there a specific change for GRU?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, for this specific model just literal change only helped with migraphx driver read command / compile was still failing with types do not match. The fix is in parse_gru.cpp because the type mismatch is introduced by the rewrite_rnn pass, which decomposes the GRU op into dot operations using m.insert_instruction(make_op("dot"), ...) directl; bypassing add_common_op and its type reconciliation. I agree this is odd behaviour; i will send you model via teams; for you to have better understanding of it. |
||
| // first output for concatenation of hidden states | ||
| auto hidden_states = | ||
| info.add_instruction(make_op("gru", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| #include "test.hpp" | ||
| #include <migraphx/common.hpp> | ||
| #include <migraphx/module.hpp> | ||
| #include <migraphx/make_op.hpp> | ||
| #include <migraphx/literal.hpp> | ||
| #include <migraphx/instruction.hpp> | ||
|
|
||
| TEST_CASE(add_common_op_scalar_literal_preserves_tensor_type) | ||
| { | ||
| migraphx::module mm; | ||
|
|
||
| auto tensor = mm.add_parameter("x", migraphx::shape{migraphx::shape::half_type, {1, 100, 128}}); | ||
| auto scalar = | ||
| mm.add_literal(migraphx::literal{migraphx::shape{migraphx::shape::float_type}, {1e-5f}}); | ||
|
|
||
| auto result = migraphx::add_common_op(mm, migraphx::make_op("add"), {tensor, scalar}); | ||
|
|
||
| EXPECT(result->get_shape().type() == migraphx::shape::half_type); | ||
| } | ||
|
|
||
| TEST_CASE(add_common_op_scalar_literal_preserves_tensor_type_reversed) | ||
| { | ||
| migraphx::module mm; | ||
|
|
||
| auto tensor = mm.add_parameter("x", migraphx::shape{migraphx::shape::half_type, {1, 100, 128}}); | ||
| auto scalar = | ||
| mm.add_literal(migraphx::literal{migraphx::shape{migraphx::shape::float_type}, {1e-5f}}); | ||
|
|
||
| auto result = migraphx::add_common_op(mm, migraphx::make_op("add"), {scalar, tensor}); | ||
|
|
||
| EXPECT(result->get_shape().type() == migraphx::shape::half_type); | ||
| } | ||
|
|
||
| TEST_CASE(add_common_op_two_tensors_promotes_to_wider_type) | ||
| { | ||
| migraphx::module mm; | ||
|
|
||
| auto half_tensor = mm.add_parameter("x", migraphx::shape{migraphx::shape::half_type, {1, 128}}); | ||
| auto float_tensor = | ||
| mm.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {1, 128}}); | ||
|
|
||
| auto result = | ||
| migraphx::add_common_op(mm, migraphx::make_op("add"), {half_tensor, float_tensor}); | ||
|
|
||
| EXPECT(result->get_shape().type() == migraphx::shape::float_type); | ||
| } | ||
|
|
||
| TEST_CASE(add_common_op_float_tensor_with_float_scalar_keeps_float) | ||
| { | ||
| migraphx::module mm; | ||
|
|
||
| auto tensor = | ||
| mm.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 100, 128}}); | ||
| auto scalar = | ||
| mm.add_literal(migraphx::literal{migraphx::shape{migraphx::shape::float_type}, {1e-5f}}); | ||
|
|
||
| auto result = migraphx::add_common_op(mm, migraphx::make_op("add"), {tensor, scalar}); | ||
|
|
||
| EXPECT(result->get_shape().type() == migraphx::shape::float_type); | ||
| } | ||
|
|
||
| int main(int argc, const char* argv[]) { test::run(argc, argv); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment explaining the reasoning for this added code block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added