Repository navigation
port: NN-builder series (PR1-5) from gsoc-2026 to main - #1957
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1957 +/- ##
==========================================
- Coverage 88.02% 87.96% -0.06%
==========================================
Files 143 144 +1
Lines 13558 17348 +3790
==========================================
+ Hits 11934 15260 +3326
- Misses 1624 2088 +464
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR adds immutable estimator builders and build-context types, updates NPE, NLE, and NRE trainers to use them, renames the estimator build protocol, deprecates string configuration, exports builder classes, adjusts network defaults, and adds unit and integration tests. ChangesEstimator builder API migration
Estimated code review effort: 5 (Critical) | ~120 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
tests/density_estimator_builder_test.py (1)
71-81: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that the supplied embedding module is installed.
Line 81 only rejects
nn.Identity. It does not prove thatDensityEstimatorBuilderforwardsembinto the estimator. Assert that an estimator submodule is the same object asemb.Proposed test change
- # The embedding net must not be a plain Identity. - assert not isinstance(estimator.embedding_net, nn.Identity) + assert any(module is emb for module in estimator.modules())🤖 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/density_estimator_builder_test.py` around lines 71 - 81, Update test_density_estimator_builder_build_with_embedding_net to assert that the built estimator’s embedding_net is the exact emb object supplied to DensityEstimatorBuilder, replacing the weaker nn.Identity check while preserving the existing type assertion.sbi/neural_nets/net_builders/flow.py (1)
586-586: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate stale
num_binsdocstring after the default change.
build_zuko_nsfandbuild_zuko_ncsfchange thenum_binsdefault from8to10(Line 586, Line 651). The docstrings for both functions still state "Defaults to 8" (Line 619, Line 679). Update the docstring text to match the new default value.As per coding guidelines,
**/*.pyfiles must "Use Google-style docstrings for functions and classes", which requires the documented defaults to stay accurate.📝 Proposed docstring fix
- num_bins: The number of bins in the spline transformations. Defaults to 8. + num_bins: The number of bins in the spline transformations. Defaults to 10.Apply this change at both Line 619 (
build_zuko_nsf) and Line 679 (build_zuko_ncsf).Also applies to: 619-619, 651-651, 679-679
🤖 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/flow.py` at line 586, Update the Google-style docstrings for build_zuko_nsf and build_zuko_ncsf so their num_bins parameter descriptions state a default of 10 instead of 8, matching the current function signatures.Source: Coding guidelines
sbi/neural_nets/net_builders/estimator_configs.py (2)
57-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winResolve field annotations before
Literalvalidation.If this module adds
from __future__ import annotations,Field.typebecomes a string and_literal_values()stops validatingLiteralfields. Cacheget_type_hints(type(self))once per builder class and pass the resolved annotations to_literal_values(). The explicit_VALID_*discriminator checks do not depend onField.type.🤖 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 57 - 85, Update _EstimatorBuilderBase.__post_init__ to resolve annotations with get_type_hints(type(self)) once per builder class, then pass each resolved field annotation to _literal_values() instead of f.type. Preserve the existing validation behavior and leave explicit _VALID_* discriminator checks independent of Field.type.
70-76: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMark
extra_kwargsas keyword-only to prevent positional argument misuse.
extra_kwargsis the first field on_EstimatorBuilderBase, making it the first positional parameter of all builder subclasses. A user callingDensityEstimatorBuilder("nsf")assigns"nsf"toextra_kwargsinstead ofmodel. Themodelfield retains its default value"maf", which is valid, so__post_init__()validation does not detect the error. All current tests use keyword arguments, which masks this hazard.Add
kw_only=Trueto prevent the base field from capturing positional arguments intended for subclass discriminators.- extra_kwargs: dict = field(default_factory=dict) + extra_kwargs: dict = field(default_factory=dict, kw_only=True)The project requires Python 3.10 or newer (
requires-python = ">=3.10"in pyproject.toml), sokw_onlyis available.🤖 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 70 - 76, Update the extra_kwargs field in _EstimatorBuilderBase to be keyword-only by enabling the dataclass field’s kw_only option, ensuring positional arguments in estimator builder subclasses bind to fields such as model instead of extra_kwargs.
🤖 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/neural_nets/net_builders/estimator_configs.py`:
- Around line 397-414: Move the public type aliases DENSITY_MODELS and
CLASSIFIER_MODELS from estimator_configs.py to sbi/sbi_types.py to follow the
coding guideline that shared public type aliases belong in sbi_types.py. Import
these aliases back into estimator_configs.py, and keep the private frozensets
_VALID_DENSITY_MODELS and _VALID_CLASSIFIER_MODELS local to the
estimator_configs.py file since they are implementation details for validation.
- Around line 585-591: Update the mixed estimator validation in __post_init__ to
use the accepted fields from _build_mixed_density_estimator together with the
inner continuous-model builder signature, rather than validating only
model_builders[self.continuous_model]. Ensure num_transforms, num_components,
num_bins, and tail_bound are accepted while preserving rejection of unrelated
fields.
In `@tests/build_context_test.py`:
- Line 24: Update each listed test function in tests/build_context_test.py
(lines 24, 38, 45, 69, 151, 158, and 167) and
tests/density_estimator_builder_test.py (lines 16, 21, 28, and 38) with concise
Google-style docstrings describing the behavior under test: z-score defaults,
valid and invalid modes, injected statistics, from_kwargs serialization,
unknown-key warnings, deprecated aliases, invalid model validation, sparse
serialization, extra-key serialization, and build keyword filtering.
---
Nitpick comments:
In `@sbi/neural_nets/net_builders/estimator_configs.py`:
- Around line 57-85: Update _EstimatorBuilderBase.__post_init__ to resolve
annotations with get_type_hints(type(self)) once per builder class, then pass
each resolved field annotation to _literal_values() instead of f.type. Preserve
the existing validation behavior and leave explicit _VALID_* discriminator
checks independent of Field.type.
- Around line 70-76: Update the extra_kwargs field in _EstimatorBuilderBase to
be keyword-only by enabling the dataclass field’s kw_only option, ensuring
positional arguments in estimator builder subclasses bind to fields such as
model instead of extra_kwargs.
In `@sbi/neural_nets/net_builders/flow.py`:
- Line 586: Update the Google-style docstrings for build_zuko_nsf and
build_zuko_ncsf so their num_bins parameter descriptions state a default of 10
instead of 8, matching the current function signatures.
In `@tests/density_estimator_builder_test.py`:
- Around line 71-81: Update
test_density_estimator_builder_build_with_embedding_net to assert that the built
estimator’s embedding_net is the exact emb object supplied to
DensityEstimatorBuilder, replacing the weaker nn.Identity check while preserving
the existing type assertion.
🪄 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: dd87f876-bcb3-4178-94d4-2e26f0464ff8
📒 Files selected for processing (30)
sbi/inference/trainers/nle/mnle.pysbi/inference/trainers/nle/nle_a.pysbi/inference/trainers/nle/nle_base.pysbi/inference/trainers/npe/mnpe.pysbi/inference/trainers/npe/npe_a.pysbi/inference/trainers/npe/npe_b.pysbi/inference/trainers/npe/npe_base.pysbi/inference/trainers/npe/npe_c.pysbi/inference/trainers/npe/npe_pfn.pysbi/inference/trainers/nre/bnre.pysbi/inference/trainers/nre/nre_a.pysbi/inference/trainers/nre/nre_b.pysbi/inference/trainers/nre/nre_base.pysbi/inference/trainers/nre/nre_c.pysbi/inference/trainers/vfpe/base_vf_inference.pysbi/inference/trainers/vfpe/fmpe.pysbi/inference/trainers/vfpe/npse.pysbi/neural_nets/__init__.pysbi/neural_nets/build_context.pysbi/neural_nets/estimators/base.pysbi/neural_nets/net_builders/__init__.pysbi/neural_nets/net_builders/estimator_configs.pysbi/neural_nets/net_builders/flow.pysbi/neural_nets/net_builders/mixed_nets.pysbi/neural_nets/net_builders/vector_field_nets.pysbi/utils/user_input_checks.pytests/build_context_test.pytests/density_estimator_builder_test.pytests/npe_nle_builder_integration_test.pytests/nre_builder_integration_test.py
|
@satwiksps this is the port of your builder PRs (1–5) to main, now that 0.27 has shipped. The six cherry-picks are your commits unchanged. The three commits on top are mine, from the pre-merge review. Can I ask you for a review?
Two of these change the base class you extend in #1921, so they matter for your retarget: the keyword-only change applies to cheers, Jan |
satwiksps
left a comment
There was a problem hiding this comment.
Went through all four of your commits on top plus the six cherry-picks. Everything looks good to me.
The extra_kwargs catch is really nice. I reproduced it in my branch VectorFieldEstimatorBuilder("transformer") bound the name to extra_kwargs and quietly left model="mlp". this kw_only on _EstimatorBuilderBase fixes it for every subclass at once, including ones that don't exist yet, and the test pins it so it cant come back. That is a nicer fix than anything I could have written.
Thanks for doing the port and for the review opportunity on top.
898b1c8 to
12db0e2
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/build_context_test.py`:
- Around line 151-155: Update test_estimator_builder_base_from_kwargs to
construct ConditionalFlowConfig via its from_kwargs() method with
hidden_features=64, then retain the existing to_dict() assertion to verify the
known-field handling contract.
🪄 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: 04ce2612-6649-4aa2-8e72-caf0e8a3a267
📒 Files selected for processing (30)
sbi/inference/trainers/nle/mnle.pysbi/inference/trainers/nle/nle_a.pysbi/inference/trainers/nle/nle_base.pysbi/inference/trainers/npe/mnpe.pysbi/inference/trainers/npe/npe_a.pysbi/inference/trainers/npe/npe_b.pysbi/inference/trainers/npe/npe_base.pysbi/inference/trainers/npe/npe_c.pysbi/inference/trainers/npe/npe_pfn.pysbi/inference/trainers/nre/bnre.pysbi/inference/trainers/nre/nre_a.pysbi/inference/trainers/nre/nre_b.pysbi/inference/trainers/nre/nre_base.pysbi/inference/trainers/nre/nre_c.pysbi/inference/trainers/vfpe/base_vf_inference.pysbi/inference/trainers/vfpe/fmpe.pysbi/inference/trainers/vfpe/npse.pysbi/neural_nets/__init__.pysbi/neural_nets/build_context.pysbi/neural_nets/estimators/base.pysbi/neural_nets/net_builders/__init__.pysbi/neural_nets/net_builders/estimator_configs.pysbi/neural_nets/net_builders/flow.pysbi/neural_nets/net_builders/mixed_nets.pysbi/neural_nets/net_builders/vector_field_nets.pysbi/utils/user_input_checks.pytests/build_context_test.pytests/density_estimator_builder_test.pytests/npe_nle_builder_integration_test.pytests/nre_builder_integration_test.py
🚧 Files skipped from review as they are similar to previous changes (28)
- sbi/inference/trainers/vfpe/base_vf_inference.py
- sbi/neural_nets/net_builders/init.py
- sbi/inference/trainers/vfpe/fmpe.py
- sbi/inference/trainers/nle/nle_a.py
- sbi/neural_nets/net_builders/mixed_nets.py
- sbi/inference/trainers/nre/nre_c.py
- tests/density_estimator_builder_test.py
- sbi/inference/trainers/vfpe/npse.py
- sbi/inference/trainers/nre/nre_b.py
- sbi/utils/user_input_checks.py
- sbi/neural_nets/init.py
- sbi/inference/trainers/npe/npe_pfn.py
- sbi/inference/trainers/nre/nre_a.py
- sbi/inference/trainers/npe/npe_c.py
- tests/npe_nle_builder_integration_test.py
- sbi/inference/trainers/nre/bnre.py
- sbi/neural_nets/build_context.py
- sbi/inference/trainers/npe/npe_a.py
- sbi/inference/trainers/nle/mnle.py
- sbi/neural_nets/net_builders/vector_field_nets.py
- sbi/inference/trainers/npe/npe_b.py
- sbi/neural_nets/estimators/base.py
- sbi/inference/trainers/nre/nre_base.py
- sbi/inference/trainers/nle/nle_base.py
- sbi/inference/trainers/npe/mnpe.py
- sbi/neural_nets/net_builders/flow.py
- sbi/inference/trainers/npe/npe_base.py
- sbi/neural_nets/net_builders/estimator_configs.py
| def test_estimator_builder_base_from_kwargs(): | ||
| """The existing from_kwargs() + to_dict() contract is preserved.""" | ||
| cfg = ConditionalFlowConfig(hidden_features=64) | ||
| d = cfg.to_dict() | ||
| assert d == {"hidden_features": 64} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Exercise from_kwargs() in this test.
Line 153 constructs ConditionalFlowConfig directly. The test does not cover known-field handling through from_kwargs().
Proposed fix
- cfg = ConditionalFlowConfig(hidden_features=64)
+ cfg = ConditionalFlowConfig.from_kwargs(hidden_features=64)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def test_estimator_builder_base_from_kwargs(): | |
| """The existing from_kwargs() + to_dict() contract is preserved.""" | |
| cfg = ConditionalFlowConfig(hidden_features=64) | |
| d = cfg.to_dict() | |
| assert d == {"hidden_features": 64} | |
| def test_estimator_builder_base_from_kwargs(): | |
| """The existing from_kwargs() + to_dict() contract is preserved.""" | |
| cfg = ConditionalFlowConfig.from_kwargs(hidden_features=64) | |
| d = cfg.to_dict() | |
| assert d == {"hidden_features": 64} |
🤖 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/build_context_test.py` around lines 151 - 155, Update
test_estimator_builder_base_from_kwargs to construct ConditionalFlowConfig via
its from_kwargs() method with hidden_features=64, then retain the existing
to_dict() assertion to verify the known-field handling contract.
The builder classes dispatch straight to the build_* functions, so any default that differed from the factory silently changed the network the trainers construct. MNLE() and MNPE() had lost capacity this way (num_transforms 5 -> 2, num_bins 10 -> 5, num_components 10 -> 5). Aligns num_bins in build_zuko_nsf/ncsf, num_transforms in build_zuko_gf/bpf, and the three mixed defaults; updates the two num_bins docstrings that stated the old value.
12db0e2 to
aea7742
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
sbi/neural_nets/net_builders/estimator_configs.py (1)
141-177: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
extra_kwargscan still fail at build time for classifiers without**kwargs.
_reject_inapplicable_fieldsonly checks declared dataclass fields._build_kwargsmergesself.extra_kwargsinto the call at Line 126.build_mlp_classifierandbuild_resnet_classifierdeclare no**kwargs. An unknown key inextra_kwargstherefore raisesTypeErrorinside the build function during training, not at builder construction.Consider validating
extra_kwargskeys againstbuild_fnwhen the target function has noVAR_KEYWORDparameter, so the error surfaces at construction time with the same message style.🤖 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 141 - 177, Update _reject_inapplicable_fields to also validate keys in self.extra_kwargs when build_fn does not accept VAR_KEYWORD arguments; reject unknown keys during construction using the existing discriminator-aware ValueError message style, while allowing declared parameters and aliases.
🤖 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/nre/nre_base.py`:
- Around line 493-507: Add Google-style docstrings to `_wrap_builder` and its
nested `build_fn`: document the `builder` parameter and returned callable for
`_wrap_builder`, and document `batch_theta`, `batch_x`, and the returned
`RatioEstimator` for `build_fn`, using the existing type annotations and
behavior.
---
Nitpick comments:
In `@sbi/neural_nets/net_builders/estimator_configs.py`:
- Around line 141-177: Update _reject_inapplicable_fields to also validate keys
in self.extra_kwargs when build_fn does not accept VAR_KEYWORD arguments; reject
unknown keys during construction using the existing discriminator-aware
ValueError message style, while allowing declared parameters and aliases.
🪄 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: 50236b18-26b5-4856-9f8c-6007488ccccc
📒 Files selected for processing (30)
sbi/inference/trainers/nle/mnle.pysbi/inference/trainers/nle/nle_a.pysbi/inference/trainers/nle/nle_base.pysbi/inference/trainers/npe/mnpe.pysbi/inference/trainers/npe/npe_a.pysbi/inference/trainers/npe/npe_b.pysbi/inference/trainers/npe/npe_base.pysbi/inference/trainers/npe/npe_c.pysbi/inference/trainers/npe/npe_pfn.pysbi/inference/trainers/nre/bnre.pysbi/inference/trainers/nre/nre_a.pysbi/inference/trainers/nre/nre_b.pysbi/inference/trainers/nre/nre_base.pysbi/inference/trainers/nre/nre_c.pysbi/inference/trainers/vfpe/base_vf_inference.pysbi/inference/trainers/vfpe/fmpe.pysbi/inference/trainers/vfpe/npse.pysbi/neural_nets/__init__.pysbi/neural_nets/build_context.pysbi/neural_nets/estimators/base.pysbi/neural_nets/net_builders/__init__.pysbi/neural_nets/net_builders/estimator_configs.pysbi/neural_nets/net_builders/flow.pysbi/neural_nets/net_builders/mixed_nets.pysbi/neural_nets/net_builders/vector_field_nets.pysbi/utils/user_input_checks.pytests/build_context_test.pytests/density_estimator_builder_test.pytests/npe_nle_builder_integration_test.pytests/nre_builder_integration_test.py
🚧 Files skipped from review as they are similar to previous changes (26)
- sbi/neural_nets/net_builders/mixed_nets.py
- sbi/inference/trainers/vfpe/base_vf_inference.py
- sbi/neural_nets/net_builders/init.py
- sbi/utils/user_input_checks.py
- sbi/inference/trainers/npe/npe_a.py
- sbi/inference/trainers/vfpe/fmpe.py
- sbi/inference/trainers/nre/nre_b.py
- sbi/inference/trainers/nre/nre_a.py
- tests/density_estimator_builder_test.py
- tests/nre_builder_integration_test.py
- sbi/inference/trainers/nre/bnre.py
- sbi/neural_nets/net_builders/vector_field_nets.py
- sbi/neural_nets/estimators/base.py
- sbi/inference/trainers/nre/nre_c.py
- sbi/inference/trainers/npe/npe_b.py
- sbi/inference/trainers/npe/npe_c.py
- sbi/neural_nets/init.py
- sbi/inference/trainers/nle/nle_a.py
- sbi/neural_nets/net_builders/flow.py
- sbi/inference/trainers/npe/npe_base.py
- tests/build_context_test.py
- sbi/neural_nets/build_context.py
- sbi/inference/trainers/nle/mnle.py
- sbi/inference/trainers/npe/npe_pfn.py
- sbi/inference/trainers/nle/nle_base.py
- sbi/inference/trainers/vfpe/npse.py
| @staticmethod | ||
| def _wrap_builder( | ||
| builder: _EstimatorBuilderBase, | ||
| ) -> Callable: | ||
| """Wrap a builder object as a legacy-compatible build function. | ||
|
|
||
| This allows the existing ``_initialize_neural_network`` flow to work | ||
| unchanged: the returned callable has the same ``(batch_theta, batch_x)`` | ||
| signature as the functions produced by ``classifier_nn``. | ||
| """ | ||
|
|
||
| def build_fn(batch_theta, batch_x): | ||
| return builder.build(batch_input=batch_theta, batch_condition=batch_x) | ||
|
|
||
| return build_fn |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add Google-style docstrings for both wrapper functions.
_wrap_builder does not document builder or its return value. Nested build_fn has no docstring. Document the builder, both batch arguments, and the returned RatioEstimator.
As per coding guidelines, **/*.py: Use Google-style docstrings for functions and classes.
🤖 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/nre/nre_base.py` around lines 493 - 507, Add
Google-style docstrings to `_wrap_builder` and its nested `build_fn`: document
the `builder` parameter and returned callable for `_wrap_builder`, and document
`batch_theta`, `batch_x`, and the returned `RatioEstimator` for `build_fn`,
using the existing type annotations and behavior.
Source: Coding guidelines
Two problems with the new builder argument: A builder for the wrong estimator family fell through to the generic callable branch and failed later with an unrelated error. Each trainer now declares the families it accepts in _ALLOWED_BUILDER_TYPES: NPE and NLE take the plain density builder, MNPE and MNLE the mixed one. NPE_A defaults density_estimator to the 'mdn_snpe_a' string, so every NPE_A(prior) call emitted the deprecation warning for a value the user never passed. NPE_A now resolves its own default to a build function before the base class inspects the argument. Also widens the check_estimator_arg annotation to cover builders.
…lders The zuko flows support an unconstraining transform in place of z-scoring, but the builders offered no way to select it and no way to pass the required support distribution. Adds x_dist to both density builders and allows transform_to_unconstrained on the input side. The condition side is deliberately excluded: the build functions validate and apply the transform for the input only, so accepting it for the condition would silently do nothing.
Two arguments did not behave as their names and positions implied, and
both built a different network than the user asked for, without an error.
The NRE builder exposed the build functions' positional x/y naming, in
which embedding_net_x applies to theta. A user following classifier_nn
therefore embedded the parameters with the net meant for the data. The
fields are now embedding_net_theta and embedding_net_x, matching
classifier_nn and the attributes of the built RatioEstimator, and
_build_kwargs translates them.
extra_kwargs is declared on the shared base class, so it was the first
positional parameter of every builder: DensityEstimatorBuilder("nsf")
bound the model name to extra_kwargs and silently built the default MAF.
It is now keyword-only.
Both embedding tests assert the supplied module is installed in the named
slot, and a new test pins the model as the first positional argument of
all three builders.
aea7742 to
2031a40
Compare
Ports the merged NN-builder refactor series from
gsoc-2026tomain: #1872, #1877, #1882, #1904, #1912, #1920. The six commits keep Satwik's authorship and each body points at the original pull request for its description.On top of those, four review fixes:
51216e65fix: align low-level build defaults with the factory defaults. The builders dispatch straight to thebuild_*functions, so a differing default silently changed the network the trainers build —MNLE()/MNPE()had lost capacity this way.521dbfcffix: correct how the trainers handle thedensity_estimatorargument. A builder of the wrong family fell through to the generic callable branch and failed later with an unrelated error; each trainer now declares what it accepts in_ALLOWED_BUILDER_TYPES.NPE_A(prior)also warned about a deprecated string the user never passed.11acc7d9feat: exposetransform_to_unconstrainedandx_diston the density builders. Input side only — the condition side never applies the transform, so offering it there would silently do nothing.2031a40bfix: correct the builder argument surface. The NRE builder exposed the build functions' positional x/y naming, in whichembedding_net_xapplies to theta, so a user followingclassifier_nnembedded the parameters with the net meant for the data. Andextra_kwargs, as the first base-class field, was every builder's first positional parameter, soDensityEstimatorBuilder("nsf")bound the model name toextra_kwargsand silently built the default MAF.Merge with rebase-merge, not squash, to keep per-commit attribution.
2031a40bCodeRabbit review: findings fixed here are the keyword-only
extra_kwargsand two stale docstrings. Its mixed-builder validation finding is declined —_build_mixed_density_estimatordoes forwardnum_transformstobuild_mdn, butbuild_mdndrops it, so the rejection is correct and the proposed union-of-signatures fix would restore the silent-ignore behaviour the check exists to prevent.