Happy Config
Managing ML experiment configuration with joy.
- Use
dataclassto 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
]
}
}
Metadata
Release files for happy-config 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| happy_config-0.0.4.tar.gz | 7.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| happy_config-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / happy_config-0.0.4.tar.gz
| Download URL | happy_config-0.0.4.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
648c76ee0e5e6eb5fa997f4b46f8d4573d3b655c1d33f9b2767864deeb57c17d
|
|
BLAKE2b-256 checksum How to use checksums |
a0d0fa10e7226ba10ca3ad58441e631b663df56b857368029a290b224c0e7497
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / happy_config-0.0.4-py3-none-any.whl
| Download URL | happy_config-0.0.4-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36f2c3eae9547149500022d543713ab05fbd22b9f3589db170c1aa58909d33bb
|
|
BLAKE2b-256 checksum How to use checksums |
0ea455d90600f3c05c3e218d3437c5a260636e11277cefadccace148d6e0ccf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for happy-config 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.