Skip to content

Add VectorFieldEstimatorBuilder for FMPE / NPSE trainers - #1921

Merged
janfb merged 27 commits into
sbi-dev:mainfrom
satwiksps:nn-builder-refactor-pr-six
Aug 7, 2026
Merged

janfb merged 27 commits into
sbi-dev:mainfrom
satwiksps:nn-builder-refactor-pr-six

Conversation

@satwiksps

@satwiksps satwiksps commented Jul 6, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR continues the GSoC 2026 Neural Network Builder API refactor by introducing the VectorFieldEstimatorBuilder for both vector field trainers (FMPE & NPSE).

Instead of passing a string like vf_estimator="mlp" and configuring everything through factory functions, users can now pass a fully typed builder: VectorFieldEstimatorBuilder(model="mlp", hidden_features=128). The builder covers all four network architectures (mlp, ada_mlp, transformer, transformer_cross_attn) and provides immediate validation — passing score-only arguments (like beta_min) to a flow-matching builder, architecture-specific fields to the wrong model (like num_heads for "mlp"), or sde_type mismatches all fail fast with helpful error messages.

The estimator_type field defaults to None and is automatically resolved by the trainer (FMPE → "flow", NPSE → "score"), so users don't need to specify it unless they want explicit control. This brings FMPE and NPSE fully in line with the builder pattern previously added for NPE, NLE, and NRE.

Files Changed

  • estimator_configs.py: Added the VectorFieldEstimatorBuilder frozen dataclass with full typing, estimator_type/sde_type field guards, and per-architecture validation via _reject_inapplicable_fields.
  • vector_field_nets.py: Fixed time_emb_type default to "sinusoidal" for parity with the factory path.
  • fmpe.py & npse.py: Updated the trainers to accept VectorFieldEstimatorBuilder, resolve estimator_type=None, and reject mismatched types. Passing a string is still supported but emits a FutureWarning.
  • base_vf_inference.py: Removed None from the base class signature and deleted the unreachable branch (subclasses own the default).
  • trainers/base.py: Lifted _wrap_builder into NeuralInference, fixed docstring typo, and typed the builder parameter.
  • nre_base.py: Removed the duplicate _wrap_builder (identical to the inherited base version).
  • score_estimator.py: Fixed overlapping-memory crash by cloning mean_0 / std_0 in the score estimator constructor.
  • tests/vf_builder_integration_test.py: Added tests for builder integration, estimator_type auto-resolution, cross-trainer rejection, per-architecture validation, conflict guards, and deprecation warnings.

AI Usage

Used Grammarly for PR description refinement, VS Code Copilot for code suggestions, and GPT OSS via Antigravity for docstrings and cosmetic updates. Some tests were improved during review by Claude Opus 4.6 via Antigravity.

Does this close any issues?

N/A

@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch from 3e8f552 to 2896bdc Compare July 22, 2026 05:53
@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch 2 times, most recently from df54baf to 900a7bf Compare July 28, 2026 17:03
@satwiksps
satwiksps marked this pull request as ready for review July 28, 2026 17:21
@codecov

codecov Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.31%. Comparing base (8c6f1ea) to head (3ccf5fe).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1921      +/-   ##
==========================================
+ Coverage   89.21%   89.31%   +0.10%     
==========================================
  Files         140      140              
  Lines       13895    13987      +92     
==========================================
+ Hits        12396    12493      +97     
+ Misses       1499     1494       -5     
Flag Coverage Δ
fast 83.97% <100.00%> (?)

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

Files with missing lines Coverage Δ
sbi/inference/trainers/base.py 94.16% <100.00%> (+0.13%) ⬆️
sbi/inference/trainers/nle/nle_base.py 97.36% <100.00%> (-0.14%) ⬇️
sbi/inference/trainers/npe/npe_base.py 95.68% <ø> (-0.15%) ⬇️
sbi/inference/trainers/nre/nre_base.py 93.10% <100.00%> (-0.38%) ⬇️
sbi/inference/trainers/vfpe/base_vf_inference.py 94.93% <100.00%> (+0.19%) ⬆️
sbi/inference/trainers/vfpe/fmpe.py 100.00% <100.00%> (+8.69%) ⬆️
sbi/inference/trainers/vfpe/npse.py 95.65% <100.00%> (+11.03%) ⬆️
sbi/neural_nets/__init__.py 100.00% <ø> (ø)
sbi/neural_nets/factory.py 95.29% <ø> (ø)
sbi/neural_nets/net_builders/__init__.py 100.00% <ø> (ø)
... and 2 more

