Lightweight config loader with imports, string interpolation, and grid-search axis expansion
Project description
Simple Hackable Configmanager
[!IMPORTANT] This is a small hackable configuration manager. It just does what you expect it to do. Load from json/yaml, importing, string interpolation, expanding axes, manual overwrite, yield mutable /immutable dictionaries whose keys you may access by attributes.
Basic Usage
from your.utils import make_model, make_optim
from yourparent.configmanager import (
load_config, ImmutableAttributDict, AttributeDict
)
config : AttributeDict = load_config('tests/model.yaml', make_immutable=False)[0]
model = make_model(**conf.model.kwargs)
optimizer = make_optim(**conf.optim.kwargs)
# hashable (for use in jax.jitted regions)
hash(mutable_config)
Features - Imports
# config/mymodel/kwargs1.yaml
param1 : 1
param2 : "heythere buddy!"
# config/model.yaml
model:
kwargs:
__import__: "configs/mymodel/kwargs1.yaml"
... resolves to ...
model:
kwargs:
param1 : 1
param2 : "heythere buddy!"
[!NOTE] Per default, all nested dictionaries are merged instead of overwritten. In case you want to specify custom overwrite behaviour, please take a look further down below.
Features - Axes
[!NOTE] A really nice addition is the use of
expandable axes. This lets you specify a (nested) grid of axes in a single .yaml file.
model:
kwargs:
__axis__:
- batchnorm: false
use_bottleneck: false
- batchnorm: true
use_bottleneck: false
additional_param: 42
- {} # defaults
optim:
kwargs:
__axis__:
- path: 'optax.adamw'
- path: 'your.module.optimizer'
Turned into a bunch of configurations:
"""
this will return a list of 3 * 2 configs, as we have two
axes which are expanded. Axis one `model.kwargs` has three entries,
axis `optim.kwargs` has 2 entries.
"""
configs = load_config('tests/model.yaml')
Features - String interpolation
data:
shape: [42, 1]
seed: 0
optim:
lr: 0.001
info: "heytherebuddy"
model:
kwargs:
input_shape : "$(data.shape)" # resolves to [42, 1]
checkpoint: "run-seed:$(seed)-lr:$(optim.lr)-checkpoint-.pickle" # resolves to "run-seed:0-lr:0.001-checkpoint.pickle"
$(optim.info) : $(optim.info) # resolves to "heytherebuddy" : "heytherebuddy"
Custom Overwrites
Sometimes, you wouldn't want dictionaries to be merged. If you're instead looking for a hard-overwrite option, here it is:
__import__: "some_default_setup.yaml"
optim:
path: "my.module.optim"
__overwrite__(kwargs):
please_just_keep : "this keyword argument, instead of merging"
Instead of importing a default optimizer which would probably have the key kwargs defined, we overwrite. This resolves to something like:
model:
...
...
optim:
path: "my.module.optim"
kwargs:
please_just_keep : "this keyword argument, instead of merging"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gridconf-0.1.0.tar.gz.
File metadata
- Download URL: gridconf-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43fffd5d82cf727809d04133ecb53ce06be01e81ae23b66468841e5f1156a1c8
|
|
| MD5 |
3514ebfaae85178c80daf285ae9a39bb
|
|
| BLAKE2b-256 |
89f527c92e1cfc4cae86172a0ae5d16213c595ff809d8e0a440839b90cf160c9
|
File details
Details for the file gridconf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gridconf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a82a72363590276bb9489c2f3d1b951decfc5b0dc0f7200fa86016f79c18d77
|
|
| MD5 |
df0c4ef5c6bdcc7bb392abc428987116
|
|
| BLAKE2b-256 |
fbd30f15a0f0f5a2ecd3c3dbc5486fe0f8e5afa774cfe0539bd62e1d1a9d8865
|