Skip to content

Conversation

@Jiya873
Copy link

@Jiya873 Jiya873 commented Dec 16, 2025

Fixes #8000

@maresb
Copy link
Contributor

maresb commented Dec 20, 2025

Looks good @Jiya873 ! Could you please share the seed you found that makes this fail? That would be useful to note for reference.

@codecov
Copy link

codecov bot commented Dec 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.49%. Comparing base (cadb97a) to head (756e02b).

Additional details and impacted files

Impacted file tree graph

@@            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     

see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiya873
Copy link
Author

Jiya873 commented Dec 20, 2025

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)
            break

I reproduced the failure locally using seed 0.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: Strange flakiness in TestMarginalVsLatent GP test on Windows

2 participants