-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement Einsum reference in nGraph interpreter #5923
Implement Einsum reference in nGraph interpreter #5923
Conversation
Please, add information about the binary size increase of the ngraph library because of this operation. |
Signed-off-by: Roman Kazantsev <[email protected]>
63e8ab8
to
52fc92e
Compare
Could you set the milestone for this activity? |
Done. |
Done |
fec8058
to
8247866
Compare
Signed-off-by: Roman Kazantsev <[email protected]>
8247866
to
da05c67
Compare
24bdb1f
to
421d6ee
Compare
Signed-off-by: Roman Kazantsev <[email protected]>
421d6ee
to
f11813e
Compare
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
ngraph/core/reference/include/ngraph/runtime/reference/einsum.hpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Roman Kazantsev <[email protected]>
ngraph/core/reference/include/ngraph/runtime/reference/matmul.hpp
Outdated
Show resolved
Hide resolved
…tion Signed-off-by: Roman Kazantsev <[email protected]>
Signed-off-by: Roman Kazantsev <[email protected]>
Signed-off-by: Roman Kazantsev <[email protected]>
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.
No major comments.
* Implement Einsum reference in nGraph interpreter Signed-off-by: Roman Kazantsev <[email protected]> * Apply code-style patch and fix build issues Signed-off-by: Roman Kazantsev <[email protected]> * Fix CI build Signed-off-by: Roman Kazantsev <[email protected]> * Fix fast build and apply code review feedback Signed-off-by: Roman Kazantsev <[email protected]> * Add visitor API tests, check for input type and reduce memory consumption Signed-off-by: Roman Kazantsev <[email protected]> * Apply code style Signed-off-by: Roman Kazantsev <[email protected]> * Add visitor API tests Signed-off-by: Roman Kazantsev <[email protected]>
* Implement Einsum reference in nGraph interpreter Signed-off-by: Roman Kazantsev <[email protected]> * Apply code-style patch and fix build issues Signed-off-by: Roman Kazantsev <[email protected]> * Fix CI build Signed-off-by: Roman Kazantsev <[email protected]> * Fix fast build and apply code review feedback Signed-off-by: Roman Kazantsev <[email protected]> * Add visitor API tests, check for input type and reduce memory consumption Signed-off-by: Roman Kazantsev <[email protected]> * Apply code style Signed-off-by: Roman Kazantsev <[email protected]> * Add visitor API tests Signed-off-by: Roman Kazantsev <[email protected]>
Description:
Ticket: 49327
Details: The main idea was inherited from EinsumDecomposition transformation implementation in PR5529 and extended to support diagonal extraction and ellipsis in an equation. To get the idea about support of equations without diagonal extraction and without ellipsis, please refer to PR5529 details where it describes the procedure to split labels into three groups (common, separated, reduced dimensions), permute them for grouping, apply MatMul operation, and reshape back the resulted tensor with transpose to get layout adjusted with output subscript.
Here it describes two cases: diagonal extraction and ellipsis.
EinsumDiagonal. For example, Einsum with
equation="abb->a"
will extract diagonals per batch (i.e. zero dimension):It makes sense to note that diagonal extraction must be performed in the first step for each operand in case repeated labels in the corresponding input subscripts. For example, diagonal must be extracted for the first operand of Einsum with
equation="abbac,bd->ad"
in the first step. Only after the first step you can proceed with handling ellipsis and details from PR5529.Let us perform diagonal extraction for the first operand with input subscript
abbac
and shape equal to[2, 3, 3, 2, 4]
.a
andb
are repeated labels and[0, 3]
and[1, 2]
are the corresponding dimension indices.a
label, it will beI1
of shape[2,1,1,2,1]
whereI1[k,*,*,k,*]=1
fork=0,1
and 0 - otherwise. Forb
label, it will beI2
of shape[1,3,3,1,1]
whereI2[k,*,*,k,*]=1
fork=0,1,2
and 0 - otherwise. Note that identity rank matches to the input rank and its dimension sizes equal dimension sizes corresponding to given label from input shape and equal to 1 for all other labels.I=I1*I2*...*In
wheren
is a number of repeated labels.I
and perform reduce-sum along dimensions from the corresponding dimension indices for repeated labels excluding the first dimension, i.e.[3]
fora
and[2]
forb
. Hence, the extracted diagonal will be of shape[2,3,4]
with subscriptabc
.Ellipsis. In case of ellipsis, the procedure described in PR5529 is extended with an ellipsis case. All steps from PR5529 are modified so that it takes into account that one ellipsis label can cover multiple dimension. Also, before MatMul operation you need to broadcast operands if they both have dimensions covered by ellipsis label.
Signed-off-by: Roman Kazantsev [email protected]