Introduction to Hypster#
Hypster
is a lightweight configuration system for AI & Machine Learning projects.
It offers minimal, intuitive pythonic syntax, supporting hierarchical and swappable configurations.
Key Benefits#
🐍 Pythonic API for a familiar and expressive logic
✨ Separating configuration from execution logic for cleaner & modular code
🦥 “Lazy” instantiation for serialization in production settings
🧹
Combinations
API for Hyperparameter “Sweeps”
Installation#
You can install Hypster via pip
:
pip install hypster
This will install everything you need to use Hypster in your Python projects.
Basic Usage#
Let’s start with a simple example to demonstrate how Hypster works:
from hypster import HP, config
@config
def my_config(hp: HP):
# All imports should be inside the function
import os
chunking_strategy = hp.select(["paragraph", "semantic", "fixed"], default="paragraph")
llm_model = hp.select(
{"haiku": "claude-3-haiku-20240307", "sonnet": "claude-3-5-sonnet-20240620", "gpt-4o-mini": "gpt-4o-mini"},
default="gpt-4o-mini",
)
provider = "ANTHROPIC" if llm_model.startswith("claude") else "OPENAI"
api_key_exists = f"{provider}_API_KEY" in os.environ
llm_config = {"temperature": hp.number(0), "max_tokens": hp.number(64)}
system_prompt = hp.text("You are a helpful assistant. Answer with one word only")
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from hypster import HP, config
4 @config
5 def my_config(hp: HP):
6 # All imports should be inside the function
7 import os
ModuleNotFoundError: No module named 'hypster'
Now we can instantiate the configs with our selections and overrides:
results = my_config(
final_vars=["chunking_strategy", "llm_config", "llm_model"],
selections={"llm_model": "haiku"},
overrides={"llm_config.temperature": 0.5},
) # nested parameter name
results
{'chunking_strategy': 'paragraph',
'llm_config': {'temperature': 0, 'max_tokens': 64},
'llm_model': 'claude-3-haiku-20240307'}
In this example:
We imported
HP
andconfig
from Hypster.We defined a configuration function decorated with
@config
.Inside the function, we used
hp.select
,hp.number
&hp.text
to lazily select hyperparameters.We instantiated the configuration space and displayed the results.
Important Note: All imports must be defined within the function scope in order for Hypster to work correctly. Working this way the allows for easy portability and deployment in different environments.
Important Note #2: No return statement is needed for @config functions. I can lazily select the final variables (final_var) when we instantiate our configuration.