Skip to main content

A flexible configuration system for Python projects

Project description

Hypster Logo

chat with our AI docs

CI codecov PyPI version Python versions Docs DeepWiki License: MIT CodSpeed

Hypster is a lightweight configuration framework for optimizing AI & ML workflows

[!WARNING]

Hypster is in active development and not yet battle-tested in production.

If you’re gaining value and want to promote it to production, please reach out!

Key Features

  • :snake: Pythonic API: Intuitive & minimal syntax that feels natural to Python developers
  • :nesting_dolls: Hierarchical, Conditional Configurations: Support for nested and swappable configurations
  • :triangular_ruler: Type Safety: Built-in type hints and validation
  • :test_tube: Hyperparameter Optimization Built-In: Native, first-class optuna support

Installation

You can install Hypster using uv:

uv add hypster
# optional HPO backend
uv add 'hypster[optuna]'

Or using pip:

pip install hypster

Quick Start

Define a configuration function and instantiate it with overrides:

from hypster import HP, instantiate
from llm import LLM

def llm_config(hp: HP):
    model_name = hp.select(["gpt-4o-mini", "gpt-4o"], name="model_name")
    temperature = hp.float(0.7, name="temperature", min=0.0, max=1.0)
    max_tokens = hp.int(256, name="max_tokens", min=1, max=4096)
    llm = LLM(model_name=model_name, temperature=temperature, max_tokens=max_tokens)
    return llm

llm = instantiate(llm_config, values={"model_name": "gpt-4o-mini", "temperature": 0.3})
llm.invoke("How's your day going?")

HPO with Optuna

import optuna
from hypster.hpo.types import HpoInt, HpoFloat, HpoCategorical
from hypster.hpo.optuna import suggest_values


def objective(trial: optuna.Trial) -> float:
    values = suggest_values(trial, config=model_cfg)
    model = instantiate(model_cfg, values=values)
    X, y = make_classification(
        n_samples=400, n_features=20, n_informative=10, random_state=42
    )
    return cross_val_score(model, X, y, cv=3, n_jobs=-1).mean()

study = optuna.create_study(direction="maximize")
study.optimize(objective, n_trials=30)

Inspiration

Hypster draws inspiration from Meta's hydra and hydra-zen framework. The API design is influenced by Optuna's "define-by-run" API.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

hypster-0.3.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypster-0.3.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file hypster-0.3.2.tar.gz.

File metadata

  • Download URL: hypster-0.3.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for hypster-0.3.2.tar.gz
Algorithm Hash digest
SHA256 69afcc6f8a7683d49d0765eb31d0ed893cc79f4253ec1abc3132581892481d89
MD5 9ca94a3afd57cba7152e11ba755ee06e
BLAKE2b-256 c36a3910bf3695136fc54741e6b5904b01a591a5787f2719a8b4a2521a1b07e7

See more details on using hashes here.

File details

Details for the file hypster-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: hypster-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for hypster-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7cfbe7d91d1979729cbca64bc3471ab084f15fe270b827189490076a38fc576a
MD5 be5cc195a341cd2e29579f1fd15fb82e
BLAKE2b-256 4b79948aa04cd11b24d3798fd89917e091167e9383cc4776b6f23a439deb588d

See more details on using hashes here.

Supported by

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