Skip to content

Commit b3bd5a7

Browse files
authored
qa: cleanup MLflow (#2945)
1 parent c8e5587 commit b3bd5a7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

bentoml/_internal/frameworks/mlflow.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
if TYPE_CHECKING:
2626
import mlflow
27+
import mlflow.models
2728
else:
2829
mlflow = LazyLoader(
2930
"mlflow",
@@ -205,19 +206,16 @@ def import_model(
205206
# For MLflow < 1.25
206207
from mlflow.tracking.artifact_utils import _download_artifact_from_uri
207208

208-
local_path = _download_artifact_from_uri(
209+
local_path: str = _download_artifact_from_uri(
209210
artifact_uri=model_uri, output_path=download_dir
210211
)
211-
212-
mlflow_model_path = bento_model.path_of(MLFLOW_MODEL_FOLDER)
213-
# Rename model folder from original artifact name to fixed "mlflow_model"
214-
shutil.move(local_path, mlflow_model_path)
215-
# If the temp dir we created still exists now, we never needed it because
216-
# the provided mlflow url must have provided enough path information. Just
217-
# delete it. If it's not here, it means we needed it but it's been renamed
218-
# by now so we don't need to remove it.
219-
if os.path.isdir(download_dir):
212+
finally:
213+
mlflow_model_path = bento_model.path_of(MLFLOW_MODEL_FOLDER)
214+
# Rename model folder from original artifact name to fixed "mlflow_model"
215+
shutil.move(local_path, mlflow_model_path) # type: ignore (local_path is bound)
216+
# Remove the tempdir
220217
shutil.rmtree(download_dir)
218+
221219
mlflow_model_file = os.path.join(mlflow_model_path, MLMODEL_FILE_NAME)
222220

223221
if not os.path.exists(mlflow_model_file):
@@ -258,7 +256,7 @@ def __init__(self):
258256
input_spec=None,
259257
output_spec=None,
260258
)
261-
def predict(self, input_data):
259+
def predict(self, input_data: t.Any) -> t.Any:
262260
return self.model.predict(input_data)
263261

264262
return MLflowPyfuncRunnable

0 commit comments

Comments
 (0)