-
Notifications
You must be signed in to change notification settings - Fork 112
[AI generated] AIMIGRAPHX-236 Updated Resize op to support linear mode #4382
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?
Changes from all commits
fe93b3d
2e153d2
b49828d
08cf896
b26f944
3e0cae1
f8a1d28
ceecdcc
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 |
|---|---|---|
|
|
@@ -470,6 +470,20 @@ struct parse_resize : op_parser<parse_resize> | |
| auto out_lens = resize.out_lens; | ||
| auto vec_scale = resize.vec_scale; | ||
|
|
||
| if(args_0->get_shape().dynamic()) | ||
| { | ||
| // Resize's compute_shape() will read scales_sizes_arg as "scales" or "sizes" | ||
| // depending on its data type | ||
|
|
||
| return info.add_instruction( | ||
| make_op("resize", | ||
| {{"mode", "linear"}, | ||
| {"scales", vec_scale}, | ||
| {"coordinate_transformation_mode", resize.get_coord_trans_mode()}}), | ||
| args_0, | ||
| resize.get_scales_sizes_arg()); | ||
| } | ||
|
Comment on lines
+473
to
+485
|
||
|
|
||
| // out_lens and other variables can't be populated if non-constant (runtime) size | ||
| // inputs. | ||
| if(not resize.is_constant_scale_input()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2025 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 <migraphx/register_target.hpp> | ||
| #include <migraphx/verify.hpp> | ||
| #include <onnx_test.hpp> | ||
|
|
||
| TEST_CASE(resize_downsample_linear_dyn_test) | ||
| { | ||
| using migraphx::half; | ||
| migraphx::onnx_options options; | ||
| options.map_dyn_input_dims = {{"X", {{1, 1}, {1, 1}, {2, 3}, {4, 8}}}}; | ||
| migraphx::program p = read_onnx("resize_downsample_linear_half_test.onnx", options); | ||
| p.compile(migraphx::make_target("ref")); | ||
|
|
||
| migraphx::shape sx{migraphx::shape::half_type, {1, 1, 2, 4}}; | ||
| std::vector<half> dx = {half{1}, half{2}, half{3}, half{4}, half{5}, half{6}, half{7}, half{8}}; | ||
|
|
||
| migraphx::parameter_map pp; | ||
| pp["X"] = migraphx::argument(sx, dx.data()); | ||
|
|
||
| auto result = p.eval(pp).back(); | ||
| std::vector<half> result_vector; | ||
| result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); | ||
|
|
||
| // Expected output was calculated without any quantization | ||
| std::vector<half> gold = {half{2.8333333}, half{4.833333}}; | ||
|
|
||
| EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2025 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 <migraphx/register_target.hpp> | ||
| #include <migraphx/verify.hpp> | ||
| #include <onnx_test.hpp> | ||
|
|
||
| TEST_CASE(resize_upsample_linear_dyn_test) | ||
| { | ||
| migraphx::onnx_options options; | ||
| options.map_dyn_input_dims = {{"X", {{1, 1}, {1, 1}, {2, 3}, {2, 3}}}}; | ||
|
|
||
| migraphx::program p = read_onnx("resize_upsample_linear_test.onnx", options); | ||
| p.compile(migraphx::make_target("ref")); | ||
|
|
||
| migraphx::shape sx{migraphx::shape::float_type, {1, 1, 2, 2}}; | ||
| std::vector<float> dx = {1.0f, 2.0f, 3.0f, 4.0f}; | ||
|
|
||
| migraphx::parameter_map pp; | ||
| pp["X"] = migraphx::argument(sx, dx.data()); | ||
|
|
||
| auto result = p.eval(pp).back(); | ||
| std::vector<float> result_vector; | ||
| result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); | ||
|
|
||
| std::vector<float> gold = { | ||
| 1, 1.25, 1.75, 2, 1.5, 1.75, 2.25, 2.5, 2.5, 2.75, 3.25, 3.5, 3, 3.25, 3.75, 4}; | ||
|
|
||
| EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); | ||
| } |
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.
This (line) is pre-existing. But conceptually, why set dyn_dims to
{0, max_val}. Surely, size0is too small for aresizeoperator. Thanks.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.
This was to signify that no tensor information is known at compile time. We may update this to be {1, max_val} because a dimension can never be < 1, but we need to do this in other places in the codebase for consistency.