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 for passing of backend and gradient_backend to nutpie #7535

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

fonnesbeck
Copy link
Member

@fonnesbeck fonnesbeck commented Oct 11, 2024

Description

There is no means for passing backend and gradient_backend to compile_pymc_model from sample, so that JAX can be used as a backend. This just looks for these arguments in nuts_sampler_kwargs and passes them if they exist.

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7535.org.readthedocs.build/en/7535/

@ricardoV94
Copy link
Member

Minimal implementation of #7498

compiled_model = nutpie.compile_pymc_model(model)
compiled_model = nutpie.compile_pymc_model(
model,
backend=nuts_sampler_kwargs.pop("backend", None),
Copy link
Member

Choose a reason for hiding this comment

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

Depending on the outcome of pymc-devs/nutpie#151 it may be:

Suggested change
backend=nuts_sampler_kwargs.pop("backend", None),
backend=nuts_sampler_kwargs.pop("backend", "numba"),

Copy link
Member Author

Choose a reason for hiding this comment

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

As it happens, I submitted a nitpick PR to fix this. It should be None because None is handled in the function.

Copy link
Member

@ricardoV94 ricardoV94 Oct 11, 2024

Choose a reason for hiding this comment

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

Otherwise you can do something like:

compile_kwargs = {}
for kwarg in ("backend", "gradient_backend"):
  if kwarg in nuts_sampler_kwargs:
    compile_kwargs[kwarg] = nuts_sampler_kwargs.pop(kwarg)
compile_pymc_model(..., **compile_kwargs)

This way you don't have to guess the default of nutpie nor change anything there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do. The arg default still needs to be changed in nutpie one way or the other, as I discuss there.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.85%. Comparing base (c61e9cd) to head (b6de148).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pymc/sampling/mcmc.py 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7535      +/-   ##
==========================================
- Coverage   92.88%   92.85%   -0.03%     
==========================================
  Files         105      105              
  Lines       17587    17591       +4     
==========================================
  Hits        16335    16335              
- Misses       1252     1256       +4     
Files with missing lines Coverage Δ
pymc/sampling/mcmc.py 87.23% <0.00%> (-0.74%) ⬇️

@fonnesbeck fonnesbeck merged commit 5352798 into pymc-devs:main Oct 11, 2024
21 of 22 checks passed
@fonnesbeck fonnesbeck deleted the nutpie_sampler_args branch October 11, 2024 19:05
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.

2 participants