Hyperparameter Sweeps
Hyperparameter sweeps are essential for finding optimal configurations in machine learning and experimentation. This
guide shows you how to perform systematic parameter searches using params-proto. Simply wrap the configuration class
or the cli entrypoint function with the Sweep class:
Looking for a lighter alternative? Check out
piterfor a dictionary-based approach with the cleanpiter @ {...}syntax and operator composition (*,%,**).
Sweep Operators Reference
The Sweep class provides several operators for combining parameter configurations:
| Operator | Behavior | Example | Result |
|---|---|---|---|
sweep.product | Cartesian product of all parameter lists | lr=[0.001, 0.01]batch=[32, 64] | 4 configs:(0.001, 32), (0.001, 64)(0.01, 32), (0.01, 64) |
sweep.zip | Zip parameter lists element-wise | lr=[0.001, 0.01]batch=[32, 64] | 2 configs:(0.001, 32), (0.01, 64) |
sweep.chain | Concatenate multiple sweep configurations | Two sweeps with 15 configs each | 30 configs total (concatenated) |
sweep.set | Set fixed values for parameters | seed=42 in outer scope | All configs inherit seed=42 |
sweep.each(fn) | Apply function to each config (for derived params) | fn computes postfix from seed | Dynamic parameter computation |
Combining Operators
Operators can be nested to create complex sweep patterns:
Advanced: Dynamic Parameters with .each()
Use .each() to compute parameters that depend on other sweep values:
Utility Methods
The Sweep class also provides utility methods for managing and persisting sweep configurations:
| Method | Description | Example Usage |
|---|---|---|
sweep.save(filename, overwrite=True) | Save sweep configs to JSONL file | sweep.save("experiments.jsonl") |
Sweep.read(filename) | Read JSONL file into list of dicts | configs = Sweep.read("experiments.jsonl") |
sweep.load(file, strict=True) | Load sweep from JSONL file or list | sweep.load("experiments.jsonl") |
Sweep.log(deps, filename) | Append single config to JSONL file | Sweep.log(config, "results.jsonl") |
sweep.list | Convert sweep to list of config dicts | all_configs = sweep.list |
sweep.dataframe | Convert sweep to pandas DataFrame | df = sweep.dataframe |
sweep[index] | Index or slice into sweep configs | sweep[0], sweep[:10], sweep[::2] |
Example: Save and Load Sweeps
Example: Using DataFrame for Analysis
Related
- Core Concepts - Decorators and basic usage
- Configuration Patterns - Function vs class configurations
- Parameter Overrides - Override methods and context managers
- Parameter Iteration - Lightweight sweeps with piter
Advanced Patterns- Prefixes and composition