Make GP latent vs marginal test deterministic#8006
Merged
ricardoV94 merged 1 commit intopymc-devs:mainfrom Jan 26, 2026
Merged
Conversation
Contributor
|
Looks good @Jiya873 ! Could you please share the seed you found that makes this fail? That would be useful to note for reference. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8006 +/- ##
==========================================
+ Coverage 90.22% 91.49% +1.27%
==========================================
Files 116 116
Lines 18972 18972
==========================================
+ Hits 17117 17359 +242
+ Misses 1855 1613 -242 🚀 New features to boost your workflow:
|
Contributor
Author
|
First, I created a reproduction script and found that the assertion fails immediately at the first iteration. import numpy as np
import pymc as pm
import pytensor.tensor as pt
import numpy.testing as npt
from tqdm import tqdm
def run_reproduction(seed):
rng = np.random.RandomState(seed)
n_outputs = 2
X = rng.randn(20, 3)
y = rng.randn(n_outputs, 20)
Xnew = rng.randn(30, 3)
pnew = rng.randn(n_outputs, 30)
with pm.Model() as latent_model:
cov_func = pm.gp.cov.ExpQuad(3, [0.1, 0.2, 0.3])
mean_func = pm.gp.mean.Constant(0.5)
latent_gp = pm.gp.Latent(mean_func=mean_func, cov_func=cov_func)
latent_f = latent_gp.prior("f", X, n_outputs=n_outputs, reparameterize=True)
latent_p = latent_gp.conditional("p", Xnew)
with pm.Model() as marginal_model:
cov_func = pm.gp.cov.ExpQuad(3, [0.1, 0.2, 0.3])
mean_func = pm.gp.mean.Constant(0.5)
marginal_gp = pm.gp.Marginal(mean_func=mean_func, cov_func=cov_func)
marginal_f = marginal_gp.marginal_likelihood("f", X, y, sigma=0.0)
marginal_p = marginal_gp.conditional("p", Xnew)
lp_latent = latent_p.eval({latent_f: y})
lp_marginal = marginal_p.eval()
npt.assert_allclose(lp_latent, lp_marginal, rtol=1e-4)
if __name__ == "__main__":
iterations = 500
for i in tqdm(range(iterations)):
try:
run_reproduction(seed=i)
except AssertionError as e:
print(f"\nCaught failure at seed: {i}")
print(e)
breakI reproduced the failure locally using seed 0. |
ricardoV94
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8000