-
Notifications
You must be signed in to change notification settings - Fork 256
Build the mixed estimators from a typed config #1997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
5013e11
6ff7cea
accb769
b364a3e
95bc297
a0703f4
b10094b
08d2410
9de4403
3114a4a
5ed8875
ae2ae5d
61280c4
1abd59e
19eca3b
7a0d9a5
cafae67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1535,16 +1535,7 @@ def build( | |
| return _build_mixed_density_estimator( | ||
| batch_x=batch_input, | ||
| batch_y=batch_condition, | ||
| continuous_config=self.continuous, | ||
| z_score_y=self.z_score_condition, | ||
| num_categories_per_variable=self.num_categories_per_variable, | ||
| embedding_net=self.embedding_net, | ||
| combined_embedding_net=self.combined_embedding_net, | ||
| log_transform_x=self.log_transform_x, | ||
| discrete_hidden_features=self.discrete_hidden_features, | ||
| discrete_hidden_layers=self.discrete_hidden_layers, | ||
| combined_embedding_features=self.combined_embedding_features, | ||
| dropout_probability=self.dropout_probability, | ||
| config=self, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -1637,3 +1628,85 @@ def _config_from_factory_kwargs( | |
| ) | ||
|
|
||
| return config_cls(**accepted, extra_kwargs=unknown) | ||
|
|
||
|
|
||
| def _mixed_config_from_factory_kwargs( | ||
| family_args: dict, | ||
| factory_defaults: dict, | ||
| extra: dict, | ||
| ) -> MixedConfig: | ||
| """Build a mixed config from the deprecated factories' flat arguments.""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a full docstring here explaining what this function does. |
||
| # The flat API typed these as `Optional[int] = None`, so an explicit None | ||
| # meant "unset" and has to keep behaving like omitting the argument. | ||
| unset_if_none = ( | ||
| "continuous_hidden_features", | ||
| "discrete_hidden_features", | ||
| "combined_embedding_features", | ||
| ) | ||
| extra = { | ||
| name: value | ||
| for name, value in extra.items() | ||
| if value is not None or name not in unset_if_none | ||
| } | ||
| flow_model = extra.pop("flow_model", "nsf") | ||
|
|
||
| mixed_kwargs = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "z_score_condition": family_args["z_score_condition"], | ||
| "embedding_net": family_args["embedding_net"], | ||
| } | ||
| mixed_fields = ( | ||
| "num_categories_per_variable", | ||
| "combined_embedding_net", | ||
| "log_transform_x", | ||
| "discrete_hidden_features", | ||
| "discrete_hidden_layers", | ||
| "combined_embedding_features", | ||
| "dropout_probability", | ||
| ) | ||
| for name in mixed_fields: | ||
| if name in extra: | ||
| mixed_kwargs[name] = extra.pop(name) | ||
|
|
||
| continuous_args = { | ||
| name: family_args[name] | ||
| for name in ( | ||
| "z_score_input", | ||
| "hidden_features", | ||
| "num_transforms", | ||
| "num_bins", | ||
| "num_components", | ||
| ) | ||
| } | ||
| continuous_defaults = {name: factory_defaults[name] for name in continuous_args} | ||
|
|
||
| if "continuous_hidden_features" in extra: | ||
| # The flat API let this override only the continuous width while the | ||
| # categorical width kept falling back to `hidden_features`. | ||
|
Comment on lines
+1691
to
+1692
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments. |
||
| mixed_kwargs.setdefault( | ||
| "discrete_hidden_features", continuous_args["hidden_features"] | ||
| ) | ||
| continuous_args["hidden_features"] = extra.pop("continuous_hidden_features") | ||
|
|
||
| dropout_probability = mixed_kwargs.get("dropout_probability") | ||
| config_cls = _DENSITY_CONFIGS.get(flow_model) | ||
| if ( | ||
| dropout_probability is not None | ||
| and config_cls is not None | ||
| and "dropout_probability" in {f.name for f in fields(config_cls)} | ||
| ): | ||
| extra["dropout_probability"] = dropout_probability | ||
|
|
||
| # The flat mixed API passed `tail_bound` to every builder, so the models | ||
| # that read it saw 10.0 rather than their own narrower default. | ||
|
Comment on lines
+1706
to
+1707
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments. |
||
| if config_cls is not None and "tail_bound" in {f.name for f in fields(config_cls)}: | ||
| extra.setdefault("tail_bound", 10.0) | ||
|
|
||
| continuous = _config_from_factory_kwargs( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The caller wrote |
||
| flow_model, | ||
| _DENSITY_CONFIGS, | ||
| "mixed continuous density", | ||
| family_args=continuous_args, | ||
| factory_defaults=continuous_defaults, | ||
| extra=extra, | ||
| ) | ||
| return MixedConfig(continuous=continuous, **mixed_kwargs) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function removes the last production reader of
model_builders,ConditionalFlowConfigand_BUILD_KWARG_ALIASES' flat path, so three things can be deleted I think, please double check:model_buildersat line 46, plus 16 of the 18 builder imports at line 19 that exist only to fill it (build_zuko_unconditional_flowis the only one with another caller). Not insbi.neural_nets.__all__, not documented — about 34 lines kept alive bytest_legacy_public_builder_registry_remains_complete.ClassifierConfig(estimator_configs.py:358, 20 lines) — no reference left anywhere.ConditionalFlowConfig(estimator_configs.py:298, 60 lines) — none insbi/. The three tests inbuild_context_test.pythat use it are testing_EstimatorBuilderBase, andMarginalFlowConfigis still alive, so it can stand in.