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

Update kernel matching logic: decouple from op schemas and remove kernel def hashes #12791

Merged
merged 134 commits into from
Sep 20, 2022

Conversation

edgchen1
Copy link
Contributor

@edgchen1 edgchen1 commented Aug 30, 2022

Motivation

Currently, ORT minimal builds use kernel def hashes to map from nodes to kernels to execute when loading the model. As the kernel def hashes must be known ahead of time, this works for statically registered kernels. This works well for the CPU EP.
For this approach to work, the kernel def hashes must also be known at ORT format model conversion time, which means the EP with statically registered kernels must also be enabled then. This is not an issue for the always-available CPU EP. However, we do not want to require that any EP which statically registers kernels is always available too.
Consequently, we explore another approach to match nodes to kernels that does not rely on kernel def hashes. An added benefit of this is the possibility of moving away from kernel def hashes completely, which would eliminate the maintenance burden of keeping the hashes stable.

Approach

In a full build, ORT uses some information from the ONNX op schema to match a node to a kernel. We want to avoid including the ONNX op schema in a minimal build to reduce binary size. Essentially, we will take the necessary information from the ONNX op schema and make it available in a minimal build.
We will decouple the ONNX op schema from the kernel matching logic. The kernel matching logic will instead rely on per-op information which can either be obtained from the ONNX op schema or another source.
This per-op information must be available in a minimal build when there are no ONNX op schemas. We can put it in the ORT format model.
Existing uses of kernel def hashes to look up kernels can be replaced with the updated kernel matching logic. We no longer need to store kernel def hashes in the ORT format model’s session state and runtime optimization representations. We no longer need to keep the logic to generate and ensure stability of kernel def hashes.

edgchen1 added 30 commits May 3, 2022 07:02
@edgchen1 edgchen1 requested a review from snnn September 15, 2022 22:01
@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2022

This pull request introduces 1 alert and fixes 1 when merging da5c9f4 into 739b567 - view on LGTM.com

new alerts:

  • 1 for Unused static function

fixed alerts:

  • 1 for Explicit returns mixed with implicit (fall through) returns

@fdwr fdwr requested a review from jeffbloo September 16, 2022 04:51
@lgtm-com
Copy link

lgtm-com bot commented Sep 16, 2022

This pull request introduces 6 alerts and fixes 1 when merging 716b756 into b935524 - view on LGTM.com

new alerts:

  • 5 for Uncontrolled data used in path expression
  • 1 for Unused static function

fixed alerts:

  • 1 for Explicit returns mixed with implicit (fall through) returns

@@ -593,7 +593,7 @@ static void CustomKernelWithCustomSchema() {
floatTensorEdgeDesc.edgeType = MLOperatorEdgeType::Tensor;
floatTensorEdgeDesc.tensorDataType = MLOperatorTensorDataType::Float;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fdwr @jeffbloo please take a look at these changes too

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 Looks like a custom op WinML test. @smk2007? Seems okay 🤷‍♂️ (T to T1 makes sense, given the definition above), but I'm content if the test passes.

@@ -790,8 +790,6 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 17, ST
// !!PLEASE READ BELOW!! Following that, add new entries above this comment

/* *** IMPORTANT! ***
If kernel registrations are incorrectly updated, ORT format models get broken as the kernel hashes may be invalidated.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skottmckay should this be replaced another comment? I think it's still important to correctly register kernels

Copy link
Contributor

Choose a reason for hiding this comment

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

How would they register it correctly if the kernel def builder no longer generates a hash?

Copy link
Member

@snnn snnn left a comment

Choose a reason for hiding this comment

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

The changes to yaml files LGTM. Sorry I didn't look into the other files.

@lgtm-com
Copy link

lgtm-com bot commented Sep 17, 2022

This pull request introduces 1 alert and fixes 1 when merging 396a957 into b48f71f - view on LGTM.com

new alerts:

  • 1 for Unused static function

fixed alerts:

  • 1 for Explicit returns mixed with implicit (fall through) returns

@edgchen1
Copy link
Contributor Author

/azp run orttraining-linux-gpu-ci-pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@edgchen1
Copy link
Contributor Author

/azp run Linux Eager Mode CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@edgchen1 edgchen1 merged commit 454f77c into main Sep 20, 2022
@edgchen1 edgchen1 deleted the edgchen1/static_kernel_update branch September 20, 2022 21:25
@jywu-msft jywu-msft mentioned this pull request Sep 21, 2022
linnealovespie pushed a commit that referenced this pull request Sep 30, 2022
…nel def hashes (#12791)

# Motivation
Currently, ORT minimal builds use kernel def hashes to map from nodes to
kernels to execute when loading the model. As the kernel def hashes must
be known ahead of time, this works for statically registered kernels.
This works well for the CPU EP.
For this approach to work, the kernel def hashes must also be known at
ORT format model conversion time, which means the EP with statically
registered kernels must also be enabled then. This is not an issue for
the always-available CPU EP. However, we do not want to require that any
EP which statically registers kernels is always available too.
Consequently, we explore another approach to match nodes to kernels that
does not rely on kernel def hashes. An added benefit of this is the
possibility of moving away from kernel def hashes completely, which
would eliminate the maintenance burden of keeping the hashes stable.

# Approach
In a full build, ORT uses some information from the ONNX op schema to
match a node to a kernel. We want to avoid including the ONNX op schema
in a minimal build to reduce binary size. Essentially, we take the
necessary information from the ONNX op schema and make it available in a
minimal build.
We decouple the ONNX op schema from the kernel matching logic. The
kernel matching logic instead relies on per-op information which can
either be obtained from the ONNX op schema or another source.
This per-op information must be available in a minimal build when there
are no ONNX op schemas. We put it in the ORT format model.
Existing uses of kernel def hashes to look up kernels are replaced
with the updated kernel matching logic. We no longer store
kernel def hashes in the ORT format model’s session state and runtime
optimization representations. We no longer keep the logic to
generate and ensure stability of kernel def hashes.
siweic0 pushed a commit to siweic0/onnxruntime-web that referenced this pull request May 9, 2024
…nel def hashes (microsoft#12791)

# Motivation
Currently, ORT minimal builds use kernel def hashes to map from nodes to
kernels to execute when loading the model. As the kernel def hashes must
be known ahead of time, this works for statically registered kernels.
This works well for the CPU EP.
For this approach to work, the kernel def hashes must also be known at
ORT format model conversion time, which means the EP with statically
registered kernels must also be enabled then. This is not an issue for
the always-available CPU EP. However, we do not want to require that any
EP which statically registers kernels is always available too.
Consequently, we explore another approach to match nodes to kernels that
does not rely on kernel def hashes. An added benefit of this is the
possibility of moving away from kernel def hashes completely, which
would eliminate the maintenance burden of keeping the hashes stable.

# Approach
In a full build, ORT uses some information from the ONNX op schema to
match a node to a kernel. We want to avoid including the ONNX op schema
in a minimal build to reduce binary size. Essentially, we take the
necessary information from the ONNX op schema and make it available in a
minimal build.
We decouple the ONNX op schema from the kernel matching logic. The
kernel matching logic instead relies on per-op information which can
either be obtained from the ONNX op schema or another source.
This per-op information must be available in a minimal build when there
are no ONNX op schemas. We put it in the ORT format model.
Existing uses of kernel def hashes to look up kernels are replaced
with the updated kernel matching logic. We no longer store
kernel def hashes in the ORT format model’s session state and runtime
optimization representations. We no longer keep the logic to
generate and ensure stability of kernel def hashes.
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.

8 participants