-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
a8317b7
to
be196c2
Compare
I think you may call the BatchedGEMMStrided Kernel directly: https://devblogs.nvidia.com/cublas-strided-batched-matrix-multiply/
Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: JiangZhaoh <notifications@github.com>
Sent: Sunday, December 8, 2019 6:04:32 PM
To: apache/incubator-mxnet <incubator-mxnet@noreply.github.com>
Cc: Xingjian SHI <xshiab@connect.ust.hk>; Comment <comment@noreply.github.com>
Subject: Re: [apache/incubator-mxnet] [numpy] add op matmul (#16990)
@JiangZhaoh commented on this pull request.
________________________________
In src/operator/numpy/np_matmul_op-inl.h<#16990 (comment)>:
+ It is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
+ * \param out - output: insert 'value' to 'arr' according to 'index'.
+ * \param a - input: the first argument.
+ * \param b - input: the second argument.
+ * \param ndim - ndim of a, b and output. Because of broadcast, regard their ndim as equal.
+ */
+ template<typename DType>
+ MSHADOW_XINLINE static void Map(int i, DType* out,
+ const DType* a, const DType* b,
+ const mshadow::Shape<10> a_stride,
+ const mshadow::Shape<10> b_stride,
+ const mshadow::Shape<10> out_stride,
+ const mshadow::Shape<10> a_shape,
+ const mshadow::Shape<10> b_shape,
+ const mshadow::Shape<10> out_shape,
+ const size_t ndim){
You may refer to the implementation of batch_dot. There is no need to store the strides and shapes as Shape<10>. You can reshape the array to a 3D array and just dot the last two dimensions:
https://github.com/apache/incubator-mxnet/blob/1aa1b5a9ab53bb57a3c653793fb824d01f2d5e81/src/operator/tensor/dot-inl.h#L1348-L1409
Thanks for your advice. But, may I ask how could I broadcast the shape if I don't store strides and shapes?
e.g. Matrix A in shape (2, 1, 3, 4, 5) and matrix B in shape (3, 1, 5, 2), C=np.matmul(A, B) would broadcast A and B to shape (2, 3, 3, 4, 5) and (3, 3, 5, 2) respectively, and C's shape would be (2, 3, 3, 4, 2).
If I didn't store shape and stride, I think I should copy the content in each array to get the consistent shape firstly, and use your method then. Is this your mean?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#16990>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABHQH3R4ZQCQQAG34ABFOA3QXWRTBANCNFSM4JWMPQEA>.
|
May I confirm your mean again? |
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.
After offline discussion with @haojin2 , we think that we could add transpose flags (like in batch_dot) to matmul and make it an internal operator. So we can implement the backward pass of matmul by constructing new matmul nodes.
be196c2
to
7088599
Compare
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.
Please fix the sanity problems, and address open comments
7088599
to
7900894
Compare
e2e90f4
to
b4bf7b4
Compare
b4bf7b4
to
7df0e89
Compare
df65e77
to
66e932e
Compare
fix interoperability error and some unimportant details remove needless addition
resolve comment
66e932e
to
aba8816
Compare
* add op matmul - for interoperability error fix interoperability error and some unimportant details remove needless addition * fix website error * use BatchedGEMM * check req type / sanity / logic etc. * resolve identation mistakes * fix doc mistakes resolve comment
* add op matmul - for interoperability error fix interoperability error and some unimportant details remove needless addition * fix website error * use BatchedGEMM * check req type / sanity / logic etc. * resolve identation mistakes * fix doc mistakes resolve comment
Description
unary op: matmul
Because matmul has a special signature (i.e. (n?,k),(k,m?)->(n?,m?)) in official numpy, I comment out the following code segment in python/mxnet/numpy/multiarray.py :
if ufunc.signature is not None:
# we don't support generalised-ufuncs (gufuncs)
return NotImplemented
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments