Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Hyperparameter optimization framework (Optuna). Define-by-run API with automatic search space construction, state-of-the-art samplers (TPE, CMA-ES, NSGA-II, GPSampler), efficient pruning (Median, Hyperband, ASHA), multi-objective optimization, constrained optimization, distributed parallel execution, and visualization dashboard. Integrates with PyTorch, PyTorch Lightning, TensorFlow, Keras, XGBoost, LightGBM, CatBoost, MLflow, W&B, and scikit-learn.
.claude/skills/mkurman-optuna/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 60% | 0% |
| case-18 | ✓→✓ | = Same ✓ | 269% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 165% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 133% | 0% |
---|----------|-------------| | TPESampler | General ML tuning | Tree-structured Parzen Estimator; default, good for most cases | | CMAESSampler | Continuous, low-dim (<100) | Covariance Matrix Adaptation; efficient for numeric params | | NSGAIISampler | Multi-objective (2-3 objectives) | Pareto-front optimization | | GPSampler | Expensive evaluations | Gaussian Process-based; sample-efficient | | RandomSampler | Baseline, debugging | Uniform random sampling | | GridSampler | Small discrete spaces | Exhaustive grid search | | QMCSampler | Continuous spaces | Quasi-Monte Carlo, better coverage than random |
Usage:
pythonimport optuna sampler = optuna.samplers.TPESampler(seed=42, n_startup_trials=10) study = optuna.create_study(sampler=sampler)
Stop unpromising trials early to save compute:
pythondef objective(trial): for epoch in range(100): accuracy = train_and_evaluate(...) # Report intermediate value trial.report(accuracy, epoch) # Check if should prune if trial.should_prune(): raise optuna.TrialPruned() return accuracy
Pruner Selection:
MedianPruner: Prune if trial's intermediate value is below median at same stepHyperbandPruner: Successive halving; efficient for large trial countsSuccessiveHalvingPruner: Similar to Hyperband, simpler configurationThresholdPruner: Prune below absolute thresholdPatientPruner: Prune after N epochs without improvementIntegration with PyTorch Lightning:
pythonfrom optuna.integration import PyTorchLightningPruningCallback trainer = pl.Trainer( callbacks=[PyTorchLightningPruningCallback(trial, monitor="val_acc")], max_epochs=100, )
pythondef objective(trial): accuracy = train_and_get_accuracy(trial) latency_ms = measure_latency(trial) return accuracy, latency_ms # Return tuple study = optuna.create_study( directions=["maximize", "minimize"], sampler=optuna.samplers.NSGAIISampler(), ) study.optimize(objective, n_trials=200) # Get Pareto front best_trials = study.best_trials for trial in best_trials: print(f"Params: {trial.params}, Values: {trial.values}")
Single-machine multi-process:
pythonstudy.optimize(objective, n_trials=100, n_jobs=8) # 8 parallel workers
Multi-node via shared storage (SQLite):
python# On all nodes, share the same study name and storage study = optuna.create_study( study_name="distributed_study", storage="sqlite:///optuna_study.db", load_if_exists=True, ) study.optimize(objective, n_trials=500)
Multi-node via RDB (PostgreSQL/MySQL):
pythonstudy = optuna.create_study( study_name="large_scale_study", storage="postgresql://user:pass@host:5432/optuna", load_if_exists=True, )
pythonfrom optuna.visualization import ( plot_optimization_history, plot_param_importances, plot_parallel_coordinate, plot_contour, plot_slice, ) # Optimization progress over trials plot_optimization_history(study) # Hyperparameter importance ranking plot_param_importances(study) # Parallel coordinate plot for high-dimensional analysis plot_parallel_coordinate(study) # Slice plot showing parameter-value relationship plot_slice(study) # Contour plot for pairwise parameter interactions plot_contour(study, params=["learning_rate", "n_layers"])
Web Dashboard (optuna-dashboard):
bashpip install optuna-dashboard optuna-dashboard sqlite:///optuna_study.db # Opens at http://localhost:8080
pythonimport pytorch_lightning as pl import optuna from optuna.integration import PyTorchLightningPruningCallback def objective(trial): # Suggest hyperparameters lr = trial.suggest_float("lr", 1e-5, 1e-1, log=True) batch_size = trial.suggest_categorical("batch_size", [32, 64, 128, 256]) n_layers = trial.suggest_int("n_layers", 1, 6) model = MyLightningModule(lr=lr, n_layers=n_layers) trainer = pl.Trainer( max_epochs=50, callbacks=[PyTorchLightningPruningCallback(trial, monitor="val_loss")], logger=False, ) trainer.fit(model, train_dataloaders=train_loader, val_dataloaders=val_loader) return trainer.callback_metrics["val_loss"].item() study = optuna.create_study(direction="minimize") study.optimize(objective, n_trials=50)
pythonfrom transformers import Trainer, TrainingArguments import optuna def hp_space(trial): return { "learning_rate": trial.suggest_float("learning_rate", 1e-6, 1e-4, log=True), "per_device_train_batch_size": trial.suggest_categorical("batch_size", [8, 16, 32]), "num_train_epochs": trial.suggest_int("num_epochs", 1, 5), "warmup_ratio": trial.suggest_float("warmup_ratio", 0.0, 0.3), } trainer = Trainer( model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset, ) best_run = trainer.hyperparameter_search( hp_space=hp_space, n_trials=30, direction="minimize", )
pythondef objective(trial): model = train_model(trial) # Store arbitrary attributes trial.set_user_attr("model_architecture", str(model)) trial.set_user_attr("training_time_seconds", 3600) return evaluate(model) # Retrieve later for trial in study.trials: print(trial.user_attrs.get("training_time_seconds"))
bashpip install optuna # Optional: dashboard pip install optuna-dashboard # Optional: OptunaHub features pip install optunahub
log=True for learning rates, batch sizes, and other scale-sensitive paramsn_startup_trials to 10-20 for TPE to warm up with random explorationseed on both sampler and study.optimize()trial.report() even if not pruning — enables better analysisSee scripts/optuna_lightning_template.py for a complete PyTorch Lightning + Optuna training template. See references/advanced_samplers.md for detailed sampler comparison and selection guidance.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-19 | fail→fail | 10,634 | 7,043 | -34% | 1 | 1 | 0% | 2,024 | 3,220 | +59% | 0 | 0 | — |
case-01 | fail→pass | 16,310 | 14,631 | -10% | 1 | 1 | 0% | 3,349 | 4,815 | +44% | 0 | 0 | — |
case-18 | pass→pass | 4,028 | 3,606 | -10% | 1 | 1 | 0% | 699 | 2,580 | +269% | 0 | 0 | — |
case-02 | pass→pass | 5,351 | 3,385 | -37% | 1 | 1 | 0% | 947 | 2,509 | +165% | 0 | 0 | — |
case-03 | pass→pass | 7,148 | 5,284 | -26% | 1 | 1 | 0% | 1,240 | 2,895 | +133% | 0 | 0 | — |
case-04 | fail→pass | 15,019 | 11,651 | -22% | 1 | 1 | 0% | 2,492 | 3,983 | +60% | 0 | 0 | — |
case-05 | pass→pass | 7,700 | 8,112 | +5% | 1 | 1 | 0% | 1,367 | 3,537 | +159% | 0 | 0 | — |
case-06 | pass→pass | 12,280 | 13,913 | +13% | 1 | 1 | 0% | 2,560 | 4,891 | +91% | 0 | 0 | — |
case-07 | pass→pass | 3,891 | 2,803 | -28% | 1 | 1 | 0% | 692 | 2,413 | +249% | 0 | 0 | — |
case-08 | pass→pass | 11,309 | 9,080 | -20% | 1 | 1 | 0% | 2,351 | 3,806 | +62% | 0 | 0 | — |
case-09 | pass→pass | 6,966 | 4,955 | -29% | 1 | 1 | 0% | 1,339 | 2,992 | +123% | 0 | 0 | — |
case-10 | pass→pass | 8,094 | 6,643 | -18% | 1 | 1 | 0% | 1,470 | 3,183 | +117% | 0 | 0 | — |
case-11 | pass→pass | 8,988 | 4,565 | -49% | 1 | 1 | 0% | 1,618 | 2,730 | +69% | 0 | 0 | — |
case-12 | pass→pass | 8,076 | 4,169 | -48% | 1 | 1 | 0% | 1,503 | 2,715 | +81% | 0 | 0 | — |
case-13 | pass→pass | 3,380 | 3,074 | -9% | 1 | 1 | 0% | 567 | 2,473 | +336% | 0 | 0 | — |
case-14 | pass→pass | 8,345 | 4,431 | -47% | 1 | 1 | 0% | 1,531 | 2,752 | +80% | 0 | 0 | — |
case-15 | pass→pass | 2,771 | 2,614 | -6% | 1 | 1 | 0% | 452 | 2,355 | +421% | 0 | 0 | — |
case-16 | pass→pass | 3,968 | 3,291 | -17% | 1 | 1 | 0% | 681 | 2,543 | +273% | 0 | 0 | — |
case-17 | pass→pass | 5,308 | 3,661 | -31% | 1 | 1 | 0% | 966 | 2,633 | +173% | 0 | 0 | — |
case-20 | pass→pass | 6,323 | 6,250 | -1% | 1 | 1 | 0% | 1,298 | 3,079 | +137% | 0 | 0 | — |
case-21 | pass→pass | 13,766 | 17,169 | +25% | 1 | 1 | 0% | 2,742 | 5,364 | +96% | 0 | 0 | — |
case-22 | fail→fail | 11,332 | 11,055 | -2% | 1 | 1 | 0% | 2,308 | 4,298 | +86% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.