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
fix conjugate-transpose for matrices of certain sizes (issue #19200) #46736
fix conjugate-transpose for matrices of certain sizes (issue #19200) #46736
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@OmriSteiner Can you please sign CLA. Thanks! |
@gbaned My employer signed the CLA and added me as an authorized contributor, but apparently it takes several days for approval? |
@googlebot I signed it! |
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.
Can you add a unit test? Probably this file: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/kernel_tests/array_ops_test.py
@@ -890,7 +899,7 @@ struct TransposeElemType<4> { | |||
}; | |||
template <> | |||
struct TransposeElemType<8> { | |||
using type = uint64; | |||
using type = float2; |
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.
Is this necessary for correctness? Would we run into similar issues with complex<float16> and TransposeElemType<4>?
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.
Yes, this is necessary. Instead of simply conjugating, we call maybe_conj
, which is specialized for complex types in GPU (float2 and double2).
I thought about TransposeElemType<4>
when fixing this, and came to the conclusion that tensorflow doesn't have a complex type which uses float16. std::complex<float16>
doesn't exist, as far as I can tell.
To be honest, I'm not entirely sure why TransposeElemType
is there in the first place. If I had to make a guess, I would say that it's in order to make this code work for non-basic types (i.e not tensorflow builtin numeric types). However, this is only used in a very specific place, so it would fail to achieve that.
Thanks for the comment, I found out I didn't fix the issue for complex128, but it's sorted now.
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.
Oh, right, we just have DT_COMPLEX64 and DT_COMPLEX128. Sounds OK then. If you want to get rid of TransposeElemType that's fine too (we might find a failing test).
I do think it's another good reason to have a unit test. If someone comes along and adds a smaller complex type it'd make it at least possible to find and fix this issue.
Yeah, I could write a unit-test for this. |
@allenlavoie I've expanded the test to also test complex128. |
When using
tf.linalg.matrix_transpose
ortf.linalg.adjoint
to conjugate-transpose a complex tensor, the functions might fail to conjugate the tensor under certain circumstances.Given a complex matrix with m rows and n columns, if the following conditions are met:
Then the matrix will not be conjugated (although it will be transposed).
Code snippet which reproduces the bug (before patch):