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

[DML EP] Contrib Op: FusedMatMul #12898

Merged
merged 11 commits into from Sep 9, 2022
Merged

Conversation

sumitsays
Copy link
Contributor

@sumitsays sumitsays commented Sep 8, 2022

Description:

  • Adds the Contrib operator kernel FusedMatMul to the DML EP.
  • Changes the name (prefix) of the operator fusions performed by DMLGraphTransformer to from Fused* to DmlFused*. It is needed to avoid the name overlapping between ORT Contrib operator FusedMatMul and DML fused operator FusedMatMul (now this is DmlFusedMatMul)
  • According to ORT contrib operator FusedMatMul shape inference, the sequence is:
    • Honor the attributes trans and transBatch by manipulating the input shapes and generating the appropriate strides.
      • trans: transpose the last 2 dimensions.
      • transBatch: shift the batch dimensions (all dimensions expect the last 2 dimensions) by 1 and move the 2nd-last dimension to the place of 1st dimension.
      • Between the transBatch and trans, apply transBatch first and then trans
    • Per the numpy MatMul behavior, broadcast the shapes of the input tensors and accordingly manipulate their strides (Note: At this point strides may have already been calculated, if attribute trans or transBatch is present, and those strides should not be overridden).
  • This kernel is a special one because it does not care about actual input shape (comes from the .onnx file) while creating the DmlOperator::TensorDesc because as mentioned above actual input shapes need to be manipulated to acknowledge the 2 types of transposes. That's why I added a new way to initialize a DMLOperator via DmlOperator::InitializeWithShape
  • winml_test_model.exe successfully passes, which verifies nothing breaks because Dml fused operator re-naming.

image

  • OnnxBackendTest also successfully passes:

image

Motivation and Context

  • Why is this change required? What problem does it solve?
    This contrib operator is used by transformer-based models.

Copy link
Contributor

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

Needs some robustness checks for span copies.

Copy link
Contributor

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

🎉

@sumitsays sumitsays merged commit 05c65a5 into WindowsAI Sep 9, 2022
@sumitsays sumitsays deleted the user/sumita/MatMulScale2 branch September 9, 2022 16:37
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.

None yet

2 participants