... and 1 file with indirect coverage changes

@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch from 4b6e717 to 57d7dc2 Compare July 28, 2026 18:06
@satwiksps
satwiksps marked this pull request as draft July 28, 2026 18:30
@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch from 57d7dc2 to ef5d3a6 Compare July 29, 2026 05:48
@satwiksps
satwiksps marked this pull request as ready for review July 29, 2026 05:49
@satwiksps

satwiksps commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi @janfb,

fix: clone base distribution parameters to avoid memory overlap in lo… for bug in VPScoreEstimator for torch.broadcast_to create memory view but when load_state_dict() try to copy checkpoint weights to it, Pytorch refuses as multiple elements share same memory address. IMO .clone() is the standard fix.
asked Copilot the cause and it said it surfaces here because the GSoC test files shift pytest-split shard boundaries, causing the VP tests to hit the load_state_dict path.

also I hope the remaining CI failures could be fixed when main merges into gsoc-2026 ?

@janfb

janfb commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Hi @satwiksps, thanks for the detailed comment. I will do the full review later today, but one thing upfront because it explains your CI failures:

  • the PR silently changed the default z-scoring. Before, FMPE(prior) resolved via posterior_flow_nn, which defaults z_score_theta="independent". Your builder dispatches to build_vector_field_estimator, which defaults z_score_x=None, so no z-scoring at all.

I think the cleanest fix is at the root: change the defaults in build_vector_field_estimator to

z_score_x: Optional[str] = "independent",
z_score_y: Optional[str] = "independent",

That matches all other low-level net builders (build_maf etc.), and posterior_flow_nn / posterior_score_nn pass these explicitly anyway, so nothing else changes.

This is also why the c2st test fails (it uses default FMPE(prior) on unstandardized data) and why the load_state_dict crash appeared: with z-scoring off, mean_0 is a scalar, and the broadcast_to view then has overlapping memory. So merging main won't fix your CI — this will. Keep the .clone() though, that fix is correct either way.

Please also add a small regression test that the default builder produces a standardizing net, so this can't slip through again.

Cheers, Jan

@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch 2 times, most recently from 63b62e9 to ddde810 Compare July 29, 2026 11:07

@janfb janfb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

well done! this is a very complex PR due to the complexity of the VF kwargs. I noticed a couple of general design issues, but they are beyond the scope of this PR, so I suggest to fix the obvious problems here now, see my comments.

Comment thread sbi/inference/trainers/nle/nle_base.py Resolved
Comment thread sbi/inference/trainers/base.py Resolved
@satwiksps

Copy link
Copy Markdown
Collaborator Author

All tests pass now, thank you Jan, for helping me find hidden errors 🙌. Once the cherry picked PRs are merged in to main, after new release, I will change base branch to main and see if any merge conflicts, resolve them and then re-request review.

@satwiksps
satwiksps changed the base branch from gsoc-2026 to main August 5, 2026 05:08
@satwiksps
satwiksps force-pushed the nn-builder-refactor-pr-six branch from c9443a6 to ef50ece Compare August 5, 2026 07:37
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change adds VectorFieldEstimatorBuilder, integrates builder configuration with FMPE and NPSE, centralizes trainer input ordering, updates vector-field network defaults, and adds integration tests for validation and training behavior.

Changes

Vector-field estimator builder integration

Layer / File(s) Summary
Builder configuration and network construction
sbi/neural_nets/net_builders/estimator_configs.py, sbi/neural_nets/net_builders/vector_field_nets.py, sbi/neural_nets/factory.py, sbi/neural_nets/__init__.py, sbi/neural_nets/net_builders/__init__.py
Adds vector-field builder configuration, validation, estimator dispatch, shared model types, cross-attention support, independent z-scoring defaults, and sinusoidal time embeddings.
Trainer input and condition contract
sbi/inference/trainers/base.py, sbi/inference/trainers/nle/nle_base.py, sbi/inference/trainers/npe/npe_base.py, sbi/inference/trainers/nre/nre_base.py
Centralizes builder input ordering with _INPUT_IS_THETA and _wrap_builder. NLE uses observation-first ordering. Duplicate adapters are removed from NPE and NRE.
FMPE and NPSE estimator integration
sbi/inference/trainers/vfpe/base_vf_inference.py, sbi/inference/trainers/vfpe/fmpe.py, sbi/inference/trainers/vfpe/npse.py
Accepts builder objects, resolves flow or score estimator types, validates conflicting arguments, retains deprecated string paths, and requires a configured neural-network builder.
Builder and trainer integration tests
tests/vf_builder_integration_test.py
Tests configuration validation, warnings, conflicts, end-to-end training, asymmetric shapes, trainer compatibility, normalization defaults, and supported architectures.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FMPE_or_NPSE
  participant VectorFieldTrainer
  participant VectorFieldEstimatorBuilder
  participant build_vector_field_estimator
  FMPE_or_NPSE->>VectorFieldTrainer: provide estimator configuration
  VectorFieldTrainer->>VectorFieldEstimatorBuilder: validate and normalize builder
  VectorFieldTrainer->>VectorFieldEstimatorBuilder: pass ordered input and condition batches
  VectorFieldEstimatorBuilder->>build_vector_field_estimator: dispatch estimator type and network
  build_vector_field_estimator-->>VectorFieldEstimatorBuilder: return ConditionalVectorFieldEstimator
  VectorFieldEstimatorBuilder-->>VectorFieldTrainer: provide configured estimator
