-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/wandb_artifact_log_checkpoint' into 'main'
Feature/wandb artifact log checkpoint See merge request ADLR/megatron-lm!2575
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
|
||
from pathlib import Path | ||
|
||
from megatron.training.global_vars import get_wandb_writer | ||
|
||
|
||
def on_save_checkpoint_success(checkpoint_path: str, tracker_filename: str, save_dir: str, iteration: int) -> None: | ||
"""Function to be called after checkpointing succeeds and checkpoint is persisted for logging it as an artifact in W&B | ||
Args: | ||
checkpoint_path (str): path of the saved checkpoint | ||
tracker_filename (str): path of the tracker filename for the checkpoint iteration | ||
save_dir (str): path of the root save folder for all checkpoints | ||
iteration (int): iteration of the checkpoint | ||
""" | ||
|
||
wandb_writer = get_wandb_writer() | ||
|
||
if wandb_writer: | ||
metadata = {"iteration": iteration} | ||
artifact = wandb_writer.Artifact(Path(save_dir).stem, type="model", metadata=metadata) | ||
artifact.add_reference(f"file://{checkpoint_path}", checksum=False) | ||
artifact.add_file(tracker_filename) | ||
wandb_writer.run.log_artifact(artifact, aliases=[Path(checkpoint_path).stem]) |