Skip to content

Commit 5344961

Browse files
Merge pull request #228029 from santiagxf/santiagxf/mlflow-online-ref
Update how-to-deploy-mlflow-models-online-endpoints.md
2 parents 84fb2a4 + e9647e8 commit 5344961

File tree

1 file changed

+4
-46
lines changed

1 file changed

+4
-46
lines changed

articles/machine-learning/how-to-deploy-mlflow-models-online-endpoints.md

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -565,35 +565,7 @@ Use the following steps to deploy an MLflow model with a custom scoring script.
565565
566566
__score.py__
567567
568-
```python
569-
import logging
570-
import mlflow
571-
import os
572-
from io import StringIO
573-
from mlflow.pyfunc.scoring_server import infer_and_parse_json_input, predictions_to_json
574-
575-
def init():
576-
global model
577-
global input_schema
578-
# The path 'model' corresponds to the path where the MLflow artifacts where stored when
579-
# registering the model using MLflow format.
580-
model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'model')
581-
model = mlflow.pyfunc.load_model(model_path)
582-
input_schema = model.metadata.get_input_schema()
583-
584-
def run(raw_data):
585-
json_data = json.loads(raw_data)
586-
if "input_data" not in json_data.keys():
587-
raise Exception("Request must contain a top level key named 'input_data'")
588-
589-
serving_input = json.dumps(json_data["input_data"])
590-
data = infer_and_parse_json_input(serving_input, input_schema)
591-
result = model.predict(data)
592-
593-
result = StringIO()
594-
predictions_to_json(raw_predictions, result)
595-
return result.getvalue()
596-
```
568+
:::code language="python" source="~/azureml-examples-main/cli/endpoints/online/ncd/sklearn-diabetes/src/score.py" highlight="14":::
597569
598570
> [!TIP]
599571
> The previous scoring script is provided as an example about how to perform inference of an MLflow model. You can adapt this example to your needs or change any of its parts to reflect your scenario.
@@ -607,21 +579,7 @@ Use the following steps to deploy an MLflow model with a custom scoring script.
607579
608580
__conda.yml__
609581
610-
```yaml
611-
channels:
612-
- conda-forge
613-
dependencies:
614-
- python=3.7.11
615-
- pip
616-
- pip:
617-
- mlflow
618-
- scikit-learn==0.24.1
619-
- cloudpickle==2.0.0
620-
- psutil==5.8.0
621-
- pandas==1.3.5
622-
- azureml-inference-server-http
623-
name: mlflow-env
624-
```
582+
:::code language="yaml" source="~/azureml-examples-main/cli/endpoints/online/ncd/sklearn-diabetes/environment/conda.yml":::
625583
626584
> [!NOTE]
627585
> Note how the package `azureml-inference-server-http` has been added to the original conda dependencies file.
@@ -673,9 +631,9 @@ Use the following steps to deploy an MLflow model with a custom scoring script.
673631
model: azureml:sklearn-diabetes@latest
674632
environment:
675633
image: mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04
676-
conda_file: mlflow/sklearn-diabetes/environment/conda.yml
634+
conda_file: sklearn-diabetes/environment/conda.yml
677635
code_configuration:
678-
code: mlflow/sklearn-diabetes/src
636+
code: sklearn-diabetes/src
679637
scoring_script: score.py
680638
instance_type: Standard_F2s_v2
681639
instance_count: 1

0 commit comments

Comments
 (0)