def setUp(self): self.p = promote.Promote('fakeuser', 'fakeapike', 'https://www.fakeurl.com/') self.p.deployment_file = os.path.join(os.path.dirname(__file__), 'sample-model', 'deploy_clfModel.py') self.p.deployment_dir = os.path.dirname(self.p.deployment_file)
def promote(self): sys.stdout.write("Promoting Container... ") sys.stdout.flush() prom = promote.Promote(self.image) prom.run() sys.stdout.write("Done") sys.stdout.flush()
def testInvalidDeploymentFile(self): originalArgv = copy.copy(sys.argv) sys.argv[0] = 'foo' try: promote.Promote('fakeuser', 'fakeapike', 'https://www.fakeurl.com/') raise Exception("shouldn't get here") except Exception as ex: self.assertIsNotNone(ex) sys.argv = originalArgv
def testInvalidDeploymentDir(self): # TODO: this is just a subset of testInvalidDeploymentFile. it's a stupid test. originalArgv = copy.copy(sys.argv) sys.argv[0] = 'foo' try: promote.Promote('fakeuser', 'fakeapike', 'https://www.fakeurl.com/') raise Exception("shouldn't get here") except Exception as ex: self.assertIsNotNone(ex) sys.argv = originalArgv
# h2o will automatically hold on to the prediction data, which is a feature we don't need in promote # you must use h2o.remove() to remove this prediction from memory, otherwise you will eventually run # out of memory for your model. # http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/h2o.html?highlight=remove#h2o.remove h2o.remove(h2o_data) h2o.remove(prediction) # Return the result as our response. return {'response': model_response} USERNAME = '******' API_KEY = 'your_api_key' PROMOTE_URL = 'http://www.promote_url.com' p = promote.Promote(USERNAME, API_KEY, PROMOTE_URL) # add metadata p.metadata.logloss = float("{0:.5f}".format(model.logloss())) # test data TESTDATA = {"C1": 4.9, "C2": 3, "C3": 1.4, "C4": 0.2} # test model locally print(helloh2o(TESTDATA)) # test that TESTDATA is valid json p.deploy("helloh2o", helloh2o, TESTDATA, confirm=True,
import helpers from sklearn.externals import joblib clf = joblib.load('./pickles/model_weights.pkl') with tf as tensorflow: tf.session() tf.load('./pickles/model_weights.pkl') t = [1,2,3,4,5] import promote p = promote.Promote("colin", "789asdf879h789a79f79sf79s", "https://sandbox.c.yhat.com/") # schema is optional @schema(Schema([{'name': And(str, len)}])) def promoteModel(data): tf.evaluate(testdata) if prediction not in t: return 'error' else: return prediction # testdata is optional testdata = {'name': 'greg'} promoteModel(testdata) p.deploy("HelloModel", promoteModel, testdata=testdata, confirm=True, dry_run=False, verbose=0)