Skip to content

Conversation

@vinx13
Copy link
Member

@vinx13 vinx13 commented Sep 27, 2022

The current Einsum doesn't utilize ReduceOp for reduction. It instead unrolls the whole reduction when defining the computation. It makes the generated result not suitable for analysis as it doesn't contain reduction information. It's also broken for large reductions. This PR provided a new implementation that generates the reduction axes correctly.
Graph level optimizations might be needed for efficient Einsum. This PR only provides compute definition for further analysis and optimizations.

cc @spectrometerHBH @MasterJH5574 @junrushao @masahi

// Neglecting oshape assign check temporally
return oshape;
}
Array<PrimExpr> NumpyEinsumShape(const std::string subscripts,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: what does the “Numpy” prefix stand for?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is the name used previously, indeed there's no reason using numpy prefix, we can probably find a better name

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. The function is just doing pure shape inference... Just some random thought, what about “InferEinsumShape”?

Comment on lines -176 to -179
TVM_REGISTER_GLOBAL("topi.einsum").set_body([](TVMArgs args, TVMRetValue* rv) {
*rv = einsum(args[0], args[1]);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this no longer used?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's moved to einsum.cc file

Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

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

Thanks @vinx13 for the fix!!

@vinx13 vinx13 merged commit 178f82d into apache:main Sep 27, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [TOPI] Implement Einsum with reduction axes

* address comments
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.

2 participants