Skip to content

Commit

Permalink
Merge branch 'main' into test-ml-sdk-version-ml-1.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
diondrapeck authored Oct 17, 2023
2 parents 3235ebb + 815379d commit 91a9d70
Show file tree
Hide file tree
Showing 39 changed files with 2,488 additions and 2 deletions.
45 changes: 45 additions & 0 deletions cli/endpoints/online/deploy-with-packages/custom-model/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#<register_model>
MODEL_NAME='sklearn-regression'
MODEL_PATH='model'
az ml model create --name $MODEL_NAME --path $MODEL_PATH --type custom_model
#</register_model>

#<base_environment>
az ml environment create -f environment/sklearn-regression-env.yml
#</base_environment>

#<build_package>
az ml model package -n $MODEL_NAME -l latest --file package-moe.yml
#</build_package>

#<endpoint_name>
ENDPOINT_NAME = "sklearn-regression-online"
#</endpoint_name>

# The following code ensures the created deployment has a unique name
ENDPOINT_SUFIX=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-5} | head -n 1)
ENDPOINT_NAME="$ENDPOINT_NAME-$ENDPOINT_SUFIX"

#<create_endpoint>
az ml online-endpoint create -n $ENDPOINT_NAME
#</create_endpoint>

#<create_deployment>
az ml online-deployment create -f deployment.yml
#</create_deployment>

#<test_deployment>
az ml online-endpoint invoke -n $ENDPOINT_NAME -d with-package -f sample-request.json
#</test_deployment>

#<create_deployment_with_package>
az ml online-deployment create -f model-deployment.yml --with-package
#</create_deployment_with_package>

#<delete_resources>
az ml online-endpoint delete -n $ENDPOINT_NAME --yes
#</delete_resources>

#<build_package_copy>
az ml model package -n $MODEL_NAME -l latest --file package-external.yml
#</build_package_copy>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: with-package
endpoint_name: hello-packages
environment: azureml:sklearn-regression-online-pkg@latest
instance_type: Standard_DS3_v2
instance_count: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
name: hello-packages
auth_mode: key
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: model-env
channels:
- conda-forge
dependencies:
- python=3.9
- numpy=1.23.5
- pip=23.0.1
- scikit-learn=1.2.2
- scipy=1.10.1
- xgboost==1.3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$schema: https://azuremlschemas.azureedge.net/latest/environment.schema.json
name: sklearn-regression-env
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04
conda_file: conda.yaml
description: An environment for models built with XGBoost and Scikit-learn.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: with-package
endpoint_name: hello-packages
model: azureml:sklearn-regression@latest
environment: azureml:sklearn-regression-env@latest
code_configuration:
code: src
scoring_script: score.py
instance_type: Standard_DS3_v2
instance_count: 1
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$schema: http://azureml/sdk-2-0/ModelVersionPackage.json
base_environment_source:
type: environment_asset
resource_id: azureml:sklearn-regression-env@latest
target_environment_name: sklearn-regression-docker-pkg
inferencing_server:
type: azureml_online
code_configuration:
code: src
entry_script: score.py
model_configuration:
mode: copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$schema: http://azureml/sdk-2-0/ModelVersionPackage.json
base_environment_source:
type: environment_asset
resource_id: azureml:sklearn-regression-env@latest
target_environment_name: sklearn-regression-online-pkg
inferencing_server:
type: azureml_online
code_configuration:
code: src
entry_script: score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": [
[1,2,3,4,5,6,7,8,9,10],
[10,9,8,7,6,5,4,3,2,1]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import logging
import json
import numpy
import joblib


def init():
"""
This function is called when the container is initialized/started, typically after create/update of the deployment.
You can write the logic here to perform init operations like caching the model in memory
"""
global model
# AZUREML_MODEL_DIR is an environment variable created during deployment.
# It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)
# Please provide your model's folder name if there is one
model_path = os.path.join(
os.getenv("AZUREML_MODEL_DIR"), "model/sklearn_regression_model.pkl"
)
# deserialize the model file back into a sklearn model
model = joblib.load(model_path)
logging.info("Init complete")


def run(raw_data):
"""
This function is called for every invocation of the endpoint to perform the actual scoring/prediction.
In the example we extract the data from the json input and call the scikit-learn model's predict()
method and return the result back
"""
logging.info("model 1: request received")
data = json.loads(raw_data)["data"]
data = numpy.array(data)
result = model.predict(data)
logging.info("Request processed")
return result.tolist()
41 changes: 41 additions & 0 deletions cli/endpoints/online/deploy-with-packages/mlflow-model/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#<register_model>
MODEL_NAME='heart-classifier-mlflow'
MODEL_PATH='model'
az ml model create --name $MODEL_NAME --path $MODEL_PATH --type mlflow_model
#</register_model>

#<build_package>
az ml model package -n $MODEL_NAME -l latest --file package.yml
#</build_package>

#<endpoint_name>
ENDPOINT_NAME = "heart-classifier"
#</endpoint_name>

# The following code ensures the created deployment has a unique name
ENDPOINT_SUFIX=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-5} | head -n 1)
ENDPOINT_NAME="$ENDPOINT_NAME-$ENDPOINT_SUFIX"

#<create_endpoint>
az ml online-endpoint create -n $ENDPOINT_NAME
#</create_endpoint>

#<create_deployment>
az ml online-deployment create -f deployment.yml -e $ENDPOINT_NAME
#</create_deployment>

#<test_deployment>
az ml online-endpoint invoke -n $ENDPOINT_NAME -d with-package -f sample-request.json
#</test_deployment>

#<create_deployment_inline>
az ml online-deployment create -f model-deployment.yml -e $ENDPOINT_NAME
#</create_deployment_inline>

#<delete_resources>
az ml online-endpoint delete -n $ENDPOINT_NAME --yes
#</delete_resources>

#<build_package_copy>
az ml model package -n $MODEL_NAME -l latest --file package-external.yml
#</build_package_copy>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: with-package
endpoint_name: heart-classifier
environment: azureml:heart-classifier-mlflow-pkg@latest
instance_type: Standard_DS3_v2
instance_count: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
name: heart-classifier
auth_mode: key
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: with-package-inline
endpoint_name: heart-classifier-mlflow
model: azureml:heart-classifier-mlflow@latest
instance_type: Standard_DS3_v2
instance_count: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
artifact_path: pipeline
flavors:
python_function:
env: conda.yaml
loader_module: mlflow.sklearn
model_path: model.pkl
python_version: 3.8.5
sklearn:
pickled_model: model.pkl
serialization_format: cloudpickle
sklearn_version: 1.1.2
model_uuid: 04bd660a1b8b4b1e84b9198c46cfd117
run_id: 22874b7e-b069-43f0-b90c-1c57793c7854
signature:
inputs: '[{"name": "age", "type": "long"}, {"name": "sex", "type": "long"},
{"name": "cp", "type": "long"}, {"name": "trestbps", "type": "long"}, {"name":
"chol", "type": "long"}, {"name": "fbs", "type": "long"}, {"name": "restecg",
"type": "long"}, {"name": "thalach", "type": "long"}, {"name": "exang", "type":
"long"}, {"name": "oldpeak", "type": "double"}, {"name": "slope", "type": "long"},
{"name": "ca", "type": "long"}, {"name": "thal", "type": "string"}]'
outputs: '[{"type": "long"}]'
utc_time_created: '2022-10-13 00:55:57.543663'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
channels:
- conda-forge
dependencies:
- python=3.8.5
- pip
- pip:
- mlflow
- cloudpickle==1.6.0
- scikit-learn==1.1.2
- xgboost==1.3.3
name: mlflow-env
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mlflow
cloudpickle==1.6.0
colorama==0.4.4
dask==2.30.0
dataclasses==0.6
lz4==4.0.0
psutil==5.9.0
scikit-learn==1.1.2
sparse==0.13.0
tblib==1.7.0
toolz==0.11.2
typing-extensions==4.1.1
uuid==1.30
xgboost==1.4.2
xxhash==3.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: http://azureml/sdk-2-0/ModelVersionPackage.json
target_environment_name: heart-classifier-mlflow-pkg
inferencing_server:
type: azureml_online
model_configuration:
mode: copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$schema: http://azureml/sdk-2-0/ModelVersionPackage.json
target_environment_name: heart-classifier-mlflow-pkg
inferencing_server:
type: azureml_online
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"input_data": {
"columns": [
"age", "sex", "cp", "trestbps", "chol", "fbs", "restecg", "thalach", "exang", "oldpeak", "slope", "ca", "thal"
],
"index": [1],
"data": [
[1, 1, 4, 145, 233, 1, 2, 150, 0, 2.3, 3, 0, 2]
]
}
}
11 changes: 11 additions & 0 deletions cli/endpoints/online/deploy-with-packages/registry-model/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#<get_model>
MODEL_NAME="t5-base"
MODEL_VERSION=$(az ml model show --name $MODEL_NAME --label latest --registry-name azureml | jq .version -r)
#</get_model>

#<build_package>
az ml model package --name $MODEL_NAME \
--version $MODEL_VERSION \
--registry-name azureml \
--file package.yml
#</build_package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$schema: http://azureml/sdk-2-0/ModelVersionPackage.json
target_environment_name: pkg-t5-base-online
inferencing_server:
type: azureml_online
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: model-env
channels:
- conda-forge
dependencies:
- python=3.9
- numpy=1.23.5
- pip=23.0.1
- scikit-learn=1.2.2
- scipy=1.10.1
- xgboost==1.3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$schema: https://azuremlschemas.azureedge.net/latest/environment.schema.json
name: sklearn-regression-env
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04
conda_file: conda.yaml
description: An environment for models built with XGBoost and Scikit-learn.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": [
[1,2,3,4,5,6,7,8,9,10],
[10,9,8,7,6,5,4,3,2,1]
]
}
Loading

0 comments on commit 91a9d70

Please sign in to comment.