-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Support PyTensor deterministic operations as observations #7656
base: main
Are you sure you want to change the base?
Conversation
We need to tell InferenceData converter how to get the data values to put in |
I don't consider this a bugfix, it's behavior that was explicitly forbidden for conservative reasons (more like a NotImplementedError) |
Where does this happen in the code? |
I think the MiniBatch tests will still fail. Any thoughts on how that should behave? |
Also, feel free to choose a better title! I couldn't express it too well |
scale = 12 | ||
scaled_target = target / scale | ||
mu = pm.Normal("mu", mu=0, sigma=1) | ||
pm.Normal("x", mu=mu, sigma=1, observed=scaled_target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I sample this to check that it has the correct data in the InferenceData?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we have more direct ways of testing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well maybe. Just make sure to do a cheap sampling, since we don't care about draws at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the "extract_..." function directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a more direct unit test, this would be a CI, we don't care how it's done just want to be sure the data is there in the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still want some sampling here to check the outputs? This test is not testing anything explicitly at the moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add sampling to this test when I can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Line 63 in fa43eba
Line 152 in fa43eba
We should be able to just use constant_fold (also in pytensor) for it |
I have an implementation before this suggestion. I need a little help understanding this. Feel free to put suggestion |
What do you mean? My suggestion is to simply call constant_fold on the observed variable |
I am not able to make this work with either |
From pymc.pytensorf. There's a |
Ah if it's a SharedVariable like |
from pytensor.compile.mode import Mode
import pymc as pm
with pm.Model(coords={"date": [0, 1, 2]}) as m:
data = pm.Data("data", [0, 1, 2], dims="date")
x = pm.Normal("x")
y = pm.Normal("y", x, observed=data, dims="date")
cheap_eval_mode = Mode(linker="py", optimizer=None)
m.rvs_to_values[y].eval(mode=cheap_eval_mode)
# array([0., 1., 2.]) |
Thanks for the suggestion. I've used mode on the random variable directly. Is it different to get the rvs_to_values from the model? it currently isn't accessed from the function at the moment. |
Could you point me to similar tests for this? |
I've just added to associated pytensorf test suite |
There are some failing tests related to the Mini batch also using the is_valid_observed function as well. How should those be handled. Are those test tests no longer valid? |
Yeah sounds like the test should be changed to the more strict kind of stuff that we still don't allow, like having a pt.random.normal in it. |
Looks like a random test failure? Will address rest of feedback when I have chance |
Yeah that one is flaky, we should probably try/except on that error and just skip when it happens |
Are we far from merge here? |
Hi @ricardoV94 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7656 +/- ##
==========================================
- Coverage 92.70% 92.65% -0.06%
==========================================
Files 107 107
Lines 18391 18327 -64
==========================================
- Hits 17050 16981 -69
- Misses 1341 1346 +5
|
Description
Will need some help on this implementation and how to best test this.
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7656.org.readthedocs.build/en/7656/