KappaConfig
KappaConfig is a configuration framework that allows you to define a full fletched configuration in yaml. Basic yaml and many yaml configuration frameworks are restrictive in how a yaml is processed. KappaConfig provides a rich extension to parsing yamls into primitive types.
With support for many use-cases out-of-the-box (which you can use, but don't have to):
- reuse defined dict/list/primities via cross reference or templating
- write python expressions in yaml
- use yamls from multiple sources to compose one large yaml during program execution
Install
Install: pip install kappaconfig
Update to latest release: pip install kappaconfig --upgrade
Examples
This directory contains
various examples on how KappaConfig can be used to create flexible and compact yaml files.
<file>.yaml is the compact representation of a yaml that is resolved to <file>.result.yaml during runtime and
subsequently used by the application. <file>.yaml abstracts away non-vital fields (for easy configuration design),
while the resolved file (<file>.result.yaml) contains every detail for reproducability.
TODO example
TODO title
Lots of configurations consist of a small part that varies between different configurations and a large part that stays the same or only few variables of it change. For example: when running machine learning experiments the core of a dataset configuration (e.g. normalization, splits) stays largely the same but things like preprocessing might change between different experiments.
cifar10:
train:
split: train # use train split
normalization: range # normalize to range [-1;1]
filter: # use 45.000 samples for training
index_from: 0
index_to: 45000
valid:
split: train # use train split (most datasets don't have a dedicated validation split)
normalization: range
filter: # use remaining 5.000 samples for validation
index_from: 45000
index_to: 50000
test:
split: test # use test split
normalization: range
TODO continue example
Usage
import kappaconfig as kc
# load yaml from file
kc_hp = kc.from_file_uri("hyperparams.yaml")
# initialize default resolver
resolver = kc.DefaultResolver()
# resolve to primitive types
hp = resolver.resolve(hp)
Examples
Reference existing nodes
Inspired by OmegaConf/Hydra nodes can reference other nodes.
# input
batch_size: 64
train_loader:
batch_size: ${batch_size}
test_loader:
batch_size: ${batch_size}
---
# resolved
batch_size: 64
train_loader:
batch_size: 64
test_loader:
batch_size: 64
Write python code in yaml
# input
seeds: ${eval:list(range(5))}
---
# resolved
seeds: [0, 1, 2, 3, 4]
Parameterize templates
# warmup_cosine_schedule.yaml
vars: # vars is a special node that is removed after resolving a template
# default values
epochs: 100
warmup_factor: 0.05
kind: sequential_schedule
sub_schedules:
- kind: warmup_schedule
epochs: ${eval:${vars.epochs}*${vars.warmup_factor}}
- kind: cosine_schedule
epochs: ${eval:${vars.epochs}*${eval:1-${vars.warmup_factor}}}
---
# template_default_params.yaml
optimizer:
kind: SGD
schedule:
template: ${yaml:warmup_cosine_schedule.yaml}
---
# template_default_params.yaml resolved
optimizer:
kind: SGD
schedule:
kind: sequential_schedule
sub_schedules:
- kind: warmup_schedule
epochs: 5
- kind: cosine_schedule
epochs: 95
---
# template_custom_params.yaml
optimizer:
kind: SGD
schedule:
template: ${yaml:warmup_cosine_schedule.yaml}
template.vars.epochs: 200
---
# template_custom_params.yaml resolved
optimizer:
kind: SGD
schedule:
kind: sequential_schedule
sub_schedules:
- kind: warmup_schedule
epochs: 10
- kind: cosine_schedule
epochs: 190
---
Metadata
Release files for kappaconfig 1.0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kappaconfig-1.0.16.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kappaconfig-1.0.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.6 kB
Release files / kappaconfig-1.0.16.tar.gz
| Download URL | kappaconfig-1.0.16.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51467fc60f454daa00485f90df6bd8c93479b38e76b2b46a66a33098fcc3e403
|
|
BLAKE2b-256 checksum How to use checksums |
a152b7da5a596780933d39e2bfe49cf54db0f76fd76c856912223db5d7dc3efc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / kappaconfig-1.0.16-py3-none-any.whl
| Download URL | kappaconfig-1.0.16-py3-none-any.whl |
|---|---|
| Size | 23.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdfd854b9d138b075a39b74d2e13f46c14c9305a07e8d0591cacd6b41f1bd175
|
|
BLAKE2b-256 checksum How to use checksums |
3ca49131477c68c3e851514e3d74e0553ad69e865fa3fd20d9a87499d7857cfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|