Skip to content
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

Enable transpose optimizer in minimal extended build #10349

Merged
merged 22 commits into from
Jan 31, 2022

Conversation

edgchen1
Copy link
Contributor

Description
Enable transpose optimizer and infrastructure it depends on in a minimal extended build.

Motivation and Context
Enable the transpose optimizer to run as part of runtime optimization of ORT format models.

if (node.ContainsSubgraph()) {
const auto subgraphs = node.GetSubgraphs();
for (const auto& subgraph : subgraphs) {
const auto status = VerifyEachNodeIsAssignedToAnEpImpl(*subgraph, is_verbose, node_placements);
Copy link
Contributor

@guoyu-wang guoyu-wang Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, ORT_RETURN_IF_ERROR #Resolved


/** Returns the attribute of a Node with a given name. */
const ONNX_NAMESPACE::AttributeProto* GetNodeAttribute(const Node& node, const std::string& attr_name);

Copy link
Contributor

@guoyu-wang guoyu-wang Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, can be moved below with AddInitializer to reduce number of #ifdef? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is unfortunately used by the template GetRepeatedNodeAttributeValues(), which is above the other ifdef

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the other 2 functions up here in the same #ifdef?

@edgchen1 edgchen1 changed the title [WIP] Enable transpose optimizer in minimal extended build Enable transpose optimizer in minimal extended build Jan 24, 2022
@edgchen1 edgchen1 marked this pull request as ready for review January 24, 2022 17:42
"${ONNX_SOURCE_ROOT}/onnx/defs/data_type_utils.h"
"${ONNX_SOURCE_ROOT}/onnx/defs/data_type_utils.cc"
"${ONNX_SOURCE_ROOT}/onnx/defs/shape_inference.h"
"${ONNX_SOURCE_ROOT}/onnx/defs/shape_inference.cc"
)
Copy link
Contributor

@skottmckay skottmckay Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the shape inference code?

I would have expected this causes a large hit to binary size but maybe most of it can be thrown away. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graph.cc:MergeShapeInfo():

static Status MergeShapeInfo(const std::string& output_name,

NodeArg::UpdateTypeAndShape()
api_impl.cc:ApiGraph::CopyValueInfo()
ORT_THROW_IF_ERROR(dst_arg.UpdateTypeAndShape(*src_arg, /*strict*/ false, /*override_types*/ false, logger_));

the reason is ApiGraph::CopyValueInfo()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the dependency on shape inference code

@skottmckay
Copy link
Contributor

skottmckay commented Jan 25, 2022

Does this need to be enabled? I think in training they have scenarios when the type gets overridden, but for our usages I wouldn't expect that to ever happen.


In reply to: 1020851523


In reply to: 1020851523 #Closed


Refers to: include/onnxruntime/core/graph/node_arg.h:86 in 16c7768. [](commit_id = 16c7768, deletion_comment = False)

@skottmckay
Copy link
Contributor

Actually taking a step up, do we need to use UpdateTypeAndShape?

I could only see a call to that in ApiGraph::CopyValueInfo, and given that's a straight copy we shouldn't need any of the merge/override logic. Not sure what isn't populated by the call to GetOrCreateNodeArg with the source NodeArg - if that include type and shape we don't need a call to UpdateTypeAndShape at all.


In reply to: 1020851523


Refers to: include/onnxruntime/core/graph/node_arg.h:86 in 16c7768. [](commit_id = 16c7768, deletion_comment = False)


for (const auto& node : Nodes()) {
node.ForEachDef([&](const NodeArg& node_arg, bool is_input) {
if (is_input) {
Copy link
Contributor

@skottmckay skottmckay Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! way simpler than the old code :) #Closed

@edgchen1
Copy link
Contributor Author

yeah, modifying ApiGraph::CopyValueInfo might be better


In reply to: 1020858991


Refers to: include/onnxruntime/core/graph/node_arg.h:86 in 16c7768. [](commit_id = 16c7768, deletion_comment = False)

NodeArg& dst_arg = graph_.GetOrCreateNodeArg(std::string(dst_name), nullptr);

if (auto* dst_type = dst_arg.TypeAsProto(); dst_type != nullptr) {
int32_t src_data_element_type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller guarantees this so you don't have to do the check if you don't want to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good to know. Will leave the check to make debugging easier.

/// in the ValueInfo class (like symbolic shape information). Destination dtype must be compatible with source dtype
/// if known.
/// in the ValueInfo class (like symbolic shape information). If already set, the destination dtype should be equal
/// to the source dtype.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, and if the caller fails to do this, the behavior is undefined.

NodeArg& dst_arg = graph_.GetOrCreateNodeArg(std::string(dst_name), nullptr);

if (auto* dst_type = dst_arg.TypeAsProto(); dst_type != nullptr) {
int32_t src_data_element_type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the dst_type init have to be in the 'if'? just wondering what the benefit of that is given it slightly complicates reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the benefit in my opinion is that the scope of dst_type can be more limited

Copy link
Contributor

@skottmckay skottmckay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

Copy link
Contributor

@skottmckay skottmckay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@edgchen1 edgchen1 merged commit c43c169 into master Jan 31, 2022
@edgchen1 edgchen1 deleted the edgchen1/transpose_optimizer_minimal_build branch January 31, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants