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

Feature request: allow user to pass gradient tape into sample() function #1419

Closed
krishvishal opened this issue Sep 28, 2020 · 2 comments
Closed

Comments

@krishvishal
Copy link

When sampling a Turing model using ReverseDiff and memoization in a distributed setting (MCMCDistributed()), the gradient tape is compiled n times if there are n worker processes.

We can avoid the extra compilations by allowing user to compile the tape once and passing it into the sample function.

@krishvishal krishvishal changed the title Feature request: allow user to pass gradient pass into sample() function Feature request: allow user to pass gradient tape into sample() function Sep 28, 2020
@devmotion
Copy link
Member

Note that you have to be careful to not share the tape though: #1412 (comment)

@devmotion
Copy link
Member

IMO it would be great to make the setup more modular and less "magic". I'm not sure though if one should be able to specify the tape as part of the sample calls. It seems it is only relevant for a very specific application, so maybe it should be bundled more clearly with the ReverseDiff AD choices. If AD settings would be more explicit (see #1402), maybe one could think about having an ReverseDiffAD singleton for ReverseDiff without caching and then allow users to cache the tape once by calling ReverseDiffCachedAD(model, sampler) that precomputes a tape for a specific model and sampler, which could then be passed around explicitly and be reused (although still not clear to me how exactly since as mentioned above you need a separate one for each cache).

Since this issue seems to (only?) affect the cutoff when distributed sampling pays off, it might be good to take the time and think about such design choices before implementing a workaround.

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

No branches or pull requests

3 participants