Loading

Possibly related PRs

  • sbi-dev/sbi#1957: Extends estimator-builder integration across shared trainer and vector-field builder infrastructure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding VectorFieldEstimatorBuilder support for FMPE and NPSE trainers.
Description check ✅ Passed The description directly explains the builder API, supported trainers, validation behavior, compatibility changes, and tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
sbi/inference/trainers/vfpe/npse.py (1)

109-111: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the sde_type documentation to match the new behavior.

The text says sde_type is "Only used when vf_estimator is a string (i.e. when using the default builder)". Three cases now exist:

  • vf_estimator is None: sde_type is forwarded to the default VectorFieldEstimatorBuilder (Line 167).
  • vf_estimator is a VectorFieldEstimatorBuilder: a non-default sde_type raises ValueError (Line 156). Set sde_type on the builder.
  • vf_estimator is a string: sde_type is forwarded to posterior_score_nn (Line 199).

State these cases so users know where to set the value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sbi/inference/trainers/vfpe/npse.py` around lines 109 - 111, Update the
sde_type parameter documentation near the trainer configuration to describe all
three behaviors: when vf_estimator is None, it is forwarded to the default
VectorFieldEstimatorBuilder; when vf_estimator is a VectorFieldEstimatorBuilder,
non-default sde_type raises ValueError and must be configured on the builder;
and when vf_estimator is a string, it is forwarded to posterior_score_nn.
sbi/neural_nets/net_builders/vector_field_nets.py (2)

171-173: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Documented architecture name does not match the accepted literal. VF_MODELS defines "transformer_cross_attn", and build_vector_field_estimator raises ValueError: Unknown architecture for any other value. Three docstrings still advertise 'transformer_cross_attention', so a user who copies the documented name hits that error.

  • sbi/neural_nets/net_builders/vector_field_nets.py#L171-L173: change "transformer_cross_attention" to "transformer_cross_attn" in the net argument description.
  • sbi/neural_nets/factory.py#L378-L378: change 'transformer_cross_attention' to 'transformer_cross_attn' in the posterior_score_nn model list.
  • sbi/neural_nets/factory.py#L469-L469: change 'transformer_cross_attention' to 'transformer_cross_attn' in the posterior_flow_nn model list.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sbi/neural_nets/net_builders/vector_field_nets.py` around lines 171 - 173,
Replace the outdated transformer architecture name with “transformer_cross_attn”
in the net argument description of vector_field_nets.py and in the
posterior_score_nn and posterior_flow_nn model lists in factory.py at the
specified ranges, keeping all other documented architecture names unchanged.

230-246: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Remove duplicate is_x_emb_seq forwarding.

When posterior_flow_nn or posterior_score_nn receives is_x_emb_seq, the transformer call raises TypeError: got multiple values for keyword argument 'is_x_emb_seq'. Remove the key from forwarded kwargs while preserving the caller-provided value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sbi/neural_nets/net_builders/vector_field_nets.py` around lines 230 - 246,
Update the transformer branch around build_transformer_network so is_x_emb_seq
is removed from kwargs before forwarding, while preserving and using the
caller-provided value when present; retain the existing net-based default for
callers that omit it and avoid passing the argument twice.
🧹 Nitpick comments (3)
sbi/neural_nets/net_builders/estimator_configs.py (1)

744-751: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Correct the dispatch names in the class docstring.

The docstring states that build() dispatches to build_flow_matching_estimator or build_score_matching_estimator. build() calls build_vector_field_estimator and passes estimator_type. Update the text so readers can follow the actual call path.

📝 Proposed docstring fix
     matching).  The ``estimator_type`` field selects between the two:
-    ``"flow"`` dispatches to ``build_flow_matching_estimator`` and
-    ``"score"`` dispatches to ``build_score_matching_estimator``.
+    ``build()`` forwards it to ``build_vector_field_estimator``, which
+    constructs a ``FlowMatchingEstimator`` for ``"flow"`` and a
+    ``ConditionalScoreEstimator`` subclass for ``"score"``.
     """
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sbi/neural_nets/net_builders/estimator_configs.py` around lines 744 - 751,
Update the class docstring’s dispatch description to reference
build_vector_field_estimator as the method called by build(), while retaining
that estimator_type selects between flow and score behavior.
tests/vf_builder_integration_test.py (1)

172-177: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused gaussian_sims argument.

test_builder_role_shapes builds its own prior, theta, and x at Lines 175-177. The gaussian_sims fixture is requested but never used, so the fixture runs for no reason.

♻️ Proposed cleanup
 `@pytest.mark.parametrize`("trainer_cls", [FMPE, NPSE])
-def test_builder_role_shapes(trainer_cls, gaussian_sims):
+def test_builder_role_shapes(trainer_cls):
     """Asymmetric dims catch silent role swaps (Decision 10/13)."""
     prior = MultivariateNormal(zeros(2), torch.eye(2))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/vf_builder_integration_test.py` around lines 172 - 177, Remove the
unused gaussian_sims parameter from test_builder_role_shapes and its
parametrized test signature, leaving the locally constructed prior, theta, and x
data unchanged.
sbi/inference/trainers/vfpe/npse.py (1)

155-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a sentinel default for sde_type to detect an explicit value.

The conflict check treats sde_type != "ve" as "the caller passed sde_type". A caller who passes sde_type="ve" explicitly together with a builder that sets sde_type="vp" gets no error, and the builder value wins silently. A sentinel default (for example sde_type: Optional[...] = None) would let you detect an explicit value exactly and keep "ve" as the resolved default. This is optional; the current behavior already documents builder precedence.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sbi/inference/trainers/vfpe/npse.py` around lines 155 - 162, Update the
trainer’s sde_type handling around the VectorFieldEstimatorBuilder conflict
check to use a sentinel or None default that distinguishes omitted from
explicitly provided values, including explicit "ve". Preserve "ve" as the
resolved default when sde_type is omitted, while raising for any explicitly
supplied value that conflicts with the builder’s sde_type.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sbi/inference/trainers/vfpe/base_vf_inference.py`:
- Around line 376-380: Reset _best_val_loss, _epochs_since_last_improvement, and
_best_model_state_dict at epoch 0 for non-resumed training runs instead of
relying on hasattr, while preserving them when resume_training is true. Record
the resume state before the training loop and update the convergence-state
initialization in the surrounding training method so a fresh run cannot load a
prior run’s checkpoint.

In `@sbi/neural_nets/net_builders/estimator_configs.py`:
- Around line 703-707: Move the public VF_MODELS type alias from
estimator_configs.py into sbi_types.py, then import or re-export it in
estimator_configs.py so existing consumers remain compatible. Keep
_VALID_VF_MODELS defined locally in estimator_configs.py using the relocated
alias.

In `@tests/vf_builder_integration_test.py`:
- Around line 258-285: Update test_default_builder_applies_z_scoring to validate
the score estimator’s actual input-normalization statistics, mean_0 and std_0,
rather than using _mean_base and _std_base for non-flow estimators. Keep the
existing flow assertions and embedding_net Standardize check unchanged.

---

Outside diff comments:
In `@sbi/inference/trainers/vfpe/npse.py`:
- Around line 109-111: Update the sde_type parameter documentation near the
trainer configuration to describe all three behaviors: when vf_estimator is
None, it is forwarded to the default VectorFieldEstimatorBuilder; when
vf_estimator is a VectorFieldEstimatorBuilder, non-default sde_type raises
ValueError and must be configured on the builder; and when vf_estimator is a
string, it is forwarded to posterior_score_nn.

In `@sbi/neural_nets/net_builders/vector_field_nets.py`:
- Around line 171-173: Replace the outdated transformer architecture name with
“transformer_cross_attn” in the net argument description of vector_field_nets.py
and in the posterior_score_nn and posterior_flow_nn model lists in factory.py at
the specified ranges, keeping all other documented architecture names unchanged.
- Around line 230-246: Update the transformer branch around
build_transformer_network so is_x_emb_seq is removed from kwargs before
forwarding, while preserving and using the caller-provided value when present;
retain the existing net-based default for callers that omit it and avoid passing
the argument twice.

---

Nitpick comments:
In `@sbi/inference/trainers/vfpe/npse.py`:
- Around line 155-162: Update the trainer’s sde_type handling around the
VectorFieldEstimatorBuilder conflict check to use a sentinel or None default
that distinguishes omitted from explicitly provided values, including explicit
"ve". Preserve "ve" as the resolved default when sde_type is omitted, while
raising for any explicitly supplied value that conflicts with the builder’s
sde_type.

In `@sbi/neural_nets/net_builders/estimator_configs.py`:
- Around line 744-751: Update the class docstring’s dispatch description to
reference build_vector_field_estimator as the method called by build(), while
retaining that estimator_type selects between flow and score behavior.

In `@tests/vf_builder_integration_test.py`:
- Around line 172-177: Remove the unused gaussian_sims parameter from
test_builder_role_shapes and its parametrized test signature, leaving the
locally constructed prior, theta, and x data unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6ede3170-336e-445a-9c80-4ca2e5afea2d

📥 Commits

Reviewing files that changed from the base of the PR and between 8c6f1ea and ef50ece.

📒 Files selected for processing (13)
  • sbi/inference/trainers/base.py
  • sbi/inference/trainers/nle/nle_base.py
  • sbi/inference/trainers/npe/npe_base.py
  • sbi/inference/trainers/nre/nre_base.py
  • sbi/inference/trainers/vfpe/base_vf_inference.py
  • sbi/inference/trainers/vfpe/fmpe.py
  • sbi/inference/trainers/vfpe/npse.py
  • sbi/neural_nets/__init__.py
  • sbi/neural_nets/factory.py
  • sbi/neural_nets/net_builders/__init__.py
  • sbi/neural_nets/net_builders/estimator_configs.py
  • sbi/neural_nets/net_builders/vector_field_nets.py
  • tests/vf_builder_integration_test.py
💤 Files with no reviewable changes (1)
  • sbi/inference/trainers/npe/npe_base.py

Comment thread tests/vf_builder_integration_test.py Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/vf_builder_integration_test.py (1)

335-367: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a rejection test for 2-D cross-attention conditions. When net="transformer_cross_attn" receives 2-D batch_y, assert ValueError with the documented sequence-shape message.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/vf_builder_integration_test.py` around lines 335 - 367, Extend
test_all_architectures_build with a case where transformer_cross_attn receives
2-D batch_y and assert build_vector_field_estimator raises ValueError containing
the documented sequence-shape message. Keep the existing valid 3-D
cross-attention case unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/vf_builder_integration_test.py`:
- Around line 335-367: Extend test_all_architectures_build with a case where
transformer_cross_attn receives 2-D batch_y and assert
build_vector_field_estimator raises ValueError containing the documented
sequence-shape message. Keep the existing valid 3-D cross-attention case
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15be97a6-e56f-4265-8f98-512e8460418a

📥 Commits

Reviewing files that changed from the base of the PR and between 1ca6ecf and a4fb358.

📒 Files selected for processing (3)
  • sbi/inference/trainers/vfpe/base_vf_inference.py
  • sbi/inference/trainers/vfpe/npse.py
  • tests/vf_builder_integration_test.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • sbi/inference/trainers/vfpe/base_vf_inference.py
  • sbi/inference/trainers/vfpe/npse.py

@satwiksps
satwiksps requested a review from janfb August 6, 2026 10:59

@janfb janfb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Almost done, two things remain, see comments.

Comment thread sbi/inference/trainers/base.py Resolved
Comment thread sbi/inference/trainers/vfpe/npse.py Resolved
Comment thread tests/vf_builder_integration_test.py Resolved
Comment thread sbi/inference/trainers/vfpe/npse.py Resolved
@satwiksps
satwiksps requested a review from janfb August 7, 2026 08:54

@janfb janfb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

all fixed now, great! 👏

@janfb
janfb merged commit 94c9a7c into sbi-dev:main Aug 7, 2026
17 checks passed
@satwiksps
satwiksps deleted the nn-builder-refactor-pr-six branch August 7, 2026 10:14
janfb added a commit that referenced this pull request Aug 17, 2026
`posterior_flow_nn(z_score_theta=None)` does not disable z-scoring any more.
The config layer drops `None` fields as "unset", and #1921 changed the
`build_vector_field_estimator` default from `None` to "independent". The
parametrization thus trained a z-scored network, and the strict xfail became
an XPASS on all Python versions.

"none" disables z-scoring, so the case again tests what its id says. The xfail
stays valid: FMPE without z-scoring gives C2ST 0.61 on the shifted data.
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