Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Conversation

cswiercz
Copy link
Contributor

@cswiercz cswiercz commented Sep 6, 2017

Create an operator for the Khatri-Rao function implemented in #6567. The operator accepts a variable number of input matrix arguments as well as a flag indicating whether the Khatri-Rao product should be computed row-wise or column-wise. This option is provided because the row-wise operation is more memory efficient.

A Note to Reviewers

This is my first time putting MXNet code up for review so please tear this code apart. I need to learn.

Additionally, I've knowingly omitted the Backwards/Gradient calculation.

@cswiercz
Copy link
Contributor Author

cswiercz commented Sep 6, 2017

Pinging @jli05 and @JeanKossaifi

@JeanKossaifi
Copy link
Contributor

@cswiercz that's a great addition and will be very useful! Was meaning to do it but didn't have time..

I am not sure about the row_wise flag. The khatri-rao is a column-wise kronecker product, and the row-wise would also refer to the kronecker product, not khatri-rao.. Would it be clearer to have khatri_rao and maybe row_wise_kronecker (long name but unambiguous?)

@cswiercz
Copy link
Contributor Author

cswiercz commented Sep 11, 2017

I am not sure about the row_wise flag. The khatri-rao is a column-wise kronecker product, and the row-wise would also refer to the kronecker product, not khatri-rao.. Would it be clearer to have khatri_rao and maybe row_wise_kronecker (long name but unambiguous?)

Yeah, I wasn't so sure about the flag. Having a separate operator sounds like a better idea. Plus it would clean up the code a bit. For consistency maybe:

  • khatri_rao()
  • column_wise_kronecker() (alias to khatri_rao)
  • row_wise_kronecker()

Thoughts from anyone who is interested?

@jli05
Copy link
Contributor

jli05 commented Sep 11, 2017

I'm for exposing only column-wise Khatri-Rao for the Python Op, but only reserving the row-wise one for framework developers (C++).

@cswiercz
Copy link
Contributor Author

I'm for exposing only column-wise Khatri-Rao for the Python Op, but only reserving the row-wise one for framework developers (C++).

Fair enough. It would certainly simplify the code considerably. I made the appropriate changes.

@cswiercz
Copy link
Contributor Author

@mli @piiswrong - Two MXNet contributors who know this function have approved this PR. Is there anything I'm missing?

@cswiercz
Copy link
Contributor Author

cswiercz commented Oct 9, 2017

@mli @piiswrong - If it makes any difference, this code is going into src/operator/contrib.

Copy link
Contributor

@piiswrong piiswrong left a comment

Choose a reason for hiding this comment

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

Sorry for missing this. Please ping me with email if PR gets ignored for too long next time.

@@ -111,7 +111,11 @@ inline char loup(char uplo, bool invert) { return invert ? (uplo == 'U' ? 'L' :
* \param lda leading dimension of a
*/
template <typename xpu, typename DType>
inline void flip(int m, int n, DType *b, int ldb, DType *a, int lda);
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the previous definition for flip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only the DType=float and DType=double versions were implemented in the subsequent lines. I the function prototype in this line with a generalized version templated on the DType.

This change was necessary due to the use of MSHADOW_TYPE_SWITCH, I believe. Without this templating I was observing compile errors when testing with non float and double types.

I think the float and double-specific versions can be removed, actually...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes they don't make much sense.

Please remove them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. See 66afdc3 below.

@cswiercz
Copy link
Contributor Author

cswiercz commented Oct 9, 2017

Sorry for missing this. Please ping me with email if PR gets ignored for too long next time.

No worries. I know you're busy with more pressing, non-contrib things.

@piiswrong
Copy link
Contributor

@cswiercz Could you rebase to current master?

Chris Swierczewski added 3 commits December 12, 2017 14:37
Create an operator for the Khatri-Rao function implemented in apache#6567. The
operator accepts a variable number of input matrix arguments as well as a flag
indicating whether the Khatri-Rao product should be computed row-wise or
column-wise. This option is provided because the row-wise operation is more
memory efficient.
Remove row-wise flag from parameter/keyword set. That is, only compute the
column-wise Khatri-Rao product.
Remove unnecessary type-specific `flip` code. The fully-templatized version
handles the `float` and `double` instances.
@cswiercz
Copy link
Contributor Author

@piiswrong Rebased. All tests pass.

@piiswrong piiswrong merged commit c4a76da into apache:master Dec 14, 2017
@cswiercz cswiercz mentioned this pull request Dec 15, 2017
5 tasks
DMLC_REGISTER_PARAMETER(KhatriRaoParam);


NNVM_REGISTER_OP(khatri_rao)
Copy link
Member

Choose a reason for hiding this comment

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

This op is supposed to be registered under contrib namespace.

rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* Implement Khatri-Rao operator

Create an operator for the Khatri-Rao function implemented in apache#6567. The
operator accepts a variable number of input matrix arguments as well as a flag
indicating whether the Khatri-Rao product should be computed row-wise or
column-wise. This option is provided because the row-wise operation is more
memory efficient.

* Implement Khatri-Rao operator

Remove row-wise flag from parameter/keyword set. That is, only compute the
column-wise Khatri-Rao product.

* Implement Khatri-Rao operator

Remove unnecessary type-specific `flip` code. The fully-templatized version
handles the `float` and `double` instances.
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* Implement Khatri-Rao operator

Create an operator for the Khatri-Rao function implemented in apache#6567. The
operator accepts a variable number of input matrix arguments as well as a flag
indicating whether the Khatri-Rao product should be computed row-wise or
column-wise. This option is provided because the row-wise operation is more
memory efficient.

* Implement Khatri-Rao operator

Remove row-wise flag from parameter/keyword set. That is, only compute the
column-wise Khatri-Rao product.

* Implement Khatri-Rao operator

Remove unnecessary type-specific `flip` code. The fully-templatized version
handles the `float` and `double` instances.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants