Skip to content
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

RFC-0034-batch-kronecker-product #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dannygoodacre
Copy link

No description provided.

@facebook-github-bot
Copy link
Contributor

Hi @dannygoodacre!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@dannygoodacre dannygoodacre marked this pull request as ready for review December 24, 2023 01:45
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Contributor

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Hi,

Thanks a lot for the detailed rfc!
I do think it makes sense to add this feature, I do have a couple inline comments.



## **Drawbacks**
This is not a breaking change.
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this new kwarg to torch.kron wouldn't be bc-breaking either but would make it diverge from numpy's kron.
cc @rgommers any plans on adding kron to the arrray API that we should follow here?



## **Proposed Implementation**
In the following, `a` and `b` are tensors of the specified sizes, and `batch_kron(a, b, batch_dim)` the proposed feature, where `batch_dim = 0` refers to the outermost dimension.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean by outermost here. But 0 should refer to the first dimension indeed.
Note that to match existing function, we can also consider doing the same as mm/bmm and only have the 0th dimension always be batch for a bkron op.

Copy link
Author

Choose a reason for hiding this comment

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

Keeping consistent with bmm makes sense. Then the only condition on the tensors would be that the first dimensions agree. Plus, batching in any other dimension is rather niche and potentially overkill to include.

```
a.shape = (2,5,4)
b.shape = (2,5,7)
batch_kron(a, b, 0).shape = (2,25,28)
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @zou3519 do you think that using vmap here would be the best way to expose this kind of feature rather than adding a new function? Can we implement a fast batched kron without having a native op for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants