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)
Built Distribution
Close
Hashes for config_spec-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66c8635e272c9ebe41f1a7e81ae1e919d2dfd88d28e0d255d4cfdc897b349bf3 |
|
MD5 | b1b4d96b3dd3c5e34b06be288a70d9f0 |
|
BLAKE2b-256 | 9961d9f8279c738a5e585f38d9475d5aaf817f81fda4d01534a1fb2d85ebadda |