Skip to main content

PhaseSweep

PhaseSweep runs phase-chained hyperparameter sweeps from one ordinary YAML file. That file contains your trainer configuration, the metric, and the search plan. PhaseSweep materializes the configured trainer input for every trial, decides what to try next, persists each phase winner, and carries selected values forward as fixed inputs to later phases.

This is useful when a full joint sweep is too expensive or hard to interpret. For example, choose architecture depth, then tune learning rate, then regularization. The configuration guide explains the inheritance model and its tradeoffs.

PhaseSweep phase DAG

How it works

The starter generated by phasesweep init searches depth before learning rate (abridged; the full file also sets storage, the working directory, and the metric extractor):

experiment: phasesweep_starter

# The trainer receives one complete generated YAML per trial.
trial_command: "python -m phasesweep.examples.fake_train --config {config_path}"

trainer_config:
  model:
    n_layers: 8
    dropout: 0.1
  optimizer:
    lr: 0.0003
    weight_decay: 0.05

metric:
  name: eval_loss
  goal: minimize

phases:
  - name: depth
    n_trials: 2
    sampler: { type: grid }
    search_space:
      model.n_layers: { type: categorical, choices: [6, 8] }

  - name: learning_rate
    inherits: [depth] # the winning model.n_layers is fixed here
    n_trials: 2
    sampler: { type: grid }
    search_space:
      optimizer.lr: { type: categorical, choices: [0.0001, 0.0003] }

The packaged fake trainer uses the optional report_objective(...) envelope helper. Your own trainer can report through W&B, ordinary JSON, or logs without importing PhaseSweep.

Install and try it

Requirements: Python 3.11+ and a POSIX host for real runs. GPUs are optional.

python -m pip install phasesweep
phasesweep --version

mkdir phasesweep-demo && cd phasesweep-demo
phasesweep init                       # writes the starter experiment.yaml
phasesweep validate experiment.yaml   # checks it without launching anything
phasesweep run experiment.yaml        # four tiny trials, a few seconds

phasesweep init never overwrites an existing file; use -o PATH for another destination.

The run log shows the phase chaining directly (abridged):

[depth/trial_0] python -m phasesweep.examples.fake_train --config .../trainer_config.yaml
[depth/trial_1] python -m phasesweep.examples.fake_train --config .../trainer_config.yaml
phase=depth WINNER trial=0 metric=0.3 params={'model.n_layers': 8}
[learning_rate/trial_0] python -m phasesweep.examples.fake_train --config .../trainer_config.yaml
[learning_rate/trial_1] python -m phasesweep.examples.fake_train --config .../trainer_config.yaml
phase=learning_rate WINNER trial=0 metric=0.3 params={'optimizer.lr': 0.0003}

The depth winner's model.n_layers: 8 is injected into every learning_rate trial's complete YAML. Winners persist in the working directory, so you can inspect them any time (abridged):

phasesweep show-winners experiment.yaml
phase: learning_rate
metric:
  eval_loss: 0.3
  goal: minimize
trial_number: 0
params:
  optimizer.lr: 0.0003
effective_overrides:
  model.n_layers: 8
  optimizer.lr: 0.0003
# ... completion state, fingerprints, objective provenance, and confound
# verdicts on the ranked population follow

The starter uses storage: auto, so its ledger and outputs live together under <workdir>/<experiment>/. The ledger is an Optuna journal: phasesweep status prints its path, and Optuna's own CLI and dashboard can read it. See runtime behavior for state layout, current-format requirements, locks, cleanup, GPU isolation, and resume.

Use your own trainer

Choose the input interface your trainer already accepts:

Input Command placeholder
Complete base-plus-overrides YAML (yaml_file, default) --config {config_path}
Command-line flags (argparse) {overrides} produces --key=value
Native Hydra overrides (hydra) {overrides} produces key=value
Nested overrides-only JSON (json_file) --overrides {overrides_path}

For ordinary JSON output, pass an output path under {trial_dir} to your trainer and select it with extractor: {type: json, path: result.json, key: eval.loss}. For W&B, use extractor: {type: wandb, entity: YOUR_ENTITY, project: YOUR_PROJECT, metric_key: eval/loss}, have the trainer honor the supplied W&B identity, and install the extra:

python -m pip install "phasesweep[wandb]"

metric.goal ranks each trial's selected scalar. Log matching selects the last observation by default; W&B selects an exact finished-summary key. The trainer owns evaluation, early stopping, checkpoint selection, and aggregation. Inheritance transfers parameters, not model weights.

See the configuration guide for input types, reporting, credentials, and selection details. The Tiny Decoder Enwik8 example is a complete real-trainer integration.

Connect an agent

The optional MCP server connects an AI agent to experiments you have approved without exposing config or storage paths, trainer commands, environment values, or raw logs. Sampled winner values follow the catalog's visible_params policy. Follow the MCP setup to install the extra, review the catalog authority boundary, configure a client-owned connection, and verify the result.

Reference

Ask DeepWiki

License

MIT. See LICENSE.

Metadata

Release files for phasesweep 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phasesweep 0.3.6
File Size Uploaded
phasesweep-0.3.6.tar.gz 2.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for phasesweep 0.3.6
File Interpreter ABI Platform
phasesweep-0.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 2.7 MB

Release files / phasesweep-0.3.6.tar.gz

Download URL phasesweep-0.3.6.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
96f6f552ab2d2f8434c245721c1d0ed2d8780f6ccfb3c621d898251b99ffe309
BLAKE2b-256 checksum
How to use checksums
630172e20a2465afdbada7e2f311abb865ee9d37da5f5dfdc9ba3f53039b37b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / phasesweep-0.3.6-py3-none-any.whl

Download URL phasesweep-0.3.6-py3-none-any.whl
Size 431.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95078b9d9b33ad2e1ff493570123ee1916e58ce879b3968c0116066a1a1e2627
BLAKE2b-256 checksum
How to use checksums
e8643f9c9dd6a97fc08e9234a7ea80d13f099cc425144a09d4ea458ac6f5d016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.8

2 release files

0.3.7

2 release files

This release

0.3.6 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page