Skip to content

Commit 9e4d842

Browse files
committed
Add option to copy & rename pickle file from MLFlow model
1 parent bf9c81b commit 9e4d842

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/sasctl/pzmm/pickleModel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) 2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
4-
53
# %%
64
from pathlib import Path
5+
import shutil
6+
import os
77

88
import pickle
99
import gzip
@@ -19,6 +19,7 @@ def pickleTrainedModel(
1919
isH2OModel=False,
2020
isBinaryModel=False,
2121
isBinaryString=False,
22+
mlFlowDetails=None,
2223
):
2324
"""
2425
Write trained model to a binary pickle file, H2O MOJO file, or a binary string object.
@@ -48,6 +49,8 @@ def pickleTrainedModel(
4849
Sets whether the H2O model provided is a binary model or a MOJO model. By default False.
4950
isBinaryString : boolean, optional
5051
Sets whether the model is to be set as a binary string instead of a pickle file. By default False.
52+
mlFlowDetails : dict, optional
53+
Model details from an MLFlow model. This dictionary is created by the readMLModelFile function.
5154
5255
Returns
5356
-------
@@ -60,6 +63,14 @@ def pickleTrainedModel(
6063
if isBinaryString:
6164
binaryString = codecs.encode(pickle.dumps(trainedModel), "base64").decode()
6265
return binaryString
66+
elif mlFlowDetails is not None:
67+
mlPicklePath = (
68+
Path(mlFlowDetails["mlflowPath"]) / mlFlowDetails["model_path"]
69+
)
70+
shutil.copy(mlPicklePath, pPath)
71+
Path(pPath + mlFlowDetails["model_path"]).rename(
72+
Path(pPath) / (modelPrefix + ".pickle")
73+
)
6374
else:
6475
# For non-H2O models, pickle the model object
6576
if not isH2OModel:

0 commit comments

Comments
 (0)