Skip to content

Added unit tests #3532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 42 commits into from
Closed
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
38c11b5
Added unit tests
Tarun-Chevula Oct 29, 2024
46e328c
Update
Tarun-Chevula Oct 29, 2024
6dc646d
Update
Tarun-Chevula Oct 29, 2024
02a17d0
Update
Tarun-Chevula Oct 29, 2024
b249438
Updated conda dependencies
Tarun-Chevula Oct 29, 2024
27f4ba8
Updated pyarrow in requirements and mlflow in conda dependencies
Tarun-Chevula Oct 29, 2024
cf5ab87
Update
Tarun-Chevula Oct 29, 2024
a1db916
Updated pyarrow in conda dependencies
Tarun-Chevula Oct 29, 2024
2686a76
Added 6 pandas unit tests
Tarun-Chevula Oct 30, 2024
9bf6ebd
Update
Tarun-Chevula Oct 30, 2024
9c0b083
Added pyarrow installation in Dockerfile
Tarun-Chevula Nov 4, 2024
fa547c3
Update
Tarun-Chevula Nov 4, 2024
46224fa
Update
Tarun-Chevula Nov 4, 2024
0717cce
Updated requirements.txt
Tarun-Chevula Nov 5, 2024
8cafc46
Update
Tarun-Chevula Nov 5, 2024
1f40de9
Updating pandas
Tarun-Chevula Nov 5, 2024
57818f7
Updated test_mlflow_unit
Tarun-Chevula Nov 5, 2024
400b555
Update
Tarun-Chevula Nov 5, 2024
aabee3f
Update
Tarun-Chevula Nov 5, 2024
c460407
Update
Tarun-Chevula Nov 5, 2024
4144344
Update reuirements.txt
Tarun-Chevula Nov 6, 2024
41b6c8c
Reverted Dockerfile changes
Tarun-Chevula Nov 7, 2024
a89e708
Added pytest
Tarun-Chevula Nov 11, 2024
2763cb1
Update
Tarun-Chevula Nov 11, 2024
f389aff
Update
Tarun-Chevula Nov 11, 2024
ba5b980
Update
Tarun-Chevula Nov 11, 2024
13cef6b
Merge branch 'Tarun/unit-tests' of https://github.com/Azure/azureml-a…
Tarun-Chevula Nov 11, 2024
bc4e38c
Update
Tarun-Chevula Nov 11, 2024
2afa190
Update
Tarun-Chevula Nov 11, 2024
26f004f
Update
Tarun-Chevula Nov 11, 2024
39a1033
Update
Tarun-Chevula Nov 11, 2024
57c733c
Update
Tarun-Chevula Nov 11, 2024
f33e1f9
Update
Tarun-Chevula Nov 11, 2024
9e7c9ea
Update
Tarun-Chevula Nov 11, 2024
3e05ce0
Update
Tarun-Chevula Nov 11, 2024
a225514
Update
Tarun-Chevula Nov 11, 2024
e02cf30
Update
Tarun-Chevula Nov 12, 2024
a99afd2
Update
Tarun-Chevula Nov 12, 2024
79a1e64
Update
Tarun-Chevula Nov 12, 2024
65d0455
Update
Tarun-Chevula Nov 12, 2024
9eb5c7a
Update
Tarun-Chevula Nov 12, 2024
2978d05
Update
Tarun-Chevula Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ COPY conda_dependencies.yaml .
RUN conda env create -p $AZUREML_CONDA_ENVIRONMENT_PATH -f conda_dependencies.yaml -q && \
rm conda_dependencies.yaml && \
conda run -p $AZUREML_CONDA_ENVIRONMENT_PATH pip cache purge && \
conda clean -a -y
conda clean -a -y

USER dockeruser

CMD [ "runsvdir", "/var/runit" ]
Original file line number Diff line number Diff line change
@@ -2,8 +2,20 @@ name: mlflow
channels:
- conda-forge
- anaconda
- defaults
dependencies:
- python=3.9.13
- numpy # NumPy for pyarrow
- pyarrow=14.0.0 # PyArrow for Apache Arrow Python bindings
- cmake # System dependency for building C++ libraries
- boost # Boost libraries needed by Arrow C++
- protobuf # Protocol Buffers (for Arrow's serialization)
- libcurl # Curl libraries (for Arrow)
- openssl # OpenSSL libraries (for Arrow)
- zlib # Compression libraries (for Arrow)
- pip
- pip:
- azureml-inference-server-http=={{latest-pypi-version}}
- azureml-inference-server-http=={{latest-pypi-version}}
- azureml-mlflow=={{latest-pypi-version}}
- pyarrow
- numpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""Tests running a sample job in the mlflow 20.04 py39 cpu environment."""
import os
import time
from pathlib import Path
from azure.ai.ml import command, MLClient
from azure.ai.ml._restclient.models import JobStatus
from azure.ai.ml.entities import Environment, BuildContext
from azure.identity import AzureCliCredential

BUILD_CONTEXT = Path("../context")
JOB_SOURCE_CODE = "src"
TIMEOUT_MINUTES = os.environ.get("timeout_minutes", 30)
STD_LOG = Path("artifacts/user_logs/std_log.txt")


def test_minimal_cpu_inference():
"""Tests a sample job using minimal 20.04 py39 cpu as the environment."""
this_dir = Path(__file__).parent

subscription_id = os.environ.get("subscription_id")
resource_group = os.environ.get("resource_group")
workspace_name = os.environ.get("workspace")

ml_client = MLClient(
AzureCliCredential(), subscription_id, resource_group, workspace_name
)

env_name = "minimal_cpu_inference"

env_docker_context = Environment(
build=BuildContext(path=this_dir / BUILD_CONTEXT),
name="minimal_cpu_inference",
description="minimal 20.04 py39 cpu inference environment created from a Docker context.",
)
ml_client.environments.create_or_update(env_docker_context)

# create the command
job = command(
code=this_dir / JOB_SOURCE_CODE, # local path where the code is stored
command="pytest mlflow_main.py --score ${{inputs.score}}",
inputs=dict(
score="valid_score.py",
),
environment=f"{env_name}@latest",
compute=os.environ.get("cpu_cluster"),
display_name="minimal-cpu-inference-example",
description="A test run of the minimal 20.04 py39 cpu inference curated environment",
experiment_name="minimalCPUInferenceExperiment"
)

returned_job = ml_client.create_or_update(job)
assert returned_job is not None

# Poll until final status is reached or timed out
timeout = time.time() + (TIMEOUT_MINUTES * 60)
while time.time() <= timeout:
job = ml_client.jobs.get(returned_job.name)
status = job.status
if status in [JobStatus.COMPLETED, JobStatus.FAILED]:
break
time.sleep(30) # sleep 30 seconds
else:
# Timeout
ml_client.jobs.cancel(returned_job.name)
raise Exception(f"Test aborted because the job took longer than {TIMEOUT_MINUTES} minutes. "
f"Last status was {status}.")

if status == JobStatus.FAILED:
ml_client.jobs.download(returned_job.name)
if STD_LOG.exists():
print(f"*** BEGIN {STD_LOG} ***")
with open(STD_LOG, "r") as f:
print(f.read(), end="")
print(f"*** END {STD_LOG} ***")
else:
ml_client.jobs.stream(returned_job.name)

assert status == JobStatus.COMPLETED
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
azure-ai-ml==1.2.0
azure.identity
requests
cython
pyarrow==14.0.0
numpy
setuptools
azure-ai-ml==0.1.0b4
azure.identity==1.10.0
requests==2.31.0
azureml-mlflow
mlflow
pytest
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
channels:
- conda-forge
dependencies:
- python=3.9.17
- pip
- pip:
- mlflow
- cloudpickle==2.2.1
name: mlflow-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mlflow
cloudpickle==2.2.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"input_data":{"columns":["a", "b"],"index":[0],"data":[[2, 1]]}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""For mlflow main tests."""
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import json
import os
from datetime import timedelta
import pytest

from utils import run_score_path_azmlinfsrv

DEFAULT_MODEL_DIR_NAME = "/var/model_dir"


@pytest.mark.skip(reason="Need infrastructure to build image for testing")
def test_score_path_azmlinfsrv_mlflow_before_2_0(inference_image_name, resource_directory, score_script):
"""For testing the scoring request gives proper response for mflow toy model."""
env_vars = {
"AZUREML_MODEL_DIR": DEFAULT_MODEL_DIR_NAME,
"MLFLOW_MODEL_FOLDER": "mlflow_model_folder",
"AZUREML_EXTRA_CONDA_YAML_ABS_PATH": DEFAULT_MODEL_DIR_NAME + "/mlflow_model_folder/conda.yaml",
}

data_path = os.path.join("..", "resources", "mlflow", "sample_input.json")

with open(data_path) as f:
payload_data = json.load(f)

req = run_score_path_azmlinfsrv(
inference_image_name,
resource_directory,
env_vars,
payload_data=payload_data,
check_text=False,
overwrite_azuremlapp=False,
custom_payload=True,
poll_timeout=timedelta(seconds=480),
)

print(req._content)
assert req.status_code == 200
assert json.loads(req._content)[0] == {"0": 0}