Skip to content

Commit

Permalink
Add run name option for wandb (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
uralik authored Oct 23, 2024
1 parent 822bc1a commit 993784c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/fairseq2/metrics/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def close(self) -> None:
class WandbRecorder(MetricRecorder):
"""Records metric values to Weights & Biases."""

def __init__(self, project: str, output_dir: Path) -> None:
def __init__(self, project: str, name: str, output_dir: Path) -> None:
"""
:param project: The W&B project name.
:param output_dir: The base directory under which to store the W&B files.
Expand All @@ -502,7 +502,9 @@ def __init__(self, project: str, output_dir: Path) -> None:

self._run = None
else:
self._run = wandb.init(project=project, dir=output_dir.parent)
self._run = wandb.init(
project=project, name=name, dir=output_dir.parent, resume="allow"
)

@override
def record_metrics(
Expand Down
3 changes: 2 additions & 1 deletion src/fairseq2/recipes/legacy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def set_score_config() -> None:

def set_metric_recorders_config() -> None:
wandb_project = getattr(config, "wandb_project", None)
wandb_run_name = getattr(config, "wandb_run_name", None)

if wandb_project is not None:
config_dict["metric_recorders"] = MetricRecordersConfig(
wandb=True, wandb_project=wandb_project
wandb=True, wandb_project=wandb_project, wandb_run_name=wandb_run_name
)

set_gang_config()
Expand Down
3 changes: 3 additions & 0 deletions src/fairseq2/recipes/lm/instruction_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class InstructionFinetuneConfig:
wandb_project: str | None = None
"""If not ``None``, sets the project name for W&B logging."""

wandb_run_name: str | None = None
"""If not ``None``, sets the run name for W&B logging. If None, then W&B creates a random name."""


instruction_finetune_presets = ConfigRegistry[InstructionFinetuneConfig]()

Expand Down
3 changes: 3 additions & 0 deletions src/fairseq2/recipes/lm/preference_finetune/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class PreferenceFinetuneConfig:
wandb_project: str | None = None
"""If not ``None``, sets the project name for W&B logging."""

wandb_run_name: str | None = None
"""If not ``None``, sets the run name for W&B logging. If None, then W&B creates a random name."""


preference_finetune_presets = ConfigRegistry[PreferenceFinetuneConfig]()

Expand Down
3 changes: 2 additions & 1 deletion src/fairseq2/recipes/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MetricRecordersConfig:
tensorboard: bool = True
wandb: bool = False
wandb_project: str | None = None
wandb_run_name: str | None = None


def register_metric_recorders(container: DependencyContainer) -> None:
Expand Down Expand Up @@ -113,4 +114,4 @@ def _create_wandb_recorder(resolver: DependencyResolver) -> MetricRecorder | Non

output_dir = config_manager.get_config("output_dir", Path).joinpath("wandb")

return WandbRecorder(config.wandb_project, output_dir)
return WandbRecorder(config.wandb_project, config.wandb_run_name, output_dir)

0 comments on commit 993784c

Please sign in to comment.