Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions runtimes/mlflow/mlserver_mlflow/runtime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mlflow

import asyncio
from io import StringIO
from fastapi import Depends, Header, Request, Response

Expand Down Expand Up @@ -155,6 +156,11 @@ async def invocations(
async def load(self) -> bool:
# TODO: Log info message
model_uri = await get_model_uri(self._settings)

if getattr(self._settings.parameters.extra, "auto_install_dependencies", False):
# INFO: Install dependencies before loading the model
await self._install_dependencies(model_uri)

self._model = mlflow.pyfunc.load_model(model_uri)

self._input_schema = self._model.metadata.get_input_schema()
Expand All @@ -163,6 +169,22 @@ async def load(self) -> bool:

return True

async def _install_dependencies(self, model_uri: str):
model_dependencies = mlflow.pyfunc.mlflow.artifacts.download_artifacts(
f"{model_uri}/requirements.txt"
)

cmd = ["pip", "install", "-r", model_dependencies]

# Execute command asynchronously
process = await asyncio.create_subprocess_exec(
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
error_msg = stderr.decode() if stderr else "Unknown error"
raise RuntimeError(f"Failed to install dependencies: {error_msg}")

def _sync_metadata(self) -> None:
# Update metadata from model signature (if present)
if self._signature is None:
Expand Down
3 changes: 3 additions & 0 deletions runtimes/mlflow/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.