Hyperparameter Sweeps
Automatically search for the best hyperparameters.Quick Start
Python API
Parameters
Search Spaces
Default Search Space
By default, sweeps search over:- Learning rate: 1e-5 to 1e-3 (log uniform)
- Batch size: 2, 4, 8, 16 (categorical)
- Warmup ratio: 0.0 to 0.2 (uniform)
LoRA rank is NOT included in the default sweep. Add it manually via
sweep_params if needed.Custom Search Space
Thesweep_params parameter expects a JSON string. Both list and dict formats are supported:
Sweep Backends
Optuna
Efficient Bayesian optimization:Grid Search
Exhaustive search over all combinations:Random Search
Random sampling from search space:Metrics
Standard Metrics
Enhanced Evaluation Metrics
Enableuse_enhanced_eval to access additional metrics:
Enhanced Evaluation Parameters
Standard Benchmarks
Useeval_benchmark to run standard LLM benchmarks:
Custom Metrics Example
Example: Find Best LR
Viewing Results
Optuna Dashboard
W&B Native Sweep Dashboard
By default, sweeps run locally and only log individual runs to W&B. Enable native W&B sweep integration to get aggregated views, parallel coordinates plots, and parameter importance analysis in a dedicated sweep dashboard.Local vs W&B Sweeps: Without
wandb_sweep=True, each trial logs as a separate W&B run. With wandb_sweep=True, all trials are grouped under a single sweep dashboard with unified visualizations.Enabling W&B Sweeps
W&B Sweep Parameters
Continuing an Existing Sweep
To add more trials to an existing sweep instead of creating a new one, pass the sweep ID:Accessing the Sweep Dashboard
- Go to wandb.ai and open your project
- Click the Sweep icon (broom) in the left panel
- Select your sweep from the list
Built-in Visualizations
W&B automatically generates three visualizations:
Each panel has an Edit button to customize axes and behavior.
Using with External W&B Sweep Agents
If you’re running AITraining from an external W&B sweep agent (not AITraining’s built-in sweep), use--wandb-run-id to resume the agent’s run instead of creating a duplicate:
--wandb-run-id is set, AITraining automatically sets WANDB_RESUME=allow so the trainer resumes the specified run instead of creating a new one.
Important Notes
- Requires W&B login: Run
wandb loginbefore using W&B sweeps - Sweep ID is logged: Look for “Created W&B sweep: ” in the logs
- Trials are grouped: Each trial appears as a run with
group={sweep_id}for aggregation - Optuna still manages search: W&B is for visualization only; Optuna/grid/random handles the actual hyperparameter search
Post-Trial Actions
Execute custom actions after each trial completes, such as committing checkpoints to git, sending notifications, or syncing to remote storage.CLI Usage
Environment Variables
The post-trial script receives these environment variables:Example: Git Commit Best Models
Example: Slack Notification
Python API with Callback
For more control, use the Python API with a callback function:TrialInfo Fields
Post-trial actions are non-blocking. If a callback or script fails, a warning is logged but the sweep continues. This ensures that sweep progress isn’t lost due to callback errors.
Best Practices
- Start small - 10-20 trials for initial exploration
- Use early stopping - Stop bad trials early
- Fix what you know - Only sweep uncertain params
- Use validation data - Always have eval split
- Use post-trial scripts - Automate checkpointing or notifications
Next Steps
Evaluation
Evaluate sweep results
LoRA/PEFT
Efficient fine-tuning