Config¶
Configuration and model building utilities.
load_yaml() and build_module() expand nested .yml/.yaml references by
default for trusted training and plugin configurations. Production artifact
loaders pass allow_file_references=False so an artifact cannot redirect
module construction to an untrusted sidecar YAML file.
Build Module¶
build_module(config, hyperpar=None, *, allow_file_references=True, import_authorizer=None)
¶
Build a module based on the provided configuration. Every (possibly nested) dictionary with a 'class' key will be replaced by an instance initialized with arguments and keywords provided as 'args' and 'kwargs' keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[str, Dict, List]
|
The configuration for building the module. |
required |
hyperpar
|
Union[str, Dict, None]
|
The hyperparameters for the module. Defaults to None. |
None
|
allow_file_references
|
bool
|
Whether nested YAML file references are
expanded before constructing modules. Defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
Union[List, Dict, Callable]: The built module. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in aimnet/config.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
Module Lookup¶
get_module(name, *, role='class')
¶
Retrieves a module and function based on the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the module and function in the format 'module.function'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
function |
Callable[..., Any]
|
The function object. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the module cannot be imported. |
AttributeError
|
If the function does not exist in the module. |
Source code in aimnet/config.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_init_module(name, args=None, kwargs=None, *, role='class')
¶
Get the initialized module based on the given name, arguments, and keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the module. |
required |
args
|
List
|
The arguments to pass to the module constructor. Defaults to an empty list. |
None
|
kwargs
|
Dict
|
The keyword arguments to pass to the module constructor. Defaults to an empty dictionary. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The initialized module. |
Source code in aimnet/config.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
YAML Loading¶
load_yaml(config, hyperpar=None, *, basedir=None, allow_file_references=True)
¶
Load a YAML configuration file and apply optional hyperparameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[str, List, Dict]
|
The YAML configuration file path or a YAML object. |
required |
hyperpar
|
Optional[Union[Dict, str, None]]
|
Optional hyperparameters to apply to the configuration. |
None
|
basedir
|
Optional[str]
|
Base directory used to resolve relative YAML
file references. Defaults to the directory containing |
None
|
allow_file_references
|
bool
|
Whether string values ending in
|
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | list
|
Union[List, Dict]: The loaded and processed configuration. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a file specified in the configuration does not exist. |
Source code in aimnet/config.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Dotted Dictionaries¶
dict_to_dotted(d, parent='')
¶
Source code in aimnet/config.py
205 206 207 208 209 210 211 212 213 214 215 | |
dotted_to_dict(d)
¶
Source code in aimnet/config.py
218 219 220 221 222 223 224 225 226 227 228 229 230 | |