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

add a way to print or save summaries within an @jit function #364

Closed
mattjj opened this issue Feb 13, 2019 · 6 comments
Closed

add a way to print or save summaries within an @jit function #364

mattjj opened this issue Feb 13, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@mattjj
Copy link
Collaborator

mattjj commented Feb 13, 2019

c.f. #196 and this comment in particular, maybe we could add something like this:

y, python_io = jax.py_call(some_py_fun, x, python_io)
@mattjj mattjj added the enhancement New feature or request label Feb 13, 2019
@mattjj mattjj self-assigned this Feb 13, 2019
@jonasrauber
Copy link
Contributor

jonasrauber commented Feb 13, 2019

Sounds great. If I understand it correctly, wouldn’t a nojit decorator also make sense? E.g. something like nojit = lambda f: partial(py_call, f) (ignoring python_io for the moment; can you explain its purpose?)

I guess the called function‘s output needs to have fixed dtype and shape and they will be auto-detected during jit and an error will be thrown if they change?

@mattjj
Copy link
Collaborator Author

mattjj commented Feb 18, 2019

Interesting idea for a nojit decorator! We'll definitely have to keep that idea in mind, and see if we can implement it.

The purpose of python_io there is to model the state of the world (and in particular the stateful Python interpreter) and thread it through our computation, or at least through the parts that have side effects. That lets us model side-effects in a functionally pure way, since we can give semantics to these programs in terms of producing a new state of the world rather than modifying the old one (and the fact that we don't actually copy the whole world every time, and instead rely on side-effects, is an optimization in the implementation). The use of python_io would have some special limitations though, like linearity in the sense of linear logic (e.g. one python_io value can't be passed into two different py_call calls, and instead must be linearly threaded through the computation) because we really can't copy the world.

Another way to think about it would be like we're passing around the GIL (without acquiring it), and that py_call needs to acquire the GIL when it's called and release it when it returns.

That's basically how functional languages like Haskell model effectful operations like IO (also worth looking at the writer monad and the state monad), though there's a lot of variation and detail.

@mattjj
Copy link
Collaborator Author

mattjj commented Apr 23, 2020

cc @gnecula thinking about recent things recently. (Just noticed this because of issue 2796.)

@gnecula
Copy link
Collaborator

gnecula commented May 12, 2020

We now have a new experimental feature (experimental/host_callback.py:id_tap) that should work to save summaries from compiled code.

@gnecula
Copy link
Collaborator

gnecula commented May 12, 2020

I believe that #3006 addresses this.

@gnecula gnecula closed this as completed May 12, 2020
@jonasrauber
Copy link
Contributor

Nice work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants