Managing ML experiment configuation with joy.
Project description
Happy Config
Managing ML experiment configuration with joy.
- Use
dataclass
to define the schema for experiment configurations. - Load configuration from multiple sources: JSON, YAML, NNI.
- Annotate fields with search space, and generate NNI search space file using CLI tool.
Basic Usage
Define configuration schema with dataclass
from dataclasses import dataclass
@dataclass
class Bar:
a: str
b: str
@dataclass
class Foo:
x: int
y: int
bar: Bar
Write configuration files
{
"x": 1,
"y": 1,
"bar:a": "1",
"bar:b": "1"
}
Note the namespace syntax bar:a
we use in JSON. It is also possible to write:
{
"x": 1,
"y": 1,
"bar": {
"a": "1"
},
"bar:b": "1"
}
Create a ConfigLoader
instacen from the schema, and load the configuration
from happy_config import ConfigLoader
loader = ConfigLoader(model=Foo, config="config.json")
config: Foo = loader() # Foo(x=1, y=1, bar=Bar(a="1", b="1"))
If we save the code in main.py
, we can use command line arguments to specify the configuration file path:
python main.py --config config.json
And we can overwrite the configurations directly using command line arguments:
python main.py --x 10 --bar:b 100
We have to use the namespace syntax here.
Generating NNI Search Space File
We embed parameter search spaces in the definition of configuration schema.
from dataclasses import dataclass
from happy_config import ConfigLoader
from happy_config.typechecking import show_type
from happy_config.param_tuning import with_search_space
@dataclass
class Bar:
s: str
@dataclass
class Foo:
y: int
bar: Bar
x: float = with_search_space(1.0, space_type='uniform', space_value=[0.0, 1.0])
@dataclass
class Config:
foo: Foo
i: int = with_search_space(0, space_type='choice', space_value=[1, 2, 3])
Save the file in main.py
. And in CLI:
python -m happy_config genspace -m main.Config -o search_space.json
The outputed search_space.json
file:
{
"foo:x": {
"_type": "uniform",
"_value": [
0.0,
1.0
]
},
"i": {
"_type": "choice",
"_value": [
1,
2,
3
]
}
}
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
Built Distribution
File details
Details for the file happy_config-0.0.4.tar.gz
.
File metadata
- Download URL: happy_config-0.0.4.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 648c76ee0e5e6eb5fa997f4b46f8d4573d3b655c1d33f9b2767864deeb57c17d |
|
MD5 | 5703102fe6932f13b780b7e8655cb420 |
|
BLAKE2b-256 | a0d0fa10e7226ba10ca3ad58441e631b663df56b857368029a290b224c0e7497 |
File details
Details for the file happy_config-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: happy_config-0.0.4-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36f2c3eae9547149500022d543713ab05fbd22b9f3589db170c1aa58909d33bb |
|
MD5 | bca3d81166ecaecc9698a3f61d3f61a1 |
|
BLAKE2b-256 | 0ea455d90600f3c05c3e218d3437c5a260636e11277cefadccace148d6e0ccf7 |