Skip to main content

Lightweight config loader with imports, string interpolation, and grid-search axis expansion

Project description

gridconf - 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.

Installation

pip install gridconf

Basic Usage

from your.utils import make_model, make_optim
from gridconf 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gridconf-0.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gridconf-0.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file gridconf-0.1.1.tar.gz.

File metadata

  • Download URL: gridconf-0.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.15

File hashes

Hashes for gridconf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d760bfd3b8e182b4c867a6d3e4b557cd7078638325d78a104710c96627cc5e92
MD5 c9aadb6068b355eff4ff4369319858a6
BLAKE2b-256 bce3e7095d85b7f2b7b3387bd74f3122dce48b843dcb5ae80182f74ebaed1374

See more details on using hashes here.

File details

Details for the file gridconf-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gridconf-0.1.1-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

Hashes for gridconf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c6943d01b52b812a30771b8fc6aa475cb050ee554909e5bc7433219e9fdc3ff
MD5 03f395254c1f156853131108455bd0ec
BLAKE2b-256 772d924a5810181385f645dcc9e6c210f7491ac97c692d90ef81b3ca63f5e62a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page