parameters
parameters
¶
Abstract base class for parameter collections with serialization helpers.
Parameters is the common superclass for every configuration group in
config/ (DataParameters, TrainingHyperparams, GenerateParameters,
etc.). It extends pydantic.BaseModel with:
- Recursive iteration over nested parameter groups.
- Name-based lookup across the full parameter tree (
get(),has()). - YAML / JSON round-trip serialization (
from_yaml(),to_yaml(),from_json()).
Classes:
| Name | Description |
|---|---|
Parameters |
Abstract base for parameter collections used throughout the config layer. |
Parameters
pydantic-model
¶
Bases: BaseModel
Abstract base for parameter collections used throughout the config layer.
Subclasses define typed fields (e.g. int, Literal["auto"] | float)
and inherit recursive iteration, name-based lookup, and YAML / JSON
serialization from this class.
Config:
default:pydantic_model_config
explicit_patch()
¶
Compile this model's recursively explicit fields as a sparse patch.
Explicit fields inside nested default models are included even when the parent field itself was never assigned. Patch values are deep-copied by the compiler, so later mutations cannot affect patch application.
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
apply_patch(patch)
¶
Overlay a compiled patch on this full model and validate once.
The base is materialized in full so environment-backed and validator- resolved defaults keep their current values. Patch assignments retain their relative precedence and always follow the base.
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
from_config_source(source=None, *, unknown_field_behavior='ignore', **kwargs)
classmethod
¶
Normalize one sparse config source plus higher-precedence keyword values.
source may be None, an instance of exactly cls, or a raw
mapping. Declared compatibility aliases are normalized for raw mappings
and keyword overrides. unknown_field_behavior controls whether
unknown raw mapping keys are ignored or rejected. Keyword overrides
accept top-level fields and canonical dotted paths, but reject inferred
bare nested names with an actionable path suggestion. A different
Pydantic model type is rejected rather than adapted.
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
get(name, default=None)
¶
Look up a parameter or sub-group by name across the full tree.
Explicit dotted paths such as "generation.validation.foo" resolve
directly. Bare names are accepted only when they map to exactly one
field in the parameter tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name to search for. |
required |
default
|
Any
|
Value returned when |
None
|
Returns:
| Type | Description |
|---|---|
DataT | Any | None
|
The parameter value or sub-group if found, otherwise |
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
has(name)
¶
Check whether name exists anywhere in the parameter tree.
Unlike get(), this does not conflate falsy values (0, "",
False, None) with absence. Bare names are accepted only when
they map to at most one field in the parameter tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name to search for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
from_yaml_str(raw)
classmethod
¶
Construct an instance from a YAML-formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
str
|
YAML content as a string. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A validated |
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
from_json(path, overrides=None)
classmethod
¶
Load from a JSON file, optionally applying field overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathT
|
Path to the JSON file. |
required |
overrides
|
dict | None
|
Field-level overrides applied via |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A validated |
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
from_yaml(path, overrides=None)
classmethod
¶
Load from a YAML file, optionally applying field overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathT
|
Path to the YAML file. |
required |
overrides
|
dict | None
|
Field-level overrides applied via |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A validated |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
to_yaml(path, exclude_unset=True)
¶
Serialize this instance to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathT
|
Destination file path. |
required |
exclude_unset
|
bool
|
If |
True
|
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
from_params(**kwargs)
classmethod
¶
Construct a Parameters instance from keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
object
|
Parameter values passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A validated |
Source code in src/nemo_safe_synthesizer/configurator/parameters.py
get_auto_params()
¶
Yield field names whose current value is the "auto" sentinel.