-
Notifications
You must be signed in to change notification settings - Fork 444
MLFlow Integration #1542
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
Closed
Closed
MLFlow Integration #1542
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
af9265e
first commit (yet to fully verify)
therealnaveenkamal 97fa748
few fixes, ruff formatting
therealnaveenkamal f6c4b20
Merge branch 'main' into main
therealnaveenkamal 4397ee9
fixes mlflow to be consistent with wandb logic
therealnaveenkamal de13928
moved _sanitize_mlflow_metrics to mlflow_utils.py
therealnaveenkamal b6da82b
Merge branch 'main' into main
therealnaveenkamal 9df13b4
moved save_serialize to log_utils
therealnaveenkamal e38df21
added unit tests
therealnaveenkamal 346aa5b
added finalize function to validate mlflow installation
therealnaveenkamal 4c21b4c
build: Adding dependencies
therealnaveenkamal 492e7bf
Disable MLflow settings in llama32_1b_pretrain.yaml
therealnaveenkamal 3148469
Merge branch 'main' into main
therealnaveenkamal b04184f
added copyright info to mlflow_utils
therealnaveenkamal b0d5c15
fixes: removed warn_rank_0, used get_checkpoint_name for consistency
therealnaveenkamal b51de40
ruff formatting
therealnaveenkamal 902332e
Merge branch 'main' of github.com:NVIDIA-NeMo/Megatron-Bridge
therealnaveenkamal f26dba4
Merge remote-tracking branch 'upstream/main'
therealnaveenkamal e07db35
added max-attention-logit param
therealnaveenkamal cd4a36a
Merge branch 'main' into main
yaoyu-33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| from pathlib import Path | ||
| from typing import Any, Optional | ||
|
|
||
| from megatron.bridge.utils.common_utils import print_rank_last | ||
|
|
||
|
|
||
| def on_save_checkpoint_success( | ||
| checkpoint_path: str, | ||
| save_dir: str, | ||
| iteration: int, | ||
| mlflow_logger: Optional[Any], | ||
| ) -> None: | ||
| """Callback executed after a checkpoint is successfully saved. | ||
|
|
||
| If an MLFlow logger is provided, logs the checkpoint directory as an MLFlow | ||
| artifact under a structured artifact path that includes the iteration number. | ||
|
|
||
| Args: | ||
| checkpoint_path: The path to the specific checkpoint file/directory saved. | ||
| save_dir: The base directory where checkpoints are being saved. | ||
| iteration: The training iteration at which the checkpoint was saved. | ||
| mlflow_logger: The MLFlow module (e.g., ``mlflow``) with an active run. | ||
| If None, this function is a no-op. | ||
| """ | ||
| if mlflow_logger is None: | ||
| return | ||
|
|
||
| try: | ||
| checkpoint_path = str(Path(checkpoint_path).resolve()) | ||
| base_name = Path(save_dir).name or "checkpoints" | ||
| artifact_subdir = f"{base_name}/iter_{iteration:07d}" | ||
|
therealnaveenkamal marked this conversation as resolved.
Outdated
|
||
| mlflow_logger.log_artifacts(checkpoint_path, artifact_path=artifact_subdir) | ||
| except Exception as exc: | ||
| # continue training | ||
| print_rank_last(f"Failed to log checkpoint artifacts to MLFlow: {exc}") | ||
|
|
||
|
|
||
| def on_load_checkpoint_success( | ||
| checkpoint_path: str, | ||
| load_dir: str, | ||
| mlflow_logger: Optional[Any], | ||
| ) -> None: | ||
| """Callback executed after a checkpoint is successfully loaded. | ||
|
|
||
| For MLFlow, this emits a simple metric and tag to document which checkpoint | ||
| was loaded during the run. It does not perform artifact lookups. | ||
|
|
||
| Args: | ||
| checkpoint_path: The path to the specific checkpoint file/directory loaded. | ||
| load_dir: The base directory from which the checkpoint was loaded. | ||
| mlflow_logger: The MLFlow module (e.g., ``mlflow``) with an active run. | ||
| If None, this function is a no-op. | ||
| """ | ||
| if mlflow_logger is None: | ||
| return | ||
|
|
||
| try: | ||
| resolved_ckpt = str(Path(checkpoint_path).resolve()) | ||
| resolved_load_dir = str(Path(load_dir).resolve()) | ||
| mlflow_logger.set_tags( | ||
| { | ||
| "last_loaded_checkpoint": resolved_ckpt, | ||
| "checkpoint_base_dir": resolved_load_dir, | ||
| } | ||
| ) | ||
| except Exception as exc: | ||
| print_rank_last(f"Failed to record loaded checkpoint information to MLFlow: {exc}") | ||
|
|
||
|
|
||
| def _sanitize_mlflow_metrics(metrics: dict[str, Any]) -> dict[str, Any]: | ||
| """Sanitize all metric names in a dictionary for MLFlow logging.""" | ||
| return {key.replace("/", "_"): value for key, value in metrics.items()} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.