Skip to content

Speedup Slice sampler #6711

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

Merged
merged 2 commits into from
May 8, 2023
Merged

Speedup Slice sampler #6711

merged 2 commits into from
May 8, 2023

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented May 8, 2023

Inherits from StepArrayShared to avoid the many mappings between raveled and non-raveled arrays, which greatly slowdown the sampler. This simple model samples 3 times as fast in my machine after the changes:

import arviz as az
import pymc as pm

with pm.Model() as m:
    x = pm.Normal("x", shape=(200,))
    idata = pm.sample(step=pm.Slice([x]), random_seed=1)
    
az.summary(idata)

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

ricardoV94 added 2 commits May 8, 2023 14:03
This avoids a crash when mixing slice sampling with another sampler that has `tune` stats
@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Merging #6711 (eb4becf) into main (a617bf2) will decrease coverage by 31.76%.
The diff coverage is 19.04%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #6711       +/-   ##
===========================================
- Coverage   89.57%   57.81%   -31.76%     
===========================================
  Files          95       95               
  Lines       16131    16135        +4     
===========================================
- Hits        14449     9329     -5120     
- Misses       1682     6806     +5124     
Impacted Files Coverage Δ
pymc/step_methods/slicer.py 27.38% <19.04%> (-68.87%) ⬇️

... and 69 files with indirect coverage changes

self.model = modelcontext(model)
self.w = w
model = modelcontext(model)
self.w = np.asarray(w).copy()
Copy link
Member

Choose a reason for hiding this comment

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

Does asarray not make a copy, or is that array?

Copy link
Member Author

@ricardoV94 ricardoV94 May 8, 2023

Choose a reason for hiding this comment

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

asarray returns the same object if it's already a numpy array

@ricardoV94 ricardoV94 merged commit 4242faf into pymc-devs:main May 8, 2023
@ricardoV94 ricardoV94 deleted the slice_perf branch June 5, 2023 08:36
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