From 293de2a19af1ce4a38dd87ecc245f9a043f85b48 Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Fri, 1 Jul 2022 14:05:52 +0530 Subject: [PATCH 01/12] Init --- mlflow-pytorch/iris/conda.yaml | 11 +++ mlflow-pytorch/iris/iris_classification.py | 107 +++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 mlflow-pytorch/iris/conda.yaml create mode 100644 mlflow-pytorch/iris/iris_classification.py diff --git a/mlflow-pytorch/iris/conda.yaml b/mlflow-pytorch/iris/conda.yaml new file mode 100644 index 0000000..90cdebe --- /dev/null +++ b/mlflow-pytorch/iris/conda.yaml @@ -0,0 +1,11 @@ +channels: +- conda-forge +dependencies: +- python=3.8.2 +- pip +- pip: + - sklearn + - cloudpickle==1.6.0 + - boto3 + - torchvision>=0.9.1 + - torch>=1.9.0 diff --git a/mlflow-pytorch/iris/iris_classification.py b/mlflow-pytorch/iris/iris_classification.py new file mode 100644 index 0000000..ae35e29 --- /dev/null +++ b/mlflow-pytorch/iris/iris_classification.py @@ -0,0 +1,107 @@ +# pylint: disable=abstract-method +import argparse +import torch +import torch.nn as nn +import torch.nn.functional as F +import os +from dkube.sdk import mlflow as m +from sklearn.datasets import load_iris +from sklearn.metrics import accuracy_score +from sklearn.model_selection import train_test_split + +import mlflow.pytorch + + +class IrisClassifier(nn.Module): + def __init__(self): + super(IrisClassifier, self).__init__() + self.fc1 = nn.Linear(4, 10) + self.fc2 = nn.Linear(10, 10) + self.fc3 = nn.Linear(10, 3) + + def forward(self, x): + x = F.relu(self.fc1(x)) + x = F.relu(self.fc2(x)) + x = F.dropout(x, 0.2) + x = self.fc3(x) + return x + + +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") + + +def prepare_data(): + iris = load_iris() + data = iris.data + labels = iris.target + target_names = iris.target_names + + X_train, X_test, y_train, y_test = train_test_split( + data, labels, test_size=0.2, random_state=42, shuffle=True, stratify=labels + ) + + X_train = torch.FloatTensor(X_train).to(device) + X_test = torch.FloatTensor(X_test).to(device) + y_train = torch.LongTensor(y_train).to(device) + y_test = torch.LongTensor(y_test).to(device) + + return X_train, X_test, y_train, y_test, target_names + + +def train_model(model, epochs, X_train, y_train): + criterion = nn.CrossEntropyLoss() + optimizer = torch.optim.Adam(model.parameters(), lr=0.01) + + for epoch in range(epochs): + out = model(X_train) + loss = criterion(out, y_train).to(device) + optimizer.zero_grad() + loss.backward() + optimizer.step() + + if epoch % 10 == 0: + print("number of epoch", epoch, "loss", float(loss)) + + return model + + +def test_model(model, X_test, y_test): + model.eval() + with torch.no_grad(): + predict_out = model(X_test) + _, predict_y = torch.max(predict_out, 1) + + print("\nprediction accuracy", float(accuracy_score(y_test.cpu(), predict_y.cpu()))) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Iris Classification Torchscripted model") + + parser.add_argument( + "--epochs", type=int, default=100, help="number of epochs to run (default: 100)" + ) + parser.add_argument("--code", required=True, help="input code name") + parser.add_argument("--dataset", help="input dataset name") + parser.add_argument("--output", required=True, help="output model name") + + args = parser.parse_args() + + model = IrisClassifier() + model = model.to(device) + X_train, X_test, y_train, y_test, target_names = prepare_data() + scripted_model = torch.jit.script(model) # scripting the model + scripted_model = train_model(scripted_model, args.epochs, X_train, y_train) + test_model(scripted_model, X_test, y_test) + + run_id= m.create_run(code=args.code, output=args.output) + with mlflow.start_run(run_id) as run: + mlflow.pytorch.log_model(scripted_model, "model") # logging scripted model + model_path = mlflow.get_artifact_uri("model") + loaded_pytorch_model = mlflow.pytorch.load_model(model_path) # loading scripted model + model.eval() + with torch.no_grad(): + test_datapoint = torch.Tensor([4.4000, 3.0000, 1.3000, 0.2000]).to(device) + prediction = loaded_pytorch_model(test_datapoint) + actual = "setosa" + predicted = target_names[torch.argmax(prediction)] + print("\nPREDICTION RESULT: ACTUAL: {}, PREDICTED: {}".format(actual, predicted)) From 02f40c478ac3277ffad341d101f6ce8e71430e5d Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Tue, 5 Jul 2022 11:19:17 +0530 Subject: [PATCH 02/12] python env example --- mlflow/README.md | 13 ++++++++----- mlflow/conda.yaml | 12 ------------ mlflow/requirements.txt | 5 +++++ 3 files changed, 13 insertions(+), 17 deletions(-) delete mode 100644 mlflow/conda.yaml create mode 100644 mlflow/requirements.txt diff --git a/mlflow/README.md b/mlflow/README.md index de7cffb..6cc87b5 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -1,15 +1,18 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorflow/tf2 ### Setup -1. Create a code with url- https://github.com/oneconvergence/dkubeio-examples/tree/mlflow/mlflow branch -mlflow +1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch -mlflow 2. Create an output model ### Traning 1. Create a vs code IDE with tensorflow 2.6.0 cpu image -2. cd to the code directory where we have the conda.yaml file -3. conda env create -f conda.yaml -4. conda activate tensorflow-example -5. python train_predict.py --code {code name} --output {output model name} +2. cd to the code directory where we have the requirements.txt file +3. pip3 install virtualenv +4. export PATH=$PATH:$HOME/.local/bin +5. virtualenv -p python3 env +6. . env/bin/activate +7. pip3 install -r requirements.txt +8. python train_predict.py --code {code name} --output {output model name} ### Building Image 1. Go to the model details page which was given as output in the above training run. A new version will be there in the version list. diff --git a/mlflow/conda.yaml b/mlflow/conda.yaml deleted file mode 100644 index 0685625..0000000 --- a/mlflow/conda.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: tensorflow-example -channels: - - conda-forge -dependencies: - - python=3.7 - - pip - - pip: - - mlflow - - tensorflow==2.0.0 - - protobuf==3.19.4 - - git+https://github.com/oneconvergence/dkube.git@3.3.mp - - boto3 diff --git a/mlflow/requirements.txt b/mlflow/requirements.txt new file mode 100644 index 0000000..45278e1 --- /dev/null +++ b/mlflow/requirements.txt @@ -0,0 +1,5 @@ +mlflow +tensorflow==2.0.0 +protobuf==3.19.4 +git+https://github.com/oneconvergence/dkube.git@3.3.mp +boto3 \ No newline at end of file From 651351a6fdb60dab309b89a16f63c04602a5ad3e Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Wed, 6 Jul 2022 10:36:12 +0530 Subject: [PATCH 03/12] Add packages --- mlflow-pytorch/iris/conda.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mlflow-pytorch/iris/conda.yaml b/mlflow-pytorch/iris/conda.yaml index 90cdebe..0bd9505 100644 --- a/mlflow-pytorch/iris/conda.yaml +++ b/mlflow-pytorch/iris/conda.yaml @@ -1,3 +1,4 @@ +name: pytorch-example channels: - conda-forge dependencies: @@ -9,3 +10,5 @@ dependencies: - boto3 - torchvision>=0.9.1 - torch>=1.9.0 + - git+https://github.com/oneconvergence/dkube.git@3.3.mp + - mlflow From fb36987d599bc6410c789df52b0d6a49f5c25fac Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Wed, 6 Jul 2022 13:57:49 +0530 Subject: [PATCH 04/12] Add README --- mlflow-pytorch/iris/Dockerfile | 60 ++++++++++++++++++++++ mlflow-pytorch/iris/README.md | 31 +++++++++++ mlflow-pytorch/iris/iris_classification.py | 13 ++--- 3 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 mlflow-pytorch/iris/Dockerfile create mode 100644 mlflow-pytorch/iris/README.md diff --git a/mlflow-pytorch/iris/Dockerfile b/mlflow-pytorch/iris/Dockerfile new file mode 100644 index 0000000..ce6ea33 --- /dev/null +++ b/mlflow-pytorch/iris/Dockerfile @@ -0,0 +1,60 @@ +# Build an image that can serve mlflow models. +FROM ubuntu:18.04 +RUN apt-get -y update +RUN apt-get install -y --no-install-recommends \ + wget \ + curl \ + nginx \ + ca-certificates \ + bzip2 \ + build-essential \ + cmake \ + openjdk-8-jdk \ + git-core \ + maven \ + && rm -rf /var/lib/apt/lists/* + +# Setup miniconda +RUN curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh >> miniconda.sh +RUN bash ./miniconda.sh -b -p /miniconda && rm ./miniconda.sh +ENV PATH="/miniconda/bin:$PATH" + +ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 +ENV GUNICORN_CMD_ARGS="--timeout 60 -k gevent" +# Set up the program in the image +WORKDIR /opt/mlflow + +RUN pip install mlflow==1.26.1 +RUN mvn --batch-mode dependency:copy -Dartifact=org.mlflow:mlflow-scoring:1.26.1:pom -DoutputDirectory=/opt/java +RUN mvn --batch-mode dependency:copy -Dartifact=org.mlflow:mlflow-scoring:1.26.1:jar -DoutputDirectory=/opt/java/jars +RUN cp /opt/java/mlflow-scoring-1.26.1.pom /opt/java/pom.xml +RUN cd /opt/java && mvn --batch-mode dependency:copy-dependencies -DoutputDirectory=/opt/java/jars + +ARG MODEL_PATH +COPY $MODEL_PATH/model /opt/ml/model + +RUN echo 'import yaml\n\ +with open(r"/opt/ml/model/conda.yaml") as file:\n\ + f = yaml.load(file, Loader=yaml.FullLoader)\n\ +for index, item in enumerate(f["dependencies"]):\n\ + if type(item) is dict and item.get("pip") != None:\n\ + f["dependencies"][index]["pip"].append("protobuf==3.19.4")\n\ + with open(r"/opt/ml/model/conda.yaml", "w") as file:\n\ + yaml.dump(f, file)' >> /tmp/update_conda_yaml.py +RUN python /tmp/update_conda_yaml.py + +RUN python -c \ + 'from mlflow.models.container import _install_pyfunc_deps;\ + _install_pyfunc_deps(\ + "/opt/ml/model", \ + install_mlflow=False, \ + enable_mlserver=False, \ + env_manager="conda")' +ENV MLFLOW_DISABLE_ENV_CREATION="true" +ENV ENABLE_MLSERVER="False" + +# granting read/write access and conditional execution authority to all child directories +# and files to allow for deployment to AWS Sagemaker Serverless Endpoints +# (see https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints.html) +RUN chmod o+rwX /opt/mlflow/ +ENTRYPOINT ["python", "-c", "from mlflow.models import container as C;C._serve('conda')"] diff --git a/mlflow-pytorch/iris/README.md b/mlflow-pytorch/iris/README.md new file mode 100644 index 0000000..4e623a5 --- /dev/null +++ b/mlflow-pytorch/iris/README.md @@ -0,0 +1,31 @@ +Example taken from https://github.com/mlflow/mlflow/tree/master/examples/pytorch/torchscript/IrisClassification + +### Setup +1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch `rm-mlflow` +2. Create an output model + +### Traning +1. Create a vs code IDE with pytorch 1.6 cpu image +2. cd to the code directory where we have the conda.yaml file +3. conda env create -f conda.yaml +4. conda activate pytorch-example +5. python iris_classification.py --code {code name} --output {output model name} + +### Building Image +1. Go to the model details page which was given as output in the above training run. A new version will be there in the version list. +2. Click on the build model image icon which is on the version's row at the right. +3. Select code +4. Select registry +5. Submit to create image build + +### Deployment +1. Select serving image which was build in the previous step. +2. Serving Port: 8000 +3. Serving Url Prefix: /invocations +4. Min CPU/Max CPU: 1 +5. Min Memory/Max Memory: 5G + +### Prediction +1. Copy the curl command from the deployment page and append --insecure +2. Change the data section to +--data-raw '{ "instances": [4.4, 3, 1.3, 0.2] \ No newline at end of file diff --git a/mlflow-pytorch/iris/iris_classification.py b/mlflow-pytorch/iris/iris_classification.py index ae35e29..8d2f3d0 100644 --- a/mlflow-pytorch/iris/iris_classification.py +++ b/mlflow-pytorch/iris/iris_classification.py @@ -20,10 +20,10 @@ def __init__(self): self.fc3 = nn.Linear(10, 3) def forward(self, x): - x = F.relu(self.fc1(x)) - x = F.relu(self.fc2(x)) - x = F.dropout(x, 0.2) - x = self.fc3(x) + x = F.relu(self.fc1(x.double())) + x = F.relu(self.fc2(x.double())) + x = F.dropout(x.double(), 0.2) + x = self.fc3(x.double()) return x @@ -53,7 +53,7 @@ def train_model(model, epochs, X_train, y_train): optimizer = torch.optim.Adam(model.parameters(), lr=0.01) for epoch in range(epochs): - out = model(X_train) + out = model(X_train.double()) loss = criterion(out, y_train).to(device) optimizer.zero_grad() loss.backward() @@ -68,7 +68,7 @@ def train_model(model, epochs, X_train, y_train): def test_model(model, X_test, y_test): model.eval() with torch.no_grad(): - predict_out = model(X_test) + predict_out = model(X_test.double()) _, predict_y = torch.max(predict_out, 1) print("\nprediction accuracy", float(accuracy_score(y_test.cpu(), predict_y.cpu()))) @@ -87,6 +87,7 @@ def test_model(model, X_test, y_test): args = parser.parse_args() model = IrisClassifier() + model.double() model = model.to(device) X_train, X_test, y_train, y_test, target_names = prepare_data() scripted_model = torch.jit.script(model) # scripting the model From da4c6a4299127acad7bede5c02397d56b1706d79 Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Mon, 11 Jul 2022 16:26:38 +0530 Subject: [PATCH 05/12] Update README.md --- mlflow/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlflow/README.md b/mlflow/README.md index 6cc87b5..4f80475 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -1,7 +1,7 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorflow/tf2 ### Setup -1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch -mlflow +1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch `rm-mlflow` 2. Create an output model ### Traning From 2b8f08803ce1bf4d51b8063fee9b789b739159aa Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Fri, 15 Jul 2022 14:29:37 +0530 Subject: [PATCH 06/12] Updated examples --- mlflow-pytorch/iris/README.md | 21 +++++++++----- mlflow-pytorch/iris/conda.yaml | 5 +++- mlflow-pytorch/iris/iris_classification.py | 7 +---- mlflow/README.md | 33 ++++++++++++++-------- mlflow/train_predict.py | 8 +----- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/mlflow-pytorch/iris/README.md b/mlflow-pytorch/iris/README.md index 4e623a5..602c2f9 100644 --- a/mlflow-pytorch/iris/README.md +++ b/mlflow-pytorch/iris/README.md @@ -9,14 +9,21 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/pytorch 2. cd to the code directory where we have the conda.yaml file 3. conda env create -f conda.yaml 4. conda activate pytorch-example -5. python iris_classification.py --code {code name} --output {output model name} +5. python iris_classification.py -### Building Image -1. Go to the model details page which was given as output in the above training run. A new version will be there in the version list. -2. Click on the build model image icon which is on the version's row at the right. -3. Select code -4. Select registry -5. Submit to create image build +## Building Image outside dkube +1. Download the model to local directory +``` +mlflow artifacts download -r -d +eg: mlflow artifacts download -r c263bdaa-9505-4dd5-81fa-f9dbf40190fc -d ./output +``` +2. Update the conda.yaml file in the downloaded path and add protobuf==3.19.4 in pip dependenicies +3. Run the below command to build the image +``` +mlflow models build-docker -n -m /decision-tree-classifier +eg: mlflow models build-docker -n lucifer001/mlflow-pytorch-demo:demo1 -m output/decision-tree-classifier +``` +4.Push the image ### Deployment 1. Select serving image which was build in the previous step. diff --git a/mlflow-pytorch/iris/conda.yaml b/mlflow-pytorch/iris/conda.yaml index 0bd9505..a9e3be7 100644 --- a/mlflow-pytorch/iris/conda.yaml +++ b/mlflow-pytorch/iris/conda.yaml @@ -10,5 +10,8 @@ dependencies: - boto3 - torchvision>=0.9.1 - torch>=1.9.0 - - git+https://github.com/oneconvergence/dkube.git@3.3.mp - mlflow +variables: + MLFLOW_TRACKING_INSECURE_TLS: "true" + MLFLOW_TRACKING_URI: ":32222>" + MLFLOW_TRACKING_TOKEN: "" \ No newline at end of file diff --git a/mlflow-pytorch/iris/iris_classification.py b/mlflow-pytorch/iris/iris_classification.py index 8d2f3d0..503f249 100644 --- a/mlflow-pytorch/iris/iris_classification.py +++ b/mlflow-pytorch/iris/iris_classification.py @@ -4,7 +4,6 @@ import torch.nn as nn import torch.nn.functional as F import os -from dkube.sdk import mlflow as m from sklearn.datasets import load_iris from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split @@ -80,9 +79,6 @@ def test_model(model, X_test, y_test): parser.add_argument( "--epochs", type=int, default=100, help="number of epochs to run (default: 100)" ) - parser.add_argument("--code", required=True, help="input code name") - parser.add_argument("--dataset", help="input dataset name") - parser.add_argument("--output", required=True, help="output model name") args = parser.parse_args() @@ -94,8 +90,7 @@ def test_model(model, X_test, y_test): scripted_model = train_model(scripted_model, args.epochs, X_train, y_train) test_model(scripted_model, X_test, y_test) - run_id= m.create_run(code=args.code, output=args.output) - with mlflow.start_run(run_id) as run: + with mlflow.start_run() as run: mlflow.pytorch.log_model(scripted_model, "model") # logging scripted model model_path = mlflow.get_artifact_uri("model") loaded_pytorch_model = mlflow.pytorch.load_model(model_path) # loading scripted model diff --git a/mlflow/README.md b/mlflow/README.md index 6cc87b5..48dbb17 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -4,22 +4,32 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorf 1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch -mlflow 2. Create an output model -### Traning +### Traning from VS code 1. Create a vs code IDE with tensorflow 2.6.0 cpu image 2. cd to the code directory where we have the requirements.txt file 3. pip3 install virtualenv 4. export PATH=$PATH:$HOME/.local/bin -5. virtualenv -p python3 env -6. . env/bin/activate -7. pip3 install -r requirements.txt -8. python train_predict.py --code {code name} --output {output model name} +5. export MLFLOW_TRACKING_INSECURE_TLS="true" +6. export MLFLOW_TRACKING_URI=":32222>" +7. export MLFLOW_TRACKING_TOKEN="" +8. virtualenv -p python3 env +9. . env/bin/activate +10. pip3 install -r requirements.txt +11. python train_predict.py -### Building Image -1. Go to the model details page which was given as output in the above training run. A new version will be there in the version list. -2. Click on the build model image icon which is on the version's row at the right. -3. Select code -4. Select registry -5. Submit to create image build +## Building Image outside dkube +1. Download the model to local directory +``` +mlflow artifacts download -r -d +eg: mlflow artifacts download -r c263bdaa-9505-4dd5-81fa-f9dbf40190fc -d ./output +``` +2. Update the conda.yaml file in the downloaded path and add protobuf==3.19.4 in pip dependenicies +3. Run the below command to build the image +``` +mlflow models build-docker -n -m /decision-tree-classifier +eg: mlflow models build-docker -n lucifer001/mlflow-sklearn-demo:demo1 -m output/decision-tree-classifier +``` +4.Push the image ### Deployment 1. Select serving image which was build in the previous step. @@ -35,4 +45,3 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorf "columns": ["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"], "data": [[5.1, 3.3, 1.7, 0.5], [5.9, 3.0, 4.2, 1.5], [6.9, 3.1, 5.4, 2.1]] }' - diff --git a/mlflow/train_predict.py b/mlflow/train_predict.py index 132f4a9..51a0f11 100644 --- a/mlflow/train_predict.py +++ b/mlflow/train_predict.py @@ -9,7 +9,6 @@ import tensorflow as tf from tensorflow import estimator as tf_estimator import mlflow.tensorflow -from dkube.sdk import mlflow as m import os TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv" @@ -69,9 +68,6 @@ def eval_input_fn(features, labels, batch_size): mlflow.tensorflow.autolog() parser = argparse.ArgumentParser() -parser.add_argument("--code", required=True, help="input code name") -parser.add_argument("--dataset", help="input dataset name") -parser.add_argument("--output", required=True, help="output model name") parser.add_argument("--batch_size", default=100, type=int, help="batch size") parser.add_argument("--train_steps", default=1000, type=int, help="number of training steps") @@ -79,8 +75,7 @@ def eval_input_fn(features, labels, batch_size): def main(argv): args = parser.parse_args(argv[1:]) - run_id = m.create_run(code=args.code, output=args.output) - with mlflow.start_run(run_id): + with mlflow.start_run(): # Fetch the data (train_x, train_y), (test_x, test_y) = load_data() @@ -181,4 +176,3 @@ def main(argv): if __name__ == "__main__": main(sys.argv) - From 8cf91dde1adf06f06e7e9bd5e1b739c3f9a51548 Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Mon, 18 Jul 2022 14:37:14 +0530 Subject: [PATCH 07/12] Update README.md --- mlflow-pytorch/iris/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mlflow-pytorch/iris/README.md b/mlflow-pytorch/iris/README.md index 602c2f9..3406ab9 100644 --- a/mlflow-pytorch/iris/README.md +++ b/mlflow-pytorch/iris/README.md @@ -20,8 +20,8 @@ eg: mlflow artifacts download -r c263bdaa-9505-4dd5-81fa-f9dbf40190fc -d ./outp 2. Update the conda.yaml file in the downloaded path and add protobuf==3.19.4 in pip dependenicies 3. Run the below command to build the image ``` -mlflow models build-docker -n -m /decision-tree-classifier -eg: mlflow models build-docker -n lucifer001/mlflow-pytorch-demo:demo1 -m output/decision-tree-classifier +mlflow models build-docker -n -m +eg: mlflow models build-docker -n lucifer001/mlflow-pytorch-demo:demo1 -m output/model ``` 4.Push the image @@ -35,4 +35,4 @@ eg: mlflow models build-docker -n lucifer001/mlflow-pytorch-demo:demo1 -m output ### Prediction 1. Copy the curl command from the deployment page and append --insecure 2. Change the data section to ---data-raw '{ "instances": [4.4, 3, 1.3, 0.2] \ No newline at end of file +--data-raw '{ "instances": [4.4, 3, 1.3, 0.2] }' From 498217e5cb064928276addfb01b9df9103432da4 Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Mon, 18 Jul 2022 14:41:25 +0530 Subject: [PATCH 08/12] Update README.md --- mlflow-pytorch/iris/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mlflow-pytorch/iris/README.md b/mlflow-pytorch/iris/README.md index 3406ab9..1ef59cc 100644 --- a/mlflow-pytorch/iris/README.md +++ b/mlflow-pytorch/iris/README.md @@ -2,15 +2,21 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/pytorch ### Setup 1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch `rm-mlflow` -2. Create an output model -### Traning +### Traning from VS code 1. Create a vs code IDE with pytorch 1.6 cpu image 2. cd to the code directory where we have the conda.yaml file 3. conda env create -f conda.yaml 4. conda activate pytorch-example 5. python iris_classification.py +## Training outside VS code +1. Install Conda v4.9 or latest +2. Clone this repo and update the conda.yaml file +3. conda env create -f conda.yaml +4. conda activate tensorflow-example +5. python train_predict.py + ## Building Image outside dkube 1. Download the model to local directory ``` From 417bffd8f0aabc5377a863cbe2729575b8d5a71e Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Mon, 18 Jul 2022 14:43:13 +0530 Subject: [PATCH 09/12] Update README.md --- mlflow-pytorch/iris/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlflow-pytorch/iris/README.md b/mlflow-pytorch/iris/README.md index 1ef59cc..c488056 100644 --- a/mlflow-pytorch/iris/README.md +++ b/mlflow-pytorch/iris/README.md @@ -14,8 +14,8 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/pytorch 1. Install Conda v4.9 or latest 2. Clone this repo and update the conda.yaml file 3. conda env create -f conda.yaml -4. conda activate tensorflow-example -5. python train_predict.py +4. conda activate pytorch-example +5. python iris_classification.py ## Building Image outside dkube 1. Download the model to local directory From 96221936d37106ff71d764293cfc8cfc7ee4f41b Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:09:56 +0530 Subject: [PATCH 10/12] Update README.md --- mlflow/README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mlflow/README.md b/mlflow/README.md index b192bf1..bc89094 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -4,7 +4,20 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorf 1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch `rm-mlflow` 2. Create an output model -### Traning from VS code +### Training from VS code inside DKube +1. curl https://pyenv.run | bash +2. exec "$SHELL" +3. export PATH=$HOME/.pyenv/bin:$PATH +4. pyenv install 3.7.2 +5. source $HOME/.pyenv/versions/env/bin/activate +6. pip install --upgrade pip +7. pip install -r requirements.txt +8. export MLFLOW_TRACKING_INSECURE_TLS="true" +9. export MLFLOW_TRACKING_URI=":32222>" +10. export MLFLOW_TRACKING_TOKEN="" +11. python train_predict.py + +### Traning from VS code outside DKube 1. Create a vs code IDE with tensorflow 2.6.0 cpu image 2. cd to the code directory where we have the requirements.txt file 3. pip3 install virtualenv @@ -16,7 +29,9 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorf 9. . env/bin/activate 10. pip3 install -r requirements.txt 11. python train_predict.py - + +`Note: Python 3.7 or higher version is required` + ## Building Image outside dkube 1. Download the model to local directory ``` From cad232da2ea05be6b45ede04c597040fb11c4144 Mon Sep 17 00:00:00 2001 From: Rahul Malhotra <53820555+rahul-179@users.noreply.github.com> Date: Wed, 27 Jul 2022 15:45:48 +0530 Subject: [PATCH 11/12] Update README.md --- mlflow/README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/mlflow/README.md b/mlflow/README.md index bc89094..386019a 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -5,20 +5,25 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorf 2. Create an output model ### Training from VS code inside DKube -1. curl https://pyenv.run | bash -2. exec "$SHELL" -3. export PATH=$HOME/.pyenv/bin:$PATH -4. pyenv install 3.7.2 -5. source $HOME/.pyenv/versions/env/bin/activate -6. pip install --upgrade pip -7. pip install -r requirements.txt -8. export MLFLOW_TRACKING_INSECURE_TLS="true" -9. export MLFLOW_TRACKING_URI=":32222>" -10. export MLFLOW_TRACKING_TOKEN="" -11. python train_predict.py +1. Create a vs code IDE with tensorflow 2.6.0 cpu image +2. cd to the code directory where we have the requirements.txt file +3. sudo apt-get update -y; sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ +libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \ +libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl +4. curl https://pyenv.run | bash +5. exec "$SHELL" +6. export PATH=$HOME/.pyenv/bin:$PATH +7. pyenv install 3.7.2 +8. pyenv virtualenv 3.7.2 env +9. source $HOME/.pyenv/versions/env/bin/activate +10. pip install --upgrade pip +11. pip install -r requirements.txt +12. export MLFLOW_TRACKING_INSECURE_TLS="true" +13. export MLFLOW_TRACKING_URI=":32222>" +14. export MLFLOW_TRACKING_TOKEN="" +15. python train_predict.py ### Traning from VS code outside DKube -1. Create a vs code IDE with tensorflow 2.6.0 cpu image 2. cd to the code directory where we have the requirements.txt file 3. pip3 install virtualenv 4. export PATH=$PATH:$HOME/.local/bin From bc7de1f7e8d5c082326b855cec0e91c0d12265ab Mon Sep 17 00:00:00 2001 From: rahul-179 Date: Tue, 25 Oct 2022 14:27:37 +0530 Subject: [PATCH 12/12] merge conflicts --- mlflow/README.md | 18 ++++++++++++++++-- mlflow/conda.yaml | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 mlflow/conda.yaml diff --git a/mlflow/README.md b/mlflow/README.md index 386019a..1b0eedf 100644 --- a/mlflow/README.md +++ b/mlflow/README.md @@ -1,9 +1,16 @@ Example taken from https://github.com/mlflow/mlflow/tree/master/examples/tensorflow/tf2 ### Setup -1. Create a code with url- https://github.com/rahul-179/dkubeio-examples/tree/mlflow/mlflow branch `rm-mlflow` +1. Create a code with url- https://github.com/oneconvergence/dkubeio-examples/tree/mlflow/mlflow branch -mlflow 2. Create an output model +### Training with Conda environment +1. Create a vs code IDE with tensorflow 2.6.0 cpu image +2. cd to the code directory where we have the conda.yaml file +3. conda env create -f conda.yaml +4. conda activate tensorflow-example +5. python train_predict.py --code {code name} --output {output model name} + ### Training from VS code inside DKube 1. Create a vs code IDE with tensorflow 2.6.0 cpu image 2. cd to the code directory where we have the requirements.txt file @@ -36,8 +43,15 @@ libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl 11. python train_predict.py `Note: Python 3.7 or higher version is required` + +### Building Image inside DKube +1. Go to the model details page which was given as output in the above training run. A new version will be there in the version list. +2. Click on the build model image icon which is on the version's row at the right. +3. Select code +4. Select registry +5. Submit to create image build -## Building Image outside dkube +### Building Image outside DKube 1. Download the model to local directory ``` mlflow artifacts download -r -d diff --git a/mlflow/conda.yaml b/mlflow/conda.yaml new file mode 100644 index 0000000..59217ae --- /dev/null +++ b/mlflow/conda.yaml @@ -0,0 +1,15 @@ +name: tensorflow-example +channels: + - conda-forge +dependencies: + - python=3.7 + - pip + - pip: + - mlflow + - tensorflow==2.0.0 + - protobuf==3.19.4 + - boto3 +variables: + MLFLOW_TRACKING_INSECURE_TLS: "true" + MLFLOW_TRACKING_URI: ":32222>" + MLFLOW_TRACKING_TOKEN: "" \ No newline at end of file