Skip to main content

JSON-parseable configuration of classes and functions

Project description

config_spec

A small library to help create JSON-serializable configs for functions

Installation:

pip install config_spec 
pip install git+https://github.com/dibyaghosh/config_spec.git

Basic Usage

from model import create_model
from config_spec import Spec
model_constructor = functools.partial(create_model, num_layers=3)
config = Spec.create(model_constructor) # a dictionary
with open('config.json', 'w') as f:
    json.dump(config, f)
# model_constructor == Spec.instantiate(config)
from model import create_model
from config_spec import recursive_partial_to_spec, recursive_spec_to_partial
config = {
    'model': functools.partial(create_model, num_layers=3),
    'optimizer': functools.partial(torch.optim.Adam, lr=1e-3),
    'num_steps': 1000,
    'batch_size': 32,
} # But this isn't serializable!
config = recursive_partial_to_spec(config) # a dictionary
with open('config.json', 'w') as f:
    json.dump(config, f)

# Later, when you want to load the config:
with open('config.json', 'r') as f:
    config = json.load(f)
config = recursive_spec_to_partial(config)

Notes

This tool was originally created for Octo, a codebase for training robot foundation models.

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

config_spec-0.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

config_spec-0.0.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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