QTZPOC-20
QTZPOC-20: Unify artifact code directory handling for all model flavors and standardize joblib pickle path Implemented a robust mechanism to ensure an artifact's code/ directory is prepended to sys.path before loading for sklearn, pyfunc, and joblib flavors. sklearn and pyfunc now resolve MLflow URIs to local directories first to facilitate this sys.path modification. Standardized the joblib flavor to explicitly read and write model.pkl within the artifact directory. Updated documentation and added comprehensive tests to reflect these changes.
This commit is contained in:
@@ -546,6 +546,15 @@ def patch_mlflow(mock_mlflow_models, joblib_flavor_artifacts):
|
||||
mock_mlflow.pyfunc = MagicMock()
|
||||
mock_mlflow.pyfunc.load_model = MagicMock(side_effect=mock_pyfunc_load_model)
|
||||
|
||||
# The sklearn and pyfunc paths resolve the URI to a local directory before loading, so that the
|
||||
# artifact's `code/` can go on `sys.path` whatever the `MLmodel` manifest says. Echoing the URI
|
||||
# keeps the loader stubs above — which branch on the URI text — working unchanged, and points
|
||||
# the code-directory lookup at a path that does not exist.
|
||||
mock_mlflow.artifacts = MagicMock()
|
||||
mock_mlflow.artifacts.download_artifacts = MagicMock(
|
||||
side_effect=lambda artifact_uri: str(artifact_uri)
|
||||
)
|
||||
|
||||
# Mock other mlflow methods that might be called
|
||||
mock_mlflow.set_tracking_uri = MagicMock()
|
||||
mock_mlflow.get_run = MagicMock(
|
||||
|
||||
Reference in New Issue
Block a user