Python configuration file and command line executable to run a script with
Project description
Python Configuration and a command line Runner
Python configuration file and command line executable to run a script with.
Why a python file as configuration?
- Configuration of any complexity
- No need to serialize the configuration
- No need other meta-languages for the configuration
Usage
In the code
Configuration file (e.g. config.py
):
num_epochs = 100
batch_size = 256
model = resnet18(10)
train_loader = get_train_loader("/path/to/dataset", batch_size=batch_size)
unsup_dataloader = get_train_unsup_loader("/path/to/unsup_dataset", batch_size=batch_size)
...
Script file (e.g. training.py
):
from torch.utils.data import DataLoader
from py_config_runner import ConfigObject, TrainvalConfigSchema
class SSLTrainvalConfigSchema(TrainvalConfigSchema):
unsup_dataloader: DataLoader
def training(config):
# ...
print(config.config_filepath)
print(config.output_path)
print(config.num_epochs)
print(config.model)
print(len(config.train_loader))
def main():
config_filepath = "/path/to/config.py"
config = ConfigObject(config_filepath)
SSLTrainvalConfigSchema.validate(config)
# Add more things at runtime
config.output_path = "/tmp/output"
training(config)
With launcher
cd /path/to/my/project
py_config_runner scripts/training.py configs/train/baseline.py
or
cd /path/to/my/project
python -u -m py_config_runner scripts/training.py configs/train/baseline.py
or if your specific launcher requires only python script files:
cd /path/to/my/project
python -m special_launcher `py_config_runner_script` scripts/training.py configs/train/baseline.py
The only condition on the script file is it should contain run(config, **kwargs)
callable method. Additionally,
argument kwargs contains logger
(e.g. kwargs['logger']
) and local_rank
(e.g. kwargs['logger']
)
for distributed computations.
No restrictions are applied on the configuration file. It is user's responsibility to provide the script file that can
consume given configuration file. Provided configuration file is loaded as python module and exposed into the script as
the module named config
.
Examples
Installation
pip install py-config-runner
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 Distribution
Built Distribution
File details
Details for the file py_config_runner-0.2.0.tar.gz
.
File metadata
- Download URL: py_config_runner-0.2.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d328bff955aba15dbc81d1d4b1e4c0a96a36addfe893381e1d0519432cb1a5f |
|
MD5 | 5e75b2d048aa71479c1390f18f1eadd2 |
|
BLAKE2b-256 | edede01f67c8ebeda1f9982ddeb2cf9e257e49a8b814662c5e072a8085c80de2 |
File details
Details for the file py_config_runner-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: py_config_runner-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e25dd8eb6fa438efee5026b20ab045ffd6cb766c8e632ded9439fcc418e4351 |
|
MD5 | 75653fbe0d9073433f2107680fac4889 |
|
BLAKE2b-256 | 5c4c578766cbe77322cd159be98789c7b12160adcb81c5fa5c61a30e81822770 |