Skip to content
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: importing mlflow:/ urls with no extra path info #2930

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

tweeklab
Copy link
Contributor

What does this PR address?

When importing a MLFlow model with a models:/ URI, the downloader puts the files at the registered model path directly into the dst_path. When dst_path is specified as bento_model.path in this case, the downloader simply returns that same value. If bentoml_model.path had the value /tmp/test_tmp_path, then the subsequent rename of the downloaded dir to mlflow_model to turn into the equivalent of:

shutil.move(/tmp/test_tmp_path, /tmp/test_tmp_path/mlflow_model), which is going to always fail. The other URI types I've tried don't seem to do this, they all seem to create a subdirectory under bento_model.path as a side effect of the download.

This fix creates an extra directory to download into, so if a models:/ URI is used, it will instead download into this directory and give the shutil.move something to rename. If the directory is still there after the fact, it's cleaned up.

Before submitting:

  • Does the Pull Request follow Conventional Commits specification naming? Here are GitHub's
    guide
    on how to create a pull request.
  • Does the code follow BentoML's code style, both make format and make lint script have passed (instructions)?
  • Did you read through contribution guidelines and follow development guidelines?
  • Did your changes require updates to the documentation? Have you updated
    those accordingly? Here are documentation guidelines and tips on writting docs.
  • Did you write tests to cover your changes? - I can't think of a way to test this that does not require patching the downloader. Since the downloader is imported when the code runs (to accommodate different versions of mlflow), I can't figure out how to get it patched. Open to ideas.

Who can help review?

Feel free to tag members/contributors who can help review your PR.

@tweeklab tweeklab requested a review from a team as a code owner August 22, 2022 22:20
@tweeklab tweeklab requested review from sauyon and removed request for a team August 22, 2022 22:20
@yubozhao yubozhao requested a review from ssheng August 22, 2022 22:22
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #2930 (e424834) into main (2552c8b) will increase coverage by 0.90%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2930      +/-   ##
==========================================
+ Coverage   69.80%   70.71%   +0.90%     
==========================================
  Files         121      104      -17     
  Lines        9930     9446     -484     
==========================================
- Hits         6932     6680     -252     
+ Misses       2998     2766     -232     
Impacted Files Coverage Δ
bentoml/_internal/frameworks/mlflow.py 91.54% <100.00%> (+0.50%) ⬆️
bentoml/_internal/frameworks/torchscript.py 0.00% <0.00%> (-95.92%) ⬇️
bentoml/_internal/frameworks/common/pytorch.py 0.00% <0.00%> (-72.64%) ⬇️
bentoml/_internal/runner/strategy.py 83.05% <0.00%> (-8.48%) ⬇️
bentoml/_internal/runner/runner_handle/local.py 76.00% <0.00%> (-8.00%) ⬇️
bentoml/_internal/models/model.py 88.07% <0.00%> (-1.76%) ⬇️
bentoml/_internal/runner/runner.py 90.90% <0.00%> (-0.91%) ⬇️
bentoml/bentos.py
bentoml/tensorflow.py
bentoml/lightgbm.py
... and 14 more

Comment on lines +215 to +216
if os.path.isdir(download_dir):
shutil.rmtree(download_dir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to put this logic in a finally block. We can merge this and add the finally block as a follow-up.

@ssheng ssheng merged commit 0e64c50 into bentoml:main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants