config
config
¶
generate_canonical_config(*classes: Any, _non_recurse_cls: List[Any] = []) -> Tuple[Dict[Any, Any], Dict[Any, Any]]
¶
generate a full configuration from components
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*classes
|
List[Type]
|
list of dataclass types to extract fields from |
()
|
Returns:
| Type | Description |
|---|---|
Tuple[Dict[Any, Any], Dict[Any, Any]]
|
Tuple[Dict[str, Any], Dict[str, Any]]: canonical field types and default values |
nest_slash_keys(flat: Dict[str, Any]) -> Dict[str, Any]
¶
Nests a flat dictionary with slash-separated keys into a nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flat
|
Dict[str, Any]
|
Flat dictionary with keys containing slashes. |
required |
Returns: Dict[str, Any]: Nested dictionary.
build_default_config(types: Dict[str, Any], defaults: Dict[str, Any]) -> OmegaConf
¶
Builds a default OmegaConf configuration from types and defaults. Args: types (Dict[str, Any]): Dictionary of configuration types. defaults (Dict[str, Any]): Dictionary of default values.
Returns:
| Name | Type | Description |
|---|---|---|
OmegaConf |
OmegaConf
|
OmegaConf configuration with defaults filled in. |
build(*classes: Any) -> OmegaConf
¶
Builds a default OmegaConf configuration from dataclass types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*classes
|
DataclassInstance | type[DataclassInstance]
|
List of dataclass types. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
OmegaConf |
OmegaConf
|
OmegaConf configuration with defaults filled in. |
hydrate(cls: Any, config: DictConfig | ListConfig) -> Any
¶
Hydrates a dataclass instance from an OmegaConf configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
DataclassInstance | type[DataclassInstance]
|
Dataclass type to instantiate. |
required |
config
|
DictConfig | ListConfig
|
OmegaConf configuration. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DataclassInstance |
Any
|
Instantiated dataclass with values from config. |
configuration(config: DictConfig | ListConfig) -> Generator[None, None, None]
¶
Context manager that sets the current config for configure() calls.
Usage
with Configurate(config): model = configure(ModelConfig)
configure(cls: Any) -> Any
¶
Hydrates a dataclass from the current Configurate context.
Must be called within a Configurate context manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Any
|
Dataclass type to instantiate. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Instantiated dataclass with values from the current config. |
current_config() -> DictConfig | ListConfig | None
¶
Returns the current configuration in the Configurate context.
Returns:
| Type | Description |
|---|---|
DictConfig | ListConfig | None
|
OmegaConf | None: Current configuration or None if not in context. |
patch() -> Generator[DictConfig, None, None]
¶
Context manager that opens the current config for free-form mutation.
If a config context is already active, temporarily disables struct mode so arbitrary keys can be added. Mutations persist into the outer context after the block — this is intentional so that callers like from_pretrained() can enrich a sparse backbone config with architecture fields that remain available for the rest of the job lifecycle.
If no context is active, creates a fresh empty config that lives only for the duration of the block.
Usage::
with patch() as cfg:
cfg.architecture.n_layers = 32
cfg.architecture.attention_bias = False
model.init(
jax.random.PRNGKey(
0
),
dummy,
)