Skip to main content

A hyper-parameter library for researchers, data scientists and machine learning engineers.

Project description

Hyperparameter

ENGLISH | 中文文档

Hyperparameter, Make configurable AI applications.Build for Python hackers.

Quick Start

Hyperparameter uses auto _ param decorator to convert keywords arguments into configurable parameters:

from hyperparameter import auto_param

@auto_param("foo")
def foo(x, y=1, z="a"):
    return f"x={x}, y={y}, z={z}"

The parameters can be controlled with param_scope

from hyperparameter import param_scope

foo(1) # x=1, y=1, z='a'
with param_scope(**{"foo.y":2}):
    foo(1) # x=1, y=2, z='a'

Advanced Usage

Read/Write Parameters

from hyperparameter import param_scope

# create param_scope
with param_scope():
    pass

with param_scope("foo.y=1", "foo.z=b"):
    pass

with param_scope(**{"foo.y":1, "foo.z":2}):
    pass

# read param with default value
with param_scope(**{"foo.y":2}) as ps:
    y = ps.foo.y(1)  
    y = ps.foo.y | 1
    y = param_scope.foo.y(1)
    y = param_scope.foo.y | 1
    foo(1) # x=1, y=2, z='a'

# wite values to param_scope
with param_scope(**{"foo.y":2}) as ps:
    ps.foo.y = 2
    param_scope.foo.y = 2

Nested Scope

Hyperparameter support nested param_scope:

from hyperparameter import param_scope

# no param_scope, use the default value defined in foo
foo(1) # x=1, y=1, z='a'

# start a new param_scope
# and set the default value of `foo.y` to `2`
with param_scope(**{"foo.y":2}) as ps:
    # found one param_scope `ps`, 
    # and receive default value of `foo.y` from `ps`
    foo(1) # x=1, y=2, z='a'

    # start another param_scope
    # and set the default value of `foo.y` to `3`
    with param_scope(**{"foo.z": "b"}) as ps2:
        # found nested param_scope `ps2`, 
        # and receive default values of `foo.z` from `ps2`
        foo(1) # x=1, y=2, z='b'
    # `ps2` ends here, and `foo.y` is restored to `2`
    foo(1) # x=1, y=2, z='a'
# `ps` ends here, and `foo.y` is restored to `1`
foo(1) # x=1, y=1, z='a'

CMD Line Arguments

An example CLI app:

from hyperparameter import param_scope, auto_param

@auto_param
def main(a=0, b=1): # `inline default values`
    print(a, b)

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()

    parser.add_argument("-D", "--define", nargs="*", default=[], action="extend")
    args = parser.parse_args()

    with param_scope(*args.define):
        main()

Examples

parameter tunning for researchers

This example shows how to use hyperparameter in your research projects, and make your experiments reproducible.

experiment tracing for data scientists

This example shows experiment management with hyperparameter, and tracing the results with mlflow.tracing.

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

hyperparameter-0.5.6.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

hyperparameter-0.5.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

File details

Details for the file hyperparameter-0.5.6.tar.gz.

File metadata

  • Download URL: hyperparameter-0.5.6.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for hyperparameter-0.5.6.tar.gz
Algorithm Hash digest
SHA256 ed83c545e59e780a9a73d58b73f3a978dd0c519db5fe04027e7f7b5a7e0934b2
MD5 880d6745f34f177fb40e14aa02d175eb
BLAKE2b-256 d827fe4555fe449bfa871525519b605ba6e4c034df3f3e71c8b91f64f2bc4437

See more details on using hashes here.

File details

Details for the file hyperparameter-0.5.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hyperparameter-0.5.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de17e8fce6f0fab47242f05b7660b4179f75ee196f8f33033d74074fb4d04922
MD5 2359e31ca2e4440c55f06651d0cbbfdc
BLAKE2b-256 40427f9ff03c1b53112b40e9bd3da556443e5237dd47016c5ee4b06a05e197ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page