Skip to content
Draft
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
10 changes: 9 additions & 1 deletion specforge/training/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,15 @@ def _logger(metrics, step):


def _configured_logger(cfg: Config):
"""Create an external tracker only for a trainer-bearing run."""
"""Create an external tracker only on the trainer's global rank zero."""
if cfg.training.role != "producer":
import torch.distributed as dist

# A distributed run has one logical metric stream. Letting every rank
# create W&B/MLflow runs or write the same TensorBoard directory both
# duplicates metrics and makes large jobs increasingly fragile.
if dist.is_available() and dist.is_initialized() and dist.get_rank() != 0:
return None
if cfg.tracking.report_to == "none" or cfg.training.role == "producer":
return _logger

Expand Down
9 changes: 9 additions & 0 deletions tests/test_config/test_unified_feature_reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ def test_tracking_config_reaches_the_existing_tracker_adapter(self):
self.assertEqual(output_dir, "/tmp/output")
self.assertIs(create.call_args.kwargs["console_logger"], _logger)

def test_only_global_rank_zero_creates_a_training_logger(self):
cfg = Config.model_validate(OFFLINE_EAGLE3)
with (
mock.patch("torch.distributed.is_available", return_value=True),
mock.patch("torch.distributed.is_initialized", return_value=True),
mock.patch("torch.distributed.get_rank", return_value=3),
):
self.assertIsNone(_configured_logger(cfg))

def test_tracking_backend_is_strictly_typed(self):
with self.assertRaises(ValidationError):
Config.model_validate(
Expand Down
Loading