πDefining of A Config Function
1
from hypster import HP, instantiate2
def my_config(hp: HP):
...3
from hypster import HP
def model_cfg(hp: HP):
# Categorical choice (list form)
model_name = hp.select(["gpt-5", "claude-sonnet-4-0", "gemini-2.5-flash"], name="model_name")
# Numeric parameters
temperature = hp.float(0.2, name="temperature", min=0.0, max=1.0)
max_tokens = hp.int(256, name="max_tokens", min=0, max=4096)
# Conditional logic
if model_name == "gpt-5":
# Extra knob only for gpt-5
top_p = hp.float(1.0, name="top_p", min=0.1, max=1.0)
return {"model_name": model_name, "temperature": temperature, "max_tokens": max_tokens, "top_p": top_p}
return {"model_name": model_name, "temperature": temperature, "max_tokens": max_tokens}4
from hypster import instantiate
cfg = instantiate(
model_cfg,
values={
"model_name": "gpt-5",
"temperature": 0.5,
"max_tokens": 1024,
},
)
# cfg -> {"model_name": "gpt-5", "temperature": 0.5, "max_tokens": 1024}Last updated
Was this helpful?