-
Notifications
You must be signed in to change notification settings - Fork 95
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 Qlinearconcat op #2476
Merged
Merged
Add Qlinearconcat op #2476
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015-2023 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/onnx/op_parser.hpp> | ||
#include <migraphx/onnx/padding.hpp> | ||
#include <migraphx/onnx/conv.hpp> | ||
#include <migraphx/ranges.hpp> | ||
#include <migraphx/make_op.hpp> | ||
#include <migraphx/onnx/checks.hpp> | ||
#include <migraphx/onnx/broadcast_qdq.hpp> | ||
#include <migraphx/instruction.hpp> | ||
#include <migraphx/stringutils.hpp> | ||
|
||
namespace migraphx { | ||
inline namespace MIGRAPHX_INLINE_NS { | ||
namespace onnx { | ||
|
||
struct parse_qlinearconcat : op_parser<parse_qlinearconcat> | ||
{ | ||
std::vector<op_desc> operators() const { return {{"QLinearConcat"}}; } | ||
|
||
// basic type checking for QLinearConcat Operator | ||
void check_inputs(const std::vector<instruction_ref>& args) const | ||
{ | ||
auto args_size = args.size(); | ||
// at least 5 input tensors: | ||
// 1. is Y_scale: tensor(float) | ||
// 2. is Y_zero_pont: tensor(uint8)/tensor(int8) | ||
// remaining is a sequence of : | ||
// 3. Tensor: tensor(uint8)/tensor(int8) | ||
// 4. Scale: tensor(float), | ||
// 5. ZeroPoint: tensor(uint8)/tensor(int8) tensors | ||
// Size can be 5, 8, 11 ... | ||
if((args_size < 5) or ((args_size - 2) % 3 != 0)) | ||
MIGRAPHX_THROW("QLINEARCONCAT: missing inputs"); | ||
|
||
auto y_zp = args[1]; | ||
auto y_zp_type = y_zp->get_shape().type(); | ||
if(y_zp_type != migraphx::shape::int8_type and y_zp_type != migraphx::shape::uint8_type) | ||
MIGRAPHX_THROW("QLINEARCONCAT: unsupported output type"); | ||
|
||
auto t0_type = args[2]->get_shape().type(); | ||
if(t0_type != migraphx::shape::int8_type and t0_type != migraphx::shape::uint8_type) | ||
MIGRAPHX_THROW("QLINEARCONCAT: unsupported input type"); | ||
for(auto idx = 2; idx < args.size(); idx += 3) | ||
{ | ||
if((args[idx]->get_shape().type() != t0_type) or | ||
(args[idx + 2]->get_shape().type() != t0_type)) | ||
{ | ||
MIGRAPHX_THROW("QLINEARCONCAT: mismatching input types"); | ||
} | ||
} | ||
} | ||
|
||
instruction_ref parse(const op_desc& /* opd */, | ||
const onnx_parser& parser, | ||
const onnx_parser::node_info& info, | ||
const std::vector<instruction_ref>& args) const | ||
{ | ||
check_inputs(args); | ||
if(not contains(info.attributes, "axis")) | ||
MIGRAPHX_THROW("QLINEARCONCAT: missing axis attribute"); | ||
|
||
auto axis = parser.parse_value(info.attributes.at("axis")).template at<int64_t>(); | ||
std::vector<instruction_ref> tmp; | ||
for(auto idx = 2; idx < args.size(); idx += 3) | ||
{ | ||
auto data_tensor = args[idx]; | ||
auto scale = args[idx + 1]; | ||
auto zero_pt = args[idx + 2]; | ||
tmp.push_back(bcast_qdq_instr("dequantizelinear", data_tensor, scale, zero_pt, info)); | ||
} | ||
auto y = info.add_instruction(migraphx::make_op("concat", {{"axis", axis}}), tmp); | ||
|
||
auto y_scale = args[0]; | ||
auto y_zero_pt = args[1]; | ||
|
||
return bcast_qdq_instr("quantizelinear", y, y_scale, y_zero_pt, info); | ||
} | ||
}; | ||
|
||
} // namespace onnx | ||
} // namespace MIGRAPHX_INLINE_NS | ||
} // namespace migraphx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Aren't the inputs supposed to be tuples? As in each input with type
TV
is a tuple of(Tensor, Scale, ZeroPoint)
. The spec says(3 - inf)
inputs, so that's what I would expect.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.
I've checked the models in the description and those inputs are parsed just a simple sequence of tensors, I can't see any tuple type for shapes there.
For MaskRCNN-int8 I can see the following inputs for QLinearConcat operator:
Is there any specific parsing option for tuple_type?
ONNX Runtime also parses these inputs as a sequence of tensors:
https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/contrib_ops/cpu/quantization/qlinear_concat.cc#L18-L19
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.
Given that the models use the operator that way, the way the code is currently makes sense to me. I also don't think there is a tuple type in ONNX. The spec is problematic however (Microsoft probably made a mistake). I would like the docstring with the spec on this operator deleted and something that reflects the code to be written instead.
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.
Removed the docstring and added comments about the actual input tensor layout in the input checking part.