Skip to content

A portable configuration tool to manage hyperparameters and settings of your experiments.

License

Notifications You must be signed in to change notification settings

ThomasAtlantis/xparameter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xparameter

A portable configuration tool to manage hyperparameters and settings of your experiments.

Features

✅ 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

Quickstart

You can install the latest official version of xparameter from PyPI:

pip install xparameter

Define Custom Configuration

# 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")

Parse Command-line Arguments

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

Revise Arguments Manually

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 Different Formats

Export as python dict:

Config.as_dict()

Export as json string:

Config.as_json()

About

A portable configuration tool to manage hyperparameters and settings of your experiments.

Topics

Resources

License

Stars

Watchers

Forks

Languages