๐Ÿš€Defining of A Config Function

A hypster config function is the heart of this framework. It requires of 3 main components:

1

Imports

from hypster import config, HP

This makes sure we have the @config decorater and HP class for type annotation.

2

Signature

@config
def my_config(hp: HP):

The function definition consists of the @config decorator and the signature. Including the HP (HyperParameter) type hint will enable IDE features like code suggestions and type checking.

3

Body

@config
def my_config(hp: HP):
    from package import Class

    var = hp.select(["a", "b", "c"], default="a")
    num = hp.number(10)
    text = hp.text("Hey!")

    instance = Class(var=var, num=num, text=text)

Hypster comes with the following HP calls:

Please note:

No return statement is allowed (nor needed). This enables selecting the variables we want to retrieve upon instantiation using final_vars and exclude_vars

4

Instantiation

Now that we've created a configuration space/function - we can instantiate it using:

my_config(final_vars=["instance"], values={"var" : "b"})

Congratulations! ๐ŸŽ‰ You've created and instantiated your first Hypster config.

Saving & Loading Config Functions

Save configurations to reuse them across projects:

# Save directly from config function
my_config.save("configs/my_config.py") # Creates directories if needed

# Save using hypster.save
from hypster import save
save(my_config, "configs/nested/my_config.py")

Loading Configurations

Load saved configurations in two ways:

# Method 1: Direct loading
from hypster import load
my_config = load("configs/my_config.py")

# Method 2: Load for nesting
@config
def parent_config(hp: HP):
    nested_config = hp.nest("configs/my_config.py")

Last updated

Was this helpful?