-
Notifications
You must be signed in to change notification settings - Fork 68
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
Implement backend='auto' and make it the default #81
Conversation
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.
I like the idea of this, but worried that this could potentially break code. We seem to be in quite a few projects at the moment and could change behavior.
@fritzo Thoughts here?
|
||
# some arrays will be defined in modules that don't implement tensordot | ||
# etc. so instead default to numpy | ||
if not backends.has_tensordot(backend): |
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.
What if someone has subclassed a NumPy array or similar or uses an unknown backend? We should fall back to NumPy here as well.
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.
So I think the behavior you describe is what happens here. For example, in my library quimb
I have a subclass of ndarray
so the initial inferred backend is quimb
. However this check for quimb.tensordot
(which is cached) means 'numpy'
is used still since unlike dask, tensorflow etc. quimb
does not provide tensordot.
Yeah I definitely appreciate this might be a significant change and would be good to get anybody's feedback! I think for almost all use cases there should be no change in behaviour however. The only really 'breaking' edge case I can think of, is if someone is using non-numpy arrays from a library that does provide |
IIUC this would not break any Pyro code since we always specify backend, and actually we usually specify a custom backend like |
Yes no change for explicit The overall logic is really that if you supply a |
I think this represents a fundamental shift where we are no longer focused on a NumPy backend, but are agnostic. I would consider this a major change (3.x) as we change our philosophy statement (something that could be argued that we have done anyways). This would make me a bit more comfortable as we are potentially breaking code, thoughts? |
Yes that seems like a reasonable approach to me! |
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.
LGTM
Description
This implements
backend='auto'
for contractions and makes it the default. This works currently by inferring the module from the class of the first array supplied. A slight detail is that sometimes the module of an array does not supplytensordot
etc. (maybe it has subclassed justnumpy.ndarray
for example) and in this case'numpy'
is still used.Hopefully this kind of thing will eventually be made redundant by
__array_function__
(#46) but for the moment it makes it a bit more convenient to work with other array libraries.Status