Skip to content

Add join sweep method #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sparse_autoencoder/train/join_sweep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Join an existing Weights and Biases sweep, as a new agent."""
import argparse

from sparse_autoencoder.train.sweep import sweep


def parse_arguments() -> argparse.Namespace:
"""Parse command line arguments.

Returns:
argparse.Namespace: Parsed command line arguments.
"""
parser = argparse.ArgumentParser(description="Join an existing W&B sweep.")
parser.add_argument(
"--id", type=str, default=None, help="Sweep ID for the existing sweep.", required=True
)
return parser.parse_args()


if __name__ == "__main__":
args = parse_arguments()

sweep(sweep_id=args.id)
27 changes: 23 additions & 4 deletions sparse_autoencoder/train/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,28 @@ def train() -> None:
sys.exit(1)


def sweep(sweep_config: SweepConfig) -> None:
"""Main function to run the training pipeline with wandb hyperparameter sweep."""
sweep_id = wandb.sweep(sweep_config.to_dict(), project="sparse-autoencoder")
def sweep(sweep_config: SweepConfig | None = None, sweep_id: str | None = None) -> None:
"""Run the training pipeline with wandb hyperparameter sweep.

Warning:
Either sweep_config or sweep_id must be specified, but not both.

Args:
sweep_config: The sweep configuration.
sweep_id: The sweep id for an existing sweep.

Raises:
ValueError: If neither sweep_config nor sweep_id is specified.
"""
if sweep_id is not None:
wandb.agent(sweep_id, train, project="sparse-autoencoder")

elif sweep_config is not None:
sweep_id = wandb.sweep(sweep_config.to_dict(), project="sparse-autoencoder")
wandb.agent(sweep_id, train)

else:
error_message = "Either sweep_config or sweep_id must be specified."
raise ValueError(error_message)

wandb.agent(sweep_id, train)
wandb.finish()