Simon M.
Simon M.

Reputation: 21

Converting H2O MOJOmodels to Binary

I am trying to upgrade a binary (DRF) H2O model to a higher version (from v3.28.1.2 to v3.42.0.3). Due to tecnical restrictions I cannot use the MOJO format for deployment. Is it possible to do the following instead?

  1. load the binary model in the older version
  2. export the model as MOJO format
  3. load the model in MOJO format in the newer version
  4. save the model in Binary in the newer version

I am able to save the model in the newer version. However, when I try to load the model object (using h2o.load_model()), I get the following error:


H2OServerError: HTTP 500 Server Error:
Server error java.lang.NullPointerException:
  Error: Caught exception: java.lang.NullPointerException
  Request: None
  Stacktrace: java.lang.NullPointerException
      hex.generic.GenericModel$GenModelSource.backingByteVec(GenericModel.java:391)
      hex.generic.GenericModel$GenModelSource.get(GenericModel.java:373)
      hex.generic.GenericModel.genModel(GenericModel.java:325)
      hex.generic.GenericModel.havePojo(GenericModel.java:546)
      water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:80)
      water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:22)
      water.api.ModelsHandler.importModel(ModelsHandler.java:263)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Upvotes: 2

Views: 128

Answers (1)

Wendy
Wendy

Reputation: 301

Let me first say what you have done is very innovative! We do not provide binary model support across the different H2O-3 versions but you found a way to do this by using Mojo and generic model.

Here is the code I used to check out your issues. However, I used the same version of H2O-3 3.44.0.3. I was able to execute the code and get a prediction frame at the end of it. If this does not help, please open an issue here (https://github.com/h2oai/h2o-3/issues) with versions of old H2O-3 and new H2O-3 that you use to create your old model and the version you try to load it with.

import h2o
import tempfile
from h2o.estimators import H2ORandomForestEstimator, H2OGenericEstimator

    airlines= h2o.import_file(path=pyunit_utils.locate("smalldata/testng/airlines_train.csv"))
drf = H2ORandomForestEstimator(ntrees=1)
drf.train(x=x, y=y, training_frame=airlines)

original_model_filename = tempfile.mkdtemp()
original_dir = original_model_filename
original_model_filename = drf.download_mojo(original_model_filename)
  
model = H2OGenericEstimator.from_file(original_model_filename)
modelBinary = model.download_model(original_dir)
model2 = h2o.load_model(modelBinary)
pred2 = model2.predict(airlines)

Upvotes: 1

Related Questions