Hypster Docs
Github 🌟Contact Us
  • 👋Welcome
  • Getting Started
    • 🖥️Installation
    • 🚀Defining of A Config Function
    • ⚡Instantiating a Config Function
    • 🍡Selecting Output Variables
    • 🎮Interactive Instantiation (UI)
    • 🪄Usage Examples
      • Machine Learning
      • LLM Generation
  • In Depth
    • 🤖Parameter Naming
    • 🍱HP Call Types
      • Selectable Types
      • Numeric Types
      • Boolean Types
      • Textual Types
      • Nested Configurations
    • 🧠Best Practices
Powered by GitBook

Contact & Follow the Author

  • Website
  • LinkedIn
  • Github
  • Medium

© Gilad Rubin 2024

On this page

Was this helpful?

Edit on GitHub
  1. Getting Started

Defining of A Config Function

PreviousInstallationNextInstantiating a Config Function

Last updated 6 months ago

Was this helpful?

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:

  • hp.select() and hp.multi_select() for

  • hp.int() and hp.multi_int() for

  • hp.number()and hp.multi_number() for

  • hp.text() and hp.multi_text() for

  • hp.bool() and hp.multi_bool() for

Please note:

All imports must be defined inside the body of the function. This enables the portability of hypster's configuration object.

No return statement is allowed (nor needed). This enables 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")
🚀
🎉
categorical choices
integer values
numeric values
string values
boolean values
selecting the variables