Skip to content

Conversation

janfb
Copy link
Contributor

@janfb janfb commented Sep 2, 2025

The slow vf tests were running for hours and were eventually killed by GH action runners. I believe there were some nested fixture calls causing this issue. This is now fixed and the runtime is "down" to 30min for the slow vf tests.

I also did some refactoring the the vf utils here and there to make it more transparent. IID inference for FMPE is working in parts, see #1656

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.88%. Comparing base (ebcd68e) to head (be335fc).
⚠️ Report is 16 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sbi/inference/posteriors/vector_field_posterior.py 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1657      +/-   ##
==========================================
+ Coverage   86.59%   86.88%   +0.28%     
==========================================
  Files         135      134       -1     
  Lines       10931    11909     +978     
==========================================
+ Hits         9466    10347     +881     
- Misses       1465     1562      +97     
Flag Coverage Δ
unittests 86.88% <97.05%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/inference/potentials/score_fn_iid.py 88.62% <ø> (ø)
sbi/inference/potentials/vector_field_potential.py 87.62% <100.00%> (ø)
sbi/samplers/rejection/rejection.py 87.75% <ø> (ø)
sbi/samplers/score/diffuser.py 91.80% <100.00%> (+5.13%) ⬆️
sbi/inference/posteriors/vector_field_posterior.py 79.10% <95.00%> (+0.36%) ⬆️

... and 21 files with indirect coverage changes

@janfb janfb changed the title Fix vf tests Fix slow vector field tests Sep 2, 2025
@janfb
Copy link
Contributor Author

janfb commented Sep 2, 2025

@@ -130,7 +94,7 @@ def set_x(
self,
x_o: Optional[Tensor],
x_is_iid: Optional[bool] = False,
iid_method: Literal["fnpe", "gauss", "auto_gauss", "jac_gauss"] = "auto_gauss",
iid_method: Optional[str] = None,
Copy link
Contributor

@manuelgloeckler manuelgloeckler Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the Literals?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was causing type checker issues. As this is mostly used internally it's fine to relax the constraints to just str I think.

if save_intermediate:
intermediate_samples.append(samples)

# Check for NaN values after predictor
if torch.isnan(samples).any():
raise RuntimeError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new runtime error which fails the test, right?
This is already happening if a single sample in the batch becomes nan, which might is to strict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good point. but it can happen that all samples are NaN and it takes a very long time until this is detected by accept_reject. Thus, it's probably better to fix this detection problem and allow NaNs for some samples here. will look into that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this check to the posterior level where the final samples are passed on. Also, I changed it to .all(), because this caused the main issue: 'FMPE' with 'auto-gauss' was returning only NaNs. It seems NPSE with iid-sampling returns only sometimes NaNs.
Therefore, NPSE iid-score tests are passing now. FMPE iid-score tests are skipped, except for fnpe.

Copy link
Contributor

@manuelgloeckler manuelgloeckler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, I will have a closer look into it later.

It could be that a single sample or so becomes nan and the newly introduce RuntimeError is raised. Previously, this wasnt a problem because this would be handled by the accept_reject, no?

Copy link
Contributor

@manuelgloeckler manuelgloeckler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks.

Mhh, from your description it could be some of the terminal points on FMPE which can have a singularity in the drift (i.e. in diffusion we add a nugget i.e. we go to exact 0, but not sure for FMPE). Will look after this in #1656 , but fine to merge this already.

Edit: Nvm, if its prior dependent then its likely something numerical with the marginal moments given a Uniform distribution.
Edit: Nvm, it is this.

@janfb janfb merged commit eae9cc9 into main Sep 4, 2025
13 checks passed
@janfb janfb deleted the fix-vf-tests branch September 4, 2025 09:02
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.

2 participants