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

Fix bug in NUTS variable assignment #4952

Merged
merged 4 commits into from
Aug 19, 2021
Merged

Conversation

aloctavodia
Copy link
Member

This is a bug I found while working on bringing BART to V4 #4914. NUTS should use the variables passed to the sampler and not get them from the model. @ricardoV94 recommend having this fix in its own PR and separated from the BART PR.

@codecov
Copy link

codecov bot commented Aug 19, 2021

Codecov Report

Merging #4952 (6249cf5) into main (3fb5807) will increase coverage by 0.05%.
The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4952      +/-   ##
==========================================
+ Coverage   74.01%   74.06%   +0.05%     
==========================================
  Files          86       86              
  Lines       13860    13862       +2     
==========================================
+ Hits        10258    10267       +9     
+ Misses       3602     3595       -7     
Impacted Files Coverage Δ
pymc3/parallel_sampling.py 87.29% <50.00%> (-0.93%) ⬇️
pymc3/step_methods/hmc/base_hmc.py 91.05% <100.00%> (ø)
pymc3/step_methods/hmc/integration.py 90.38% <0.00%> (-1.93%) ⬇️
pymc3/model.py 83.45% <0.00%> (-0.15%) ⬇️
pymc3/tests/models.py 87.76% <0.00%> (+8.63%) ⬆️

@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

We should add a minimal test. This seems to trigger it locally:

import pymc3 as pm
with pm.Model() as m:
    x = pm.Normal("x", 0, 1)
    y = pm.Normal("y", 0, 1)
    pm.sample(step=pm.Metropolis([m.rvs_to_values[x]]), chains=1, tune=10, draws=10)

@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

Getting this error on the Windows run it test_parallel_sampling.py::test_explicit_sample: AttributeError: 'functools.partial' object has no attribute '__name__'

https://github.com/pymc-devs/pymc3/pull/4952/checks?check_run_id=3368890696#step:7:75

@Spaak, @michaelosthege do you happen to have any idea? These tests are all related to multiprocessing...

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

Getting this error on the Windows run it test_parallel_sampling.py::test_explicit_sample: AttributeError: 'functools.partial' object has no attribute '__name__'

https://github.com/pymc-devs/pymc3/pull/4952/checks?check_run_id=3368890696#step:7:75

@Spaak, @michaelosthege do you happen to have any idea? These tests are all related to multiprocessing...

Yes this is definitely caused by pickling (probably a step method), required when multiprocessing uses spawn (which is the default on Windows; POSIX OSes use fork). Default pickle chokes on functools.partial objects, which is why we switched to cloudpickle (#4858). Could be I missed one/a few instances of pickling that still uses default pickle? I can have a look later today.

@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

Could be I missed one/a few instances of pickling that still uses default pickle? I can have a look later today.

You might have missed it because the tests were marked as xfail for other reasons (the one addressed in this PR)

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

You might have missed it because the test was marked as an x-fail for other reasons (the one addressed in this PR)

Yes that's probably what happened. I'll work on a fix now, which I'll file as a separate PR (rather than push commits here) to keep the commit history on main clean (I don't yet know how much code I'll have to touch).

@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

You might have missed it because the test was marked as an x-fail for other reasons (the one addressed in this PR)

Yes that's probably what happened. I'll work on a fix now, which I'll file as a separate PR (rather than push commits here) to keep the commit history on main clean (I don't yet know how much code I'll have to touch).

Sure, but if you find it easier, feel free to force push a clean history to this PR.

The bugfix that is revelant to this PR is really just those two lines that @aloctavodia changed in pymc3/step_methods/hmc/base_hmc.py in the first commit

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

Apologies; pre-commit has made me lazy and I forgot I was working in an environment that I hadn't installed pre-commit in yet. (So I pushed a commit here that failed pre-commit CI.) I'll force-push the same changes (but now properly blacked/isorted etc.) here in a minute. (So no separate PR; it turned out to be a minor change.)

@ricardoV94
Copy link
Member

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

@ricardoV94 I did make the same changes to test_abort, but it's still failing for another reason, so I left the xfail.

@ricardoV94
Copy link
Member

@ricardoV94 I did make the same changes to test_abort, but it's still failing for another reason, so I left the xfail.

Didn't notice. Thanks.

One of the changed test seems to have failed though

@Spaak Spaak force-pushed the nuts_vars branch 2 times, most recently from 8cc2e7e to e721e11 Compare August 19, 2021 09:24
@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

Oh well... that test_abort is still giving problems. Going to simply skip it until we figure it out. I did not change anything in my force push: https://github.com/pymc-devs/pymc3/compare/e721e11df92604d448601e97bbd0ad7677bd7735..b504f0c416c91c4f6b3334110b4e2703a1aaaa92

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

Hmm after your force push the test_abort is xpassing: https://github.com/pymc-devs/pymc3/pull/4952/checks?check_run_id=3370627851 which was still xfail before. Did you rebase onto main or so causing it now to succeed..?

@ricardoV94
Copy link
Member

ricardoV94 commented Aug 19, 2021

It fails locally for me (regardless of floatX), so I think it is just a weird fluke

@Spaak
Copy link
Member

Spaak commented Aug 19, 2021

Going to simply skip it until we figure it out.

Yep good idea

@ricardoV94
Copy link
Member

Thanks @aloctavodia and @Spaak

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

Successfully merging this pull request may close these issues.

3 participants