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

Allow overriding of transpose function #74

Merged
merged 1 commit into from
Nov 23, 2018

Conversation

fritzo
Copy link
Contributor

@fritzo fritzo commented Nov 21, 2018

Description

This PR makes backends fully overridable by checking each backed for a transpose function before using the default .transpose() method.

Before this PR, _transpose() would first look for a default implementation (x.transpose(axes)), and only if this failed look for an overridden backend transpose() function. This approach has two flaws: (1) backends cannot override the transpose function if a different .transpose() method already exists (e.g. in Pyro we want to track some metadata in transpose()); (2) the try-except may not play well with jit compilers like the PyTorch jit.

The only change in behavior is to the torch backend: before this PR torch.transpose() was used for transposes of 2 axes and torch.permute() was used for 3 or more axes; after this PR torch.permute() is always used.

Status

  • Ready to go

@codecov-io
Copy link

Codecov Report

Merging #74 into master will decrease coverage by <.01%.
The diff coverage is 100%.

@jcmgray
Copy link
Collaborator

jcmgray commented Nov 21, 2018

Yes I think this definitely makes sense. Some libraries (e.g. hptt), implement transpose directly for numpy arrays, which you would want to take precedence.

@jcmgray
Copy link
Collaborator

jcmgray commented Nov 22, 2018

I'll merge this shall I, unless you have comments @dgasmith?

Copy link
Owner

@dgasmith dgasmith left a comment

Choose a reason for hiding this comment

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

LGTM!

As per @jcmgray's comment. It would superb to get TBLIS and/or HPTT on conda-forge to try this out. Does HPTT compile to a single vectorized instruction or can it compile to multiple simultaneously like ICC multi arch or a more home grown solution as found in TBLIS?

@dgasmith
Copy link
Owner

@jcmgray Feel free to merge PR's if you wish with the usual caveat of something major should be discussed first.

@dgasmith dgasmith merged commit 9d395da into dgasmith:master Nov 23, 2018
@jcmgray
Copy link
Collaborator

jcmgray commented Nov 24, 2018

As per @jcmgray's comment. It would superb to get TBLIS and/or HPTT on conda-forge to try this out. Does HPTT compile to a single vectorized instruction or can it compile to multiple simultaneously like ICC multi arch or a more home grown solution as found in TBLIS?

I'm actually not sure at all, I did add a numpy like transpose wrapper to hptt but don't know any details beyond that. Although it seems to have very good performance, the real critical transpose is the one inside numpy.tensordot it seems. On the other hand definitely agree that TBLIS would be super neat to get properly set-up.

@jcmgray Feel free to merge PR's if you wish with the usual caveat of something major should be discussed first.

Great, noted.

@fritzo
Copy link
Contributor Author

fritzo commented Nov 24, 2018

@dgasmith would it be possible to cut a release with this PR and the new eager optimizer? I'd like to use both features in our upcoming Pyro release.

@dgasmith
Copy link
Owner

@fritzo Sure, no reason not to cut a minor release soon. Do you have a timeline that you are thinking of, might look at pulling in #73 from @jcmgray as well before the release.

@fritzo
Copy link
Contributor Author

fritzo commented Nov 25, 2018

@dgasmith Our Pyro release is planned for the week of Dec 3. Let me know if there is any additional documentation you'd like before the next opt_einsum release. Thanks!

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.

4 participants