File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 7
7
import shutil
8
8
from pathlib import Path
9
9
from typing import Optional , Union , Any
10
- import h2o
10
+
11
+ try :
12
+ import h2o
13
+ except ImportError :
14
+ h2o = None
11
15
12
16
from ..utils .misc import check_if_jupyter
13
17
@@ -107,7 +111,12 @@ def pickle_trained_model(
107
111
else :
108
112
return {model_prefix + PICKLE : pickle .dumps (trained_model )}
109
113
# For binary H2O models, save the binary file as a "pickle" file
110
- elif is_binary_model and pickle_path :
114
+ elif is_h2o_model and is_binary_model and pickle_path :
115
+ if not h2o :
116
+ raise RuntimeError (
117
+ "The h2o package is required to save the model as a binary h2o"
118
+ "model."
119
+ )
111
120
h2o .save_model (
112
121
model = trained_model ,
113
122
force = True ,
@@ -116,6 +125,10 @@ def pickle_trained_model(
116
125
)
117
126
# For MOJO H2O models, gzip the model file and adjust the file extension
118
127
elif is_h2o_model and pickle_path :
128
+ if not h2o :
129
+ raise RuntimeError (
130
+ "The h2o package is required to save the model as a mojo model."
131
+ )
119
132
trained_model .save_mojo (
120
133
force = True , path = pickle_path , filename = f"{ model_prefix } .mojo"
121
134
)
You can’t perform that action at this time.
0 commit comments