Add artifacts log mlflow logger #3928
Open
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.
What does this PR do?
This PR adds artifact logging support to the
MLFlowLoggerby implementing theupload_file()method from theLoggerDestinationinterface.Key Changes:
upload_file(): Adds the ability to log files and directories as MLflow artifactsMlflowClient.log_artifact()for single files andMlflowClient.log_artifacts()for directories_enabledflag to ensure artifacts are only logged from rank-zero in distributed settingscan_upload_files(): ReturnsTrueto advertise the artifact upload capabilityMotivation:
Previously,
MLFlowLoggercould not upload arbitrary files as artifacts (e.g., checkpoints, model weights, configuration files). Usingmlflow.log_artifact()directly in training code caused conflicts in distributed training scenarios withworld_size > 1. This implementation provides a proper, safe way to log artifacts that works correctly in both single-node and distributed training.Implementation Details:
The
upload_file()method:file_pathpointing to files or directoriesremote_file_name_enabled=False(distributed training, non-rank-zero)What issue(s) does this change relate to?
MLFlowLoggercouldn't upload files through the standardLoggerDestinationinterfaceBefore submitting
test_mlflow_upload_single_file()- tests single file uploadtest_mlflow_upload_directory()- tests directory upload with multiple filestest_mlflow_upload_file_not_enabled()- tests distributed training behaviortest_mlflow_can_upload_files()- tests capability advertisementpre-commiton your change? (see thepre-commitsection of prerequisites)Testing Notes:
All tests follow existing patterns in
test_mlflow_logger.py:pytest.importorskip('mlflow')for conditional test executiontmp_pathfixtures for isolated testing