Skip to main content

Neural network surrogate hyperparameter optimization via a simple decorator

Project description

mloopforml

Neural network surrogate hyperparameter optimization via a simple decorator.

PyPI version Python

Install

pip install mloopforml

Quickstart

import mloopforml as mloop

@mloop.optimize(
    params={"lr": (1e-4, 1e-1), "dropout": (0.0, 0.5)},
    max_iterations=50,
    direction="minimize",   # or "maximize"
    seed=42,
)
def train(lr, dropout):
    # Replace with your actual training loop
    # Return a single float (lower is better when direction="minimize")
    loss = some_model.train(lr=lr, dropout=dropout)
    return loss

result = train()

print(result.best_params)   # {'lr': 0.0042, 'dropout': 0.12}
print(result.best_score)    # 0.237

mloopforml uses M-LOOP's neural network surrogate to propose new parameter combinations. The decorator handles the optimization loop — your function just returns a number.

Parameters

Parameter Type Default Description
params dict[str, (float, float)] required Hyperparameter name → (min, max) bounds
max_iterations int 50 Total number of trials
direction str "minimize" "minimize" or "maximize"
num_training_runs int 1 Bootstrap trials before the NN surrogate activates
seed int | None None Random seed for reproducible runs

Result

Calling the decorated function returns an OptimizeResult:

result.best_params   # dict[str, float] — best parameter combination found
result.best_score    # float — best objective value
result.all_params    # list[dict] — all trial params, in order
result.all_costs     # list[float] — all trial scores (nan for failed trials)

Requirements

  • Python >=3.11
  • numpy >=2.0
  • scipy >=1.15

License

MIT

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

mloopforml-1.0.0.tar.gz (94.8 kB view details)

Uploaded Source

Built Distribution

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

mloopforml-1.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file mloopforml-1.0.0.tar.gz.

File metadata

  • Download URL: mloopforml-1.0.0.tar.gz
  • Upload date:
  • Size: 94.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mloopforml-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eec895510af95d5d51220c42d1d09f450ab02318800a49829183b26388446784
MD5 b53b9ea5b8d7597362e4895e47e41855
BLAKE2b-256 68f88357266a14a634e7adbf4e1763b3b9cd39b0b6dc34f9569becbe6134c98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mloopforml-1.0.0.tar.gz:

Publisher: publish-to-pypi.yml on emv-dev/mloopforml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mloopforml-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mloopforml-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mloopforml-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ecc506321c479811cea56ed83e5efe6616ea97c1db25f457107a065eda7409
MD5 804552f168aa0ec1482119ef1b25fa80
BLAKE2b-256 39f1aac10406f936db728349ce1c339bb2f254ca127592ffed75a4e405c20b6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mloopforml-1.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on emv-dev/mloopforml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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