Comments (6)
Hi @jonas-eschle, thanks for the issue! Firstly note you can do:
from autoray import numpy as np
x = np.random.uniform(size=(2, 3, 4), like='numpy')
y = np.cos(x)
With regards to the do
command, the reasoning is just the following:
- It makes the abstraction explicit
- Since
do
performs a cached look-up offn
this approach means the set of supported functions is everything any library provides andautoray
doesn't have to list them in a specific API. The fakenumpy
object above overrides__getattr__
to get around this.
For example
x = do('random.normal', size=(10), like='numpy')
do('fft.ifftshift', x)
# array([-1.03934721, 0.20498712, 2.19194394, 0.3072858 , -1.27799811,
# -1.41765394, -0.33233833, -0.24674171, 1.20681194, 0.86175232])
works even though we haven't listed anywhere all the fft routines numpy has.
That being said however I wouldn't be against having explicit functions listed like
tensordot = functools.partial(do, fn='tensordot')
...
if people thought that was a improvement over the two above methods.
from autoray.
I see, I was indeed not aware of the numpy interface, thanks for pointing me to it! I simply overlooked it
What about the gradients? I have not seen anything mentioned here? Or control-flow in general, cond
, while_loop
etc?
And is there a possibility to set the backend global (I didn't see this either, just in a context manager)?
from autoray.
Gradient-wise, autoray
functions very work with autograd
, tensorflow
, pytorch
, jax
and probably others, the interface is just not abstracted out yet to a autoray.grad
function or something, maybe that would be nice! quimb
(which is mainly what this project is used for) does have a general interface to these (e.g. the torch one https://github.com/jcmgray/quimb/blob/01350dbdaf0879c989923455be8195fcc56e12a6/quimb/tensor/optimize.py#L471-L522) that could be maybe be upstreamed at some point.
There's not any support for non-python control-flow since this is not something I have ever used. I suppose it's only necessary for dynamic computations where one is also compiling or taking the gradient? One could just translate them directly to python for numpy
, cupy
and torch
etc but would need to be careful about tracing through these making them accidentally static in certain situations where they would be dynamic for tensorflow
/ jax
.
Adding functions to set the backend permanently could easily be added - but are currently not there.
from autoray.
I've added ar.set_backend
and ar.get_backend
.
from autoray.
I've added
ar.set_backend
andar.get_backend
.
Ah good, many thanks!
Gradient-wise, autoray functions very work with autograd, tensorflow, pytorch, jax and probably others, the interface is just not abstracted out yet to a autoray.grad function or something, maybe that would be nice!
Indeed, that would be helpful, but it's not urgent, as we also have abstracted this away currently.
There's not any support for non-python control-flow since this is not something I have ever used.
Indeed, this is for any compiled computation where you want to have a while loop or vectorize or execute a function conditionally only. But it's a new level, and easier to wrap as there are only a few functions.
So in general the library looks quite interesting. Is there any overview which numpy functions are actually supported?
Also, just looked again at the README: I would very strongly encourage to advertise the numpy API! Having a numpy API with switchable backend that works well is a treasure! But the do(...)
is really not something anyone would want to use. I can't think of a single use-case where the do(....)
syntax would be preferred (except some stuff that is not yet there, as a dynamic extension it is good). I guess you can advertise the library way better with this
from autoray.
Is there any overview which numpy functions are actually supported?
It really is any backend function that can be imported, so the entirety of numpy
for numpy
arrays. With a few caveats:
- Some functions don't always dispatch on the first argument - e.g.
stack
andeinsum
, these need to have custom dispatchers so thatautoray
knows which arg to automatically infer the backend from. - For other libraries, if the library doesn't have the
numpy
equivalent then its ofc not supported for that backend. - For other libraries, if the library syntax doesn't match
numpy
, (e.g. to an extent tensorflow and torch, to much less of an extentcupy
anddask
etc.), a specific translator needs to be in place. See for example thetorch
section ofautoray.py
.
The idea is that it should find the correct function automatically most of the time, and then we just cover the remaining cases with explicit 'translations' which are very quick to add when they are needed.
I would very strongly encourage to advertise the numpy API!
It is in the readme, just a little down the page. It used to be more prominent and maybe should be made so again...
from autoray.
Related Issues (8)
- autoray transpose attribute-like function fails for torch tensors HOT 3
- numpy 1.24 deprecations fail quimb HOT 3
- How can I get this function from LazyArray HOT 6
- The shape of LazyArray HOT 7
- correctly infer backend for functions like concatenate HOT 3
- Translations and ideas for extensions HOT 4
- Random numbers and dtypes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autoray.