Skip to content

Commit 7f2f1fc

Browse files
Yunlong Xuchanglan
authored andcommitted
allow additional settings to WandBWriter
GitOrigin-RevId: ba40089
1 parent 7ed5444 commit 7f2f1fc

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

axlearn/common/summary_writer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ class Config(BaseWriter.Config):
402402
# If True, convert any 2D Tensors to wandb.Image before passing to wandb.log.
403403
convert_2d_to_image: bool = False
404404

405+
# Dictionary kwargs to pass to wandb.Settings().
406+
# If None, no additional custom settings will be configured.
407+
wandb_settings_kwargs: Optional[dict[str, Any]] = None
408+
405409
@classmethod
406410
def default_config(cls: Config) -> Config:
407411
cfg = super().default_config()
@@ -444,6 +448,11 @@ def _initialize_run(self):
444448
with fs.open(wandb_file, "w") as f: # pytype: disable=module-attr
445449
f.write(exp_id)
446450

451+
# Build custom settings from configured kwargs
452+
wandb_settings = (
453+
wandb.Settings(**cfg.wandb_settings_kwargs) if cfg.wandb_settings_kwargs else None
454+
)
455+
447456
wandb.init(
448457
id=exp_id,
449458
name=cfg.exp_name,
@@ -456,6 +465,7 @@ def _initialize_run(self):
456465
resume=cfg.resume,
457466
dir=cfg.dir,
458467
group=cfg.group,
468+
settings=wandb_settings,
459469
)
460470

461471
@staticmethod

axlearn/common/summary_writer_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,28 @@ def test_resume(self):
321321
finally:
322322
wandb.finish()
323323

324+
@pytest.mark.skipif(wandb is None, reason="wandb package not installed.")
325+
@pytest.mark.skipif("WANDB_API_KEY" not in os.environ, reason="wandb api key not found.")
326+
def test_wandb_settings_kwargs(self):
327+
with tempfile.TemporaryDirectory() as tempdir:
328+
try:
329+
_: WandBWriter = (
330+
WandBWriter.default_config()
331+
.set(
332+
name="test",
333+
exp_name="wandb-testSettings",
334+
dir=tempdir,
335+
mode="offline",
336+
wandb_settings_kwargs={"silent": True, "disable_code": True},
337+
)
338+
.instantiate(parent=None)
339+
)
340+
# Verify the settings were applied
341+
self.assertTrue(wandb.run.settings.silent)
342+
self.assertTrue(wandb.run.settings.disable_code)
343+
finally:
344+
wandb.finish()
345+
324346

325347
if __name__ == "__main__":
326348
absltest.main()

0 commit comments

Comments
 (0)