A portable configuration tool to manage hyperparameters and settings of your experiments.
✅ Support syntax highlighting and autocompletion for attributes
✅ Support arguments control through command line
✅ Support nested definition (namespaces) to isolate parameters of the same name
✅ Inherent Singleton ensuring consistent revision across files
✅ Support basic type checking
You can install the latest official version of xparameter from PyPI:
pip install xparameter
# config.py
from xparameter import Configure as C
from xparameter import Field as F
class Config(C):
"""Define your overall description here"""
class checkpoint(C):
"""Define group description here"""
directory = F(str, default="./checkpoints", help="Directory to save model checkpoints")
Config.parse_sys_args()
Parameters in Config
class will be automatically registered onto a argparse.ArgumentParser()
, which acts as a parser to extract parameter values from command line. In this example case, we use
python test.py --checkpoint.directory "/path/to/checkpoints"
The argument Config.checkpoint.directory
will be set to "/path/to/checkpoints"
. This parsing process and the following manual revision will trigger an inherent type check.
Use the help
command to print automatically generated help menu:
python test.py --help
Usage: config_01.py [-h] [--checkpoint.directory str]
Define your overall description here
Options:
-h, --help show this help message and exit
Checkpoint:
Define group description here
--checkpoint.directory str Directory to save model checkpoints
Manual revision of the argument values can be performed either independently or as a post-processing step following the aforementioned command-line parsing, e.g.,
# Config.parse_sys_args()
Config.checkpoint.directory = "/path/to/checkpoints"
Export as python dict:
Config.as_dict()
Export as json string:
Config.as_json()