-
Notifications
You must be signed in to change notification settings - Fork 129
[AIMIGRAPHX-1003] Add warnings for dim and value not set #4850
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
262e5c6
d4c1640
a567dc2
fdbbc0b
1446bca
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 |
|---|---|---|
|
|
@@ -37,8 +37,10 @@ | |
| #include <migraphx/op/unknown.hpp> | ||
| #include <migraphx/float8.hpp> | ||
| #include <migraphx/env.hpp> | ||
| #include <migraphx/logger.hpp> | ||
| #include <onnx.pb.h> | ||
| #include <iomanip> | ||
| #include <set> | ||
| #include <sstream> | ||
|
|
||
| namespace migraphx { | ||
|
|
@@ -259,6 +261,33 @@ void onnx_parser::parse_undefined(module* mod, const std::string& name) | |
| } | ||
| } | ||
|
|
||
| static void warn_unresolved_dim_params(const onnx_parser& parser, const onnx::GraphProto& graph) | ||
| { | ||
| if(parser.default_set) | ||
| return; | ||
| std::set<std::string> unresolved; | ||
| for(const auto& input : graph.input()) | ||
| { | ||
| if(contains(parser.map_input_dims, input.name()) or | ||
| contains(parser.map_dyn_input_dims, input.name())) | ||
| continue; | ||
|
eddieliao marked this conversation as resolved.
|
||
| for(const auto& d : input.type().tensor_type().shape().dim()) | ||
| { | ||
| // Skip batch dims and dims that are already set | ||
| if(d.has_dim_param() and not contains(parser.dim_params, d.dim_param()) and | ||
| to_lower(d.dim_param()).find("batch") == std::string::npos) | ||
|
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. The batch dimension is not always named batch so I dont think you can rely on that.
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. How often would a batch dimension not contain the word "batch"? The only example I can think of right now would be just using "N", which I can add an edge case for if desired. |
||
| unresolved.insert(d.dim_param()); | ||
| } | ||
| } | ||
| if(unresolved.empty()) | ||
| return; | ||
| log::warn() << "Model has unbound symbolic dimension(s): " | ||
|
eddieliao marked this conversation as resolved.
|
||
| << join_strings(std::move(unresolved), ", ") << ". These default to " | ||
| << parser.default_dyn_dim_value << " and may cause unexpected behavior. " | ||
| << "Try setting `--dim-param @<name> <value>` or `--input-dim @<input> <dims>` " | ||
|
eddieliao marked this conversation as resolved.
|
||
| "if program compilation fails."; | ||
| } | ||
|
|
||
| void onnx_parser::parse_from(std::istream& is, std::string name) | ||
| { | ||
| auto* mm = prog.get_main_module(); | ||
|
|
@@ -275,6 +304,7 @@ void onnx_parser::parse_from(std::istream& is, std::string name) | |
|
|
||
| if(model.has_graph()) | ||
| { | ||
| warn_unresolved_dim_params(*this, model.graph()); | ||
| (void)this->parse_graph(mm, model.graph()); | ||
| } | ||
| } | ||
|
|
@@ -295,6 +325,7 @@ void onnx_parser::parse_from(const void* data, std::size_t size) | |
|
|
||
| if(model.has_graph()) | ||
| { | ||
| warn_unresolved_dim_params(*this, model.graph()); | ||
| (void)this->parse_graph(mm, model.graph()); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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 <migraphx/migraphx.h> | ||
| #include <migraphx/migraphx.hpp> | ||
| #include <migraphx/logger.hpp> | ||
| #include <read_onnx.hpp> | ||
| #include "test.hpp" | ||
|
|
||
| namespace { | ||
| struct warning_sink | ||
| { | ||
| std::vector<std::string> messages; | ||
| std::size_t id; | ||
|
|
||
| warning_sink() | ||
| { | ||
| id = migraphx::log::add_sink( | ||
| [this](migraphx::log::severity, std::string_view msg, migraphx::source_location) { | ||
| messages.emplace_back(msg); | ||
| }, | ||
| migraphx::log::severity::warn); | ||
| } | ||
|
|
||
| ~warning_sink() { migraphx::log::remove_sink(id); } | ||
|
|
||
| bool any_unbound_dim_warning() const | ||
| { | ||
| return std::any_of(messages.begin(), messages.end(), [](const std::string& m) { | ||
| return m.find("unbound symbolic dimension") != std::string::npos; | ||
| }); | ||
| } | ||
| }; | ||
| } // namespace | ||
|
|
||
| TEST_CASE(set_default_dim_value_suppresses_unbound_dim_warning) | ||
| { | ||
| warning_sink sink; | ||
| migraphx::onnx_options opts; | ||
| opts.set_default_dim_value(4); | ||
| (void)read_onnx("dim_param_test.onnx", opts); | ||
|
|
||
| EXPECT(not sink.any_unbound_dim_warning()); | ||
| } | ||
|
|
||
| TEST_CASE(set_default_dyn_dim_value_suppresses_unbound_dim_warning) | ||
| { | ||
| warning_sink sink; | ||
| migraphx::onnx_options opts; | ||
| opts.set_default_dyn_dim_value(migraphx::dynamic_dimension{1, 1}); | ||
| (void)read_onnx("dim_param_test.onnx", opts); | ||
|
|
||
| EXPECT(not sink.any_unbound_dim_warning()); | ||
| } | ||
|
|
||
| TEST_CASE(unbound_dim_param_emits_warning) | ||
| { | ||
| warning_sink sink; | ||
| (void)read_onnx("dim_param_test.onnx"); | ||
|
|
||
| EXPECT(sink.any_unbound_dim_warning()); | ||
| } | ||
|
|
||
| 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.
Not all inputs require explicit values. Most dont require this. I think this warning is just too noisy.
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.
The idea was to warn when users didn't set values for inputs such as the attention_mask and hopefully reduce the amount of tickets coming to us. Not sure if there's a good list out there for such inputs that require very specific values, but if not I can remove this warning.