Skip to main content

Easy Configuration

Reason this release was yanked:

major flaw in nested declearation in config

Project description

CHANfiG

Introduction

CHANfiG aims to make your confuration easier.

There are tons of configurable parameters in training a Machine Learning model. To configure all these parameters, researchers usually need to write giant config files, somtimes even thousdands of lines. Most of the configs are just replicates of the default arguments of certain functions, resuling many unnessary declarations. It is also very hard to alter the configurations, one needs to navigade and open the right configuration file, make changes, save and exit. These had wasted an incountable[^incountable] amount of precisious time and is no doubt a crime. Using argparse could relief the burdens to some extent, however, it takes a lot of works to make it compatible with existing config files, and it's lack of nesting limits it's potentials. CHANfiG would like to make a change.

You just run your experiment, with arguments.

CHANfiG is highly inspired by YACS. Different to the paradigm of YACS( your code + a YACS config for experiment E (+ external dependencies + hardware + other nuisance terms ...) = reproducible experiment E), The paradigm of CHANfiG is:

your code + command line arguments (+ optional CHANfiG config + external dependencies + hardware + other nuisance terms ...) = reproducible experiment E (+ optional CHANfiG config for experiment E)

Usage

Existing code:

from chanfig import Config, ConfigParser


class Model:
    def __init__(self, encoder, dropout=0.1, activation='ReLU'):
        self.encoder = Encoder(**encoder)
        self.dropout = Dropout(dropout)
        self.activation = getattr(Activation, activation)

def main(config):
    model = Model(**config.model)
    optimizer = Optimizer(**config.optimizer)
    scheduler = Scheduler(**config.scheduler)
    dataset = Dataset(**config.dataset)
    dataloader = Dataloader(**config.dataloader)


if __name__ == '__main__':
    # config = Config.read('config.yaml')  # in case you want to read from a yaml
    # config = Config.read('config.json')  # in case you want to read from a json
    existing_configs = {'data.batch_size': 64, 'model.encoder.num_layers': 8}
    config = Config(**existing_configs)
    config = config.parse()
    # CLI arguments: python xxx.py --activation GELU
    # config.merge('dataset.yaml')
    config.model.decoder.num_layers = 8
    main(config)
    # config.yaml('config.yaml')  # in case you want to save a yaml
    # config.json('config.json')  # in case you want to save a json

All you needs to do is just run a line:

python main.py --model.encoder.num_layers 6 --model.dropout 0.2

You could also load a default configure file and make changs based on it:

python main.py --config meow.yaml --model.encoder.num_layers 6 --model.dropout 0.2

If you have made it dump current configurations, this should be in the written file:

data:
  batch_size: 64
model:
  encoder:
    num_layers: 8
  decoder:
    num_layers: 8
  activation: GELU
{
  "data": {
    "batch_size": 64
  },
  "model": {
    "encoder": {
      "num_layers": 8
    },
    "decoder": {
      "num_layers": 8
    },
  "activation": "GELU"
  }
}

Defing the default arguments in function, put alteration in CLI, and leave the rest to CHANfiG.

It works the way it should have worked.

[^incountable]: fun fact: time is always incountable.

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

chanfig-0.0.12-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file chanfig-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: chanfig-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.12

File hashes

Hashes for chanfig-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 0931cfca15d902e70b601b513c89753754eced827f5dac360e2412b71e05e330
MD5 ab558402a39a9961a077bc1adf4fb811
BLAKE2b-256 819f407bc845e0520cb8de1b07ab0e63f98e921cb7a7a6ef01897e5b85745063

See more details on using hashes here.

Supported by

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