-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Fix] in Xnnpack EP, the conversion for fused activation param isn't correct #23115
Draft
mszhanyi
wants to merge
7
commits into
main
Choose a base branch
from
zhanyi/activationparam
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−3
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba52bc0
fix activate parameter in fp16
invalid-email-address 6032820
add test data
invalid-email-address 242c182
rm useless change
invalid-email-address 7c7f16a
node assignment some for FP16
invalid-email-address 3d75696
update
invalid-email-address c4f0455
update
invalid-email-address dd9865f
head file
invalid-email-address 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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,9 +6,11 @@ | |||||||||
|
||||||||||
#include "core/common/logging/logging.h" | ||||||||||
#include "core/common/span_utils.h" | ||||||||||
#include "core/framework/float16.h" | ||||||||||
#include "core/framework/utils.h" | ||||||||||
#include "core/graph/graph.h" | ||||||||||
#include "core/providers/xnnpack/xnnpack_execution_provider.h" | ||||||||||
#include "core/providers/xnnpack/xnnpack_init.h" | ||||||||||
#include "core/session/inference_session.h" | ||||||||||
#include "core/session/onnxruntime_cxx_api.h" | ||||||||||
#include "core/session/onnxruntime_session_options_config_keys.h" | ||||||||||
|
@@ -89,6 +91,51 @@ TEST(XnnpackEP, TestNhwcConvReluClipFusion) { | |||||||||
RunAndVerifyOutputsWithEP(ort_model_path, "TestNhwcConvReluClipFusion", std::move(ep), feeds, params); | ||||||||||
} | ||||||||||
|
||||||||||
#ifdef XNNPACK_FP16_SUPPORTED | ||||||||||
TEST(XnnpackEP, TestNhwcConvReluClipFusion_FP16) { | ||||||||||
const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "nhwc_conv_clip_relu_fp16.onnx"; | ||||||||||
|
||||||||||
RandomValueGenerator generator; | ||||||||||
TensorShape input_shape_x{1, 16, 16, 192}; | ||||||||||
std::vector<MLFloat16> input_x = generator.Uniform<MLFloat16>(input_shape_x.GetDims(), -128, 128); | ||||||||||
|
||||||||||
OrtValue ml_value_x; | ||||||||||
CreateMLValue<MLFloat16>(input_shape_x.GetDims(), input_x.data(), OrtMemoryInfo(), &ml_value_x); | ||||||||||
|
||||||||||
NameMLValMap feeds; | ||||||||||
feeds.insert(std::make_pair("model_input", ml_value_x)); | ||||||||||
|
||||||||||
std::function<void(const Graph&)> verify = [](const Graph& graph) -> void { | ||||||||||
ASSERT_EQ(graph.NumberOfNodes(), 3) << "Transpose nodes should have been removed, and " | ||||||||||
"Conv+Relu and Conv+Clip should have been fused, leaving 3 nodes."; | ||||||||||
auto node_iter = graph.Nodes().begin(); | ||||||||||
auto check_node = [](const Node& node, const std::string& fusion_type) { | ||||||||||
const auto& attr = node.GetAttributes(); | ||||||||||
auto activation = attr.find("activation"); | ||||||||||
ASSERT_NE(activation, attr.cend()) << "Fused node should have activation attribute"; | ||||||||||
ASSERT_EQ(activation->second.s(), fusion_type); | ||||||||||
}; | ||||||||||
|
||||||||||
// check 2nd and 3rd nodes. | ||||||||||
// the first node is the Conv that does not get fused (created after first call to GetCapability) | ||||||||||
// the 2nd and 3rd nodes are the fused nodes (created after second call to GetCapability) | ||||||||||
++node_iter; | ||||||||||
check_node(*node_iter, "Clip"); | ||||||||||
++node_iter; | ||||||||||
check_node(*node_iter, "Relu"); | ||||||||||
}; | ||||||||||
|
||||||||||
EPVerificationParams params; | ||||||||||
params.ep_node_assignment = ExpectedEPNodeAssignment::All; | ||||||||||
params.fp32_abs_err = 0.0002f; | ||||||||||
params.graph_verifier = &verify; | ||||||||||
|
||||||||||
auto ep = DefaultXnnpackExecutionProvider(); | ||||||||||
// So far, CPU EP doensn't support Fp16 Conv fusion, so verify_outputs is skipped. | ||||||||||
RunAndVerifyOutputsWithEP(ort_model_path, "TestNhwcConvReluClipFusion_FP16", std::move(ep), feeds, params, {}, false); | ||||||||||
Comment on lines
+134
to
+135
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. Not quite following. There should still be valid output from the CPU EP even if it doesn't fuse, so why can't we use verify_outputs?
Suggested change
|
||||||||||
} | ||||||||||
#endif | ||||||||||
|
||||||||||
// test we can share the cpu ep allocator with the xnnpack EP | ||||||||||
TEST(XnnpackEP, TestAllocatorSharing) { | ||||||||||
auto init_session = [](std::vector<std::shared_ptr<IExecutionProvider>>& eps, | ||||||||||
|
Binary file not shown.
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.
What if
GetType(arg, arg_type)
failed here?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.
Generally type info is always available, so I think this is ok. Shape info may be missing depending on the model.
The Conv op looks to be setup to allow fp32, u8, s8 and optionally fp16. Should this also handle u8 and s8 or should ClipReluChecker limit fusion to fp32 and fp16?