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

Faulty logic to retrieve tune from mixed samplers #6710

Open
ricardoV94 opened this issue May 8, 2023 · 3 comments
Open

Faulty logic to retrieve tune from mixed samplers #6710

ricardoV94 opened this issue May 8, 2023 · 3 comments

Comments

@ricardoV94
Copy link
Member

This line here assumes that the first sample has tune information, which is not necessarily the case (as the comment above states):

pymc/pymc/sampling/mcmc.py

Lines 738 to 742 in 457421b

# count the number of tune/draw iterations that happened
# ideally via the "tune" statistic, but not all samplers record it!
if "tune" in mtrace.stat_names:
# Get the tune stat directly from chain 0, sampler 0
stat = mtrace._straces[0].get_sampler_stats("tune", sampler_idx=0)

Example that fails (but could be fixed in a future PR without solving the underlying issue:

import pymc as pm

with pm.Model() as m:
    x = pm.Normal("x")
    y = pm.Normal("y", x)
    idata = pm.sample(step=pm.Slice([x]))  # KeyError: 'tune'

As the Slice sampler does not provide tune stats

@manulpatel
Copy link
Contributor

Hi @ricardoV94! So ideally how should we get tune in general from any sampler?

@ricardoV94
Copy link
Member Author

It should be possible to check which sampler contains the tune statistic. If it's too hard a loop with try/except would also work.

@ricardoV94
Copy link
Member Author

Quoting @michaelosthege in #6835 (comment)

For the record: Our current approach of passing information about tuning/not-tuning via sample stats is brittle. It's a per-sampler thing, but in practice it's actually a per-iteration thing from the PyMC, ArviZ and McBackend perspective. IMO we should consider taking it out of the step method attributes and stats, and instead pass tune as a parameter to the astep method.

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

No branches or pull requests

2 participants