-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix regression in downloading single files from models artifact store #10362
Conversation
Documentation preview for 0e72186 will be available here when this CircleCI job completes successfully. More info
|
model_name = "MyModel" | ||
model_version = "12" | ||
|
||
with mock.patch.object( | ||
MlflowClient, "get_model_version_download_uri", return_value=artifact_location | ||
), mock.patch("mlflow.store.artifact.models_artifact_repo.write_yaml") as write_yaml_mock: | ||
), mock.patch("os.path.isdir", return_value=True), mock.patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to patch os.path.isdir
? Patching the built-in functions can lead to bugs. I think we can download a file instead of a directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored tests to use tmp_path location
_logger.warning( | ||
"Registered Model Metadata file not able to be written. Destination path " | ||
f"'{model_path}' is not a directory." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning might scare users or make them wonder what Registered Model Metadata file
unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Removed this. It's really only valid for deploying a root model directory and only if deploying to MLserver anyway. I'll add a note in the code about why the file might not be created.
) as write_yaml_mock, mock.patch( | ||
"os.path.isdir", return_value=False | ||
), mock.patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Calling the download_artifacts method on local FileStore will create an ./mlruns directory | ||
# which is a test side effect. Clean this up. | ||
mlruns_dir = "./mlruns" | ||
if os.path.exists(mlruns_dir): | ||
shutil.rmtree(mlruns_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, can we set the artifact location to a temporary directory? If we hit an error before this block, ./mlruns
won't be cleaned up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! refactored
overwrite=True, | ||
ensure_yaml_extension=False, | ||
) | ||
if os.path.isdir(model_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file created when we download a subdirectory in the model directory?
- model
- subdir <- this directory
- MLmodel
- ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we update 'download_artifacts' function to only call this method when 'model_path' is a directory instead? Then we also don't need below warning as it doesn't make sense for non-directory cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harupy good call. Adjusted the logic to only create this registered metadata file iff the model_path resolution after download contains the MLmodel file. Add a test to verify this behavior.
@serena-ruan great idea - updated!
@@ -169,8 +173,14 @@ def download_artifacts(self, artifact_path, dst_path=None): | |||
:return: Absolute path of the local filesystem location containing the desired artifacts. | |||
""" | |||
|
|||
from mlflow.models.model import MLMODEL_FILE_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot do a non-local import due to circular reference. We really should migrate constants like these to a separate 'neutral zero-dependency' location, but that is out of scope for this PR.
|
||
models_repo.download_artifacts(artifact_location, str(tmp_path)) | ||
|
||
add_meta_mock.assert_called_once() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, can we check that the metadata file exists?
dummy_dir = tmp_path / artifact_path | ||
dummy_dir.mkdir() | ||
dummy_file = dummy_dir / "dummy_file.txt" | ||
dummy_file.write_text("dummy content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dummy_file.write_text("dummy content") | |
dummy_file.touch() |
We can use touch
if the content is not important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
model_dir = temp_remote_storage / "model_dir" | ||
model_dir.mkdir(parents=True) | ||
mlmodel_path = model_dir / "MLmodel" | ||
mlmodel_path.write_text("dummy content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mlmodel_path.write_text("dummy content") | |
mlmodel_path.touch() |
we can use more touch
.
artifact_dst_path = f"{dst_path}/{artifact_path}" | ||
|
||
dummy_file = tmp_path / artifact_path | ||
dummy_file.write_text("dummy content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
""" | ||
artifact_location = "s3://blah_bucket/" | ||
dummy_file = tmp_path / "dummy_file.txt" | ||
dummy_file.write_text("dummy content") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
fa68683
to
0e72186
Compare
…#10362) Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
…mlflow#10362) Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com> Signed-off-by: swathi <konakanchi.swathi@gmail.com>
🛠 DevTools 🛠
Install mlflow from this PR
Checkout with GitHub CLI
Related Issues/PRs
Resolve #10230
What changes are proposed in this pull request?
Fixed the regression introduced in #9402 wherein no handling logic is provided for non-directory source file resolution, which would attempt to create a registration metadata file using a destination file as a directory path (which raises an Exception).
How is this PR tested?
Validated the basic repro is broken in 2.8.0 and is fixed in this PR (test added to validate as well):
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/artifacts
: Artifact stores and artifact loggingarea/build
: Build and test infrastructure for MLflowarea/docs
: MLflow documentation pagesarea/examples
: Example codearea/gateway
: AI Gateway service, Gateway client APIs, third-party Gateway integrationsarea/model-registry
: Model Registry service, APIs, and the fluent client calls for Model Registryarea/models
: MLmodel format, model serialization/deserialization, flavorsarea/recipes
: Recipes, Recipe APIs, Recipe configs, Recipe Templatesarea/projects
: MLproject format, project running backendsarea/scoring
: MLflow Model server, model deployment tools, Spark UDFsarea/server-infra
: MLflow Tracking server backendarea/tracking
: Tracking Service, tracking client APIs, autologgingInterface
area/uiux
: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/docker
: Docker use across MLflow's components, such as MLflow Projects and MLflow Modelsarea/sqlalchemy
: Use of SQLAlchemy in the Tracking Service or Model Registryarea/windows
: Windows supportLanguage
language/r
: R APIs and clientslanguage/java
: Java APIs and clientslanguage/new
: Proposals for new client languagesIntegrations
integrations/azure
: Azure and Azure ML integrationsintegrations/sagemaker
: SageMaker integrationsintegrations/databricks
: Databricks integrationsHow should the PR be classified in the release notes? Choose one:
rn/none
- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change
- The PR will be mentioned in the "Breaking Changes" sectionrn/feature
- A new user-facing feature worth mentioning in the release notesrn/bug-fix
- A user-facing bug fix worth mentioning in the release notesrn/documentation
- A user-facing documentation change worth mentioning in the release notes