From b3e254c3a51a6c2a67e97d0846fb02c784758e0d Mon Sep 17 00:00:00 2001 From: Wojciech Jarmosz Date: Sun, 23 May 2021 21:42:55 +0200 Subject: [PATCH] Add model fetching from mlflow registry --- Jenkinsfile_coop_registry | 19 +++++++++++++++++++ mlflow_prediction_registry.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Jenkinsfile_coop_registry create mode 100644 mlflow_prediction_registry.py diff --git a/Jenkinsfile_coop_registry b/Jenkinsfile_coop_registry new file mode 100644 index 0000000..fa132d8 --- /dev/null +++ b/Jenkinsfile_coop_registry @@ -0,0 +1,19 @@ +pipeline { + agent {dockerfile true, args '-v /tmp/mlruns:/tmp/mlruns'} + parameters { + string( + defaultValue: 'input_example.json', + description: 'Input name', + name: 'INPUT_NAME', + trim: false + ) + } + stages { + stage('Load model and run prediction') { + steps { + sh 'python3 mlflow_prediction_registry.py $INPUT_NAME' + } + } + + } +} \ No newline at end of file diff --git a/mlflow_prediction_registry.py b/mlflow_prediction_registry.py new file mode 100644 index 0000000..baebc1f --- /dev/null +++ b/mlflow_prediction_registry.py @@ -0,0 +1,28 @@ + +import json +import mlflow +from mlflow.tracking import MlflowClient +import mlflow.pyfunc +import torch +import numpy as np +import pandas as pd + +import sys + +arguments = sys.argv[1:] + +mlflow.set_tracking_uri("http://172.17.0.1:5000") +client = MlflowClient() +version = 1 +model_name = "s434704" + +input = str(arguments[0]) + +model = mlflow.pyfunc.load_model( + model_uri=f"models:/{model_name}/{model_version}" +) + +with open(f'{model_name}/{input}', 'r') as file: + json_data = json.load(file) + +print(model(torch.tensor(np.array(json_data['inputs'])).float())) \ No newline at end of file