diff --git a/configuration.ipynb b/configuration.ipynb index 5c397d80..93aca3a2 100644 --- a/configuration.ipynb +++ b/configuration.ipynb @@ -103,7 +103,7 @@ "source": [ "import azureml.core\n", "\n", - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/README.md b/how-to-use-azureml/README.md index 0accac07..37274e1a 100644 --- a/how-to-use-azureml/README.md +++ b/how-to-use-azureml/README.md @@ -9,7 +9,6 @@ As a pre-requisite, run the [configuration Notebook](../configuration.ipynb) not * [train-on-amlcompute](./training/train-on-amlcompute): Use a 1-n node Azure ML managed compute cluster for remote runs on Azure CPU or GPU infrastructure. * [train-on-remote-vm](./training/train-on-remote-vm): Use Data Science Virtual Machine as a target for remote runs. * [logging-api](./track-and-monitor-experiments/logging-api): Learn about the details of logging metrics to run history. -* [production-deploy-to-aks](./deployment/production-deploy-to-aks) Deploy a model to production at scale on Azure Kubernetes Service. * [enable-app-insights-in-production-service](./deployment/enable-app-insights-in-production-service) Learn how to use App Insights with production web service. Find quickstarts, end-to-end tutorials, and how-tos on the [official documentation site for Azure Machine Learning service](https://docs.microsoft.com/en-us/azure/machine-learning/service/). diff --git a/how-to-use-azureml/automated-machine-learning/automl_env.yml b/how-to-use-azureml/automated-machine-learning/automl_env.yml index 95a40397..9ffb33b3 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env.yml @@ -7,19 +7,21 @@ dependencies: # The python interpreter version. # Azure ML only supports 3.8 and later. - pip==22.3.1 -- python>=3.9,<3.10 +- python>=3.10,<3.11 - holidays==0.29 - scipy==1.10.1 - tqdm==4.66.1 - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.55.0 - - azureml-defaults~=1.55.0 - - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.55.0/validated_win32_requirements.txt [--no-deps] + - azureml-widgets~=1.56.0 + - azureml-defaults~=1.56.0 + - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.56.0/validated_win32_requirements.txt [--no-deps] - matplotlib==3.7.1 - - xgboost==1.3.3 + - xgboost==1.5.2 - prophet==1.1.4 - pandas==1.3.5 - cmdstanpy==1.1.0 - setuptools-git==1.2 + - spacy==3.4.4 + - https://aka.ms/automl-resources/packages/en_core_web_sm-3.4.1.tar.gz diff --git a/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml b/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml index cffceb3b..b7a0b10a 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env_linux.yml @@ -7,13 +7,12 @@ dependencies: # The python interpreter version. # Azure ML only supports 3.7 and later. - pip==22.3.1 -- python>=3.9,<3.10 +- python>=3.10,<3.11 - matplotlib==3.7.1 - numpy>=1.21.6,<=1.23.5 - urllib3==1.26.7 - scipy==1.10.1 -- scikit-learn=1.1.3 -- py-xgboost<=1.3.3 +- scikit-learn==1.1.3 - holidays==0.29 - pytorch::pytorch=1.11.0 - cudatoolkit=10.1.243 @@ -21,10 +20,11 @@ dependencies: - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.55.0 - - azureml-defaults~=1.55.0 + - azureml-widgets~=1.56.0 + - azureml-defaults~=1.56.0 - pytorch-transformers==1.0.0 - - spacy==2.3.9 + - spacy==3.4.4 + - xgboost==1.5.2 - prophet==1.1.4 - - https://aka.ms/automl-resources/packages/en_core_web_sm-2.3.1.tar.gz - - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.55.0/validated_linux_requirements.txt [--no-deps] + - https://aka.ms/automl-resources/packages/en_core_web_sm-3.4.1.tar.gz + - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.56.0/validated_linux_requirements.txt [--no-deps] diff --git a/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml b/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml index 7503bf45..bac39513 100644 --- a/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml +++ b/how-to-use-azureml/automated-machine-learning/automl_env_mac.yml @@ -7,7 +7,7 @@ dependencies: # The python interpreter version. # Currently Azure ML only supports 3.7 and later. - pip==22.3.1 -- python>=3.9,<3.10 +- python>=3.10,<3.11 - numpy>=1.21.6,<=1.23.5 - scipy==1.10.1 - scikit-learn==1.1.3 @@ -15,12 +15,12 @@ dependencies: - pip: # Required packages for AzureML execution, history, and data preparation. - - azureml-widgets~=1.55.0 - - azureml-defaults~=1.55.0 + - azureml-widgets~=1.56.0 + - azureml-defaults~=1.56.0 - pytorch-transformers==1.0.0 - prophet==1.1.4 - - xgboost==1.3.3 - - spacy==2.3.9 + - xgboost==1.5.2 + - spacy==3.4.4 - matplotlib==3.7.1 - - https://aka.ms/automl-resources/packages/en_core_web_sm-2.3.1.tar.gz - - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.55.0/validated_darwin_requirements.txt [--no-deps] + - https://aka.ms/automl-resources/packages/en_core_web_sm-3.4.1.tar.gz + - -r https://automlsdkdataresources.blob.core.windows.net/validated-requirements/1.56.0/validated_darwin_requirements.txt [--no-deps] diff --git a/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.yml b/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.yml deleted file mode 100644 index 0f30214b..00000000 --- a/how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-classification-bank-marketing-all-features -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.yml b/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.yml deleted file mode 100644 index 148f33d5..00000000 --- a/how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-classification-credit-card-fraud -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.yml b/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.yml deleted file mode 100644 index 9b05ea1f..00000000 --- a/how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-continuous-retraining -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/experimental/README.md b/how-to-use-azureml/automated-machine-learning/experimental/README.md index 566f9999..ba276ef2 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/README.md +++ b/how-to-use-azureml/automated-machine-learning/experimental/README.md @@ -9,7 +9,7 @@ To run these notebook on your own notebook server, use these installation instru The instructions below will install everything you need and then start a Jupyter notebook. If you would like to use a lighter-weight version of the client that does not install all of the machine learning libraries locally, you can leverage the [experimental notebooks.](experimental/README.md) -### 1. Install mini-conda from [here](https://conda.io/miniconda.html), choose 64-bit Python 3.7 or higher. +### 1. Install mini-conda from [here](https://conda.io/miniconda.html), choose 64-bit Python 3.8 or higher. - **Note**: if you already have conda installed, you can keep using it but it should be version 4.4.10 or later (as shown by: conda -V). If you have a previous version installed, you can update it using the command: conda update conda. There's no need to install mini-conda specifically. diff --git a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.ipynb index c8225742..6af7da1e 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.ipynb +++ b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.ipynb @@ -97,7 +97,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, @@ -148,7 +148,7 @@ "from azureml.core.compute_target import ComputeTargetException\n", "\n", "# Choose a name for your CPU cluster\n", - "cpu_cluster_name = \"cpu-cluster\"\n", + "cpu_cluster_name = \"cpu-codegen\"\n", "\n", "# Verify that cluster does not exist already\n", "try:\n", diff --git a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.yml b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.yml deleted file mode 100644 index 5e63282d..00000000 --- a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-codegen/codegen-for-autofeaturization.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: codegen-for-autofeaturization -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.ipynb index d3b29f34..c4e13504 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.ipynb +++ b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.ipynb @@ -97,7 +97,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.yml b/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.yml deleted file mode 100644 index f12506cc..00000000 --- a/how-to-use-azureml/automated-machine-learning/experimental/autofeaturization-custom-model-training/custom-model-training-from-autofeaturization-run.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: custom-model-training-from-autofeaturization-run -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb index 079432d7..1c2e67ff 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb +++ b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.ipynb @@ -92,7 +92,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml b/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml deleted file mode 100644 index 1f2ef5b4..00000000 --- a/how-to-use-azureml/automated-machine-learning/experimental/classification-credit-card-fraud-local-managed/auto-ml-classification-credit-card-fraud-local-managed.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-classification-credit-card-fraud-local-managed -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb b/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb index 11d03a73..624f078c 100644 --- a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb +++ b/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb @@ -91,7 +91,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.yml b/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.yml deleted file mode 100644 index e5d127ea..00000000 --- a/how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-regression-model-proxy -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-backtest-many-models/auto-ml-forecasting-backtest-many-models.yml b/how-to-use-azureml/automated-machine-learning/forecasting-backtest-many-models/auto-ml-forecasting-backtest-many-models.yml deleted file mode 100644 index 55b2188d..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-backtest-many-models/auto-ml-forecasting-backtest-many-models.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-backtest-many-models -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-backtest-single-model/auto-ml-forecasting-backtest-single-model.yml b/how-to-use-azureml/automated-machine-learning/forecasting-backtest-single-model/auto-ml-forecasting-backtest-single-model.yml deleted file mode 100644 index 6871fafb..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-backtest-single-model/auto-ml-forecasting-backtest-single-model.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-backtest-single-model -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.yml b/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.yml deleted file mode 100644 index 70a3271c..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-bike-share -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.yml b/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.yml deleted file mode 100644 index 13bd78f8..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-energy-demand -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.yml b/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.yml deleted file mode 100644 index 144797d6..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-forecast-function/auto-ml-forecasting-function.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-function -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-github-dau/auto-ml-forecasting-github-dau.yml b/how-to-use-azureml/automated-machine-learning/forecasting-github-dau/auto-ml-forecasting-github-dau.yml deleted file mode 100644 index eee39bd4..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-github-dau/auto-ml-forecasting-github-dau.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-github-dau -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-hierarchical-timeseries/auto-ml-forecasting-hierarchical-timeseries.yml b/how-to-use-azureml/automated-machine-learning/forecasting-hierarchical-timeseries/auto-ml-forecasting-hierarchical-timeseries.yml deleted file mode 100644 index 8a3162f3..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-hierarchical-timeseries/auto-ml-forecasting-hierarchical-timeseries.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-hierarchical-timeseries -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-many-models/auto-ml-forecasting-many-models.yml b/how-to-use-azureml/automated-machine-learning/forecasting-many-models/auto-ml-forecasting-many-models.yml deleted file mode 100644 index a9e06f92..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-many-models/auto-ml-forecasting-many-models.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-many-models -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.yml b/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.yml deleted file mode 100644 index a6cc3e71..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-orange-juice-sales -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-pipelines/auto-ml-forecasting-pipelines.yml b/how-to-use-azureml/automated-machine-learning/forecasting-pipelines/auto-ml-forecasting-pipelines.yml deleted file mode 100644 index 48d7667f..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-pipelines/auto-ml-forecasting-pipelines.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-pipelines -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-experiment-settings.yml b/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-experiment-settings.yml deleted file mode 100644 index 419cde19..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-experiment-settings.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-univariate-recipe-experiment-settings -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-run-experiment.yml b/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-run-experiment.yml deleted file mode 100644 index a370fe3a..00000000 --- a/how-to-use-azureml/automated-machine-learning/forecasting-recipes-univariate/auto-ml-forecasting-univariate-recipe-run-experiment.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-forecasting-univariate-recipe-run-experiment -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb b/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb index 10922c41..22f5a2c8 100644 --- a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb +++ b/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.ipynb @@ -570,273 +570,6 @@ "automl_run.upload_file(\"outputs/scoring_explainer.pkl\", scoring_explainer_file_name)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploying the scoring and explainer models to a web service to Azure Kubernetes Service (AKS)\n", - "\n", - "We use the TreeScoringExplainer from azureml.interpret package to create the scoring explainer which will be used to compute the raw and engineered feature importances at the inference time. In the cell below, we register the AutoML model and the scoring explainer with the Model Management Service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Register trained automl model present in the 'outputs' folder in the artifacts\n", - "original_model = automl_run.register_model(\n", - " model_name=\"automl_model\", model_path=\"outputs/model.pkl\"\n", - ")\n", - "scoring_explainer_model = automl_run.register_model(\n", - " model_name=\"scoring_explainer\", model_path=\"outputs/scoring_explainer.pkl\"\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create the conda dependencies for setting up the service\n", - "\n", - "We need to download the conda dependencies using the automl_run object." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.automl.core.shared import constants\n", - "from azureml.core.environment import Environment\n", - "\n", - "automl_run.download_file(constants.CONDA_ENV_FILE_PATH, \"myenv.yml\")\n", - "myenv = Environment.from_conda_specification(name=\"myenv\", file_path=\"myenv.yml\")\n", - "myenv" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Write the Entry Script\n", - "Write the script that will be used to predict on your model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import joblib\n", - "import pandas as pd\n", - "from azureml.core.model import Model\n", - "from azureml.train.automl.runtime.automl_explain_utilities import (\n", - " automl_setup_model_explanations,\n", - ")\n", - "\n", - "\n", - "def init():\n", - " global automl_model\n", - " global scoring_explainer\n", - "\n", - " # Retrieve the path to the model file using the model name\n", - " # Assume original model is named original_prediction_model\n", - " automl_model_path = Model.get_model_path(\"automl_model\")\n", - " scoring_explainer_path = Model.get_model_path(\"scoring_explainer\")\n", - "\n", - " automl_model = joblib.load(automl_model_path)\n", - " scoring_explainer = joblib.load(scoring_explainer_path)\n", - "\n", - "\n", - "def run(raw_data):\n", - " data = pd.read_json(raw_data, orient=\"records\")\n", - " # Make prediction\n", - " predictions = automl_model.predict(data)\n", - " # Setup for inferencing explanations\n", - " automl_explainer_setup_obj = automl_setup_model_explanations(\n", - " automl_model, X_test=data, task=\"classification\"\n", - " )\n", - " # Retrieve model explanations for engineered explanations\n", - " engineered_local_importance_values = scoring_explainer.explain(\n", - " automl_explainer_setup_obj.X_test_transform\n", - " )\n", - " # Retrieve model explanations for raw explanations\n", - " raw_local_importance_values = scoring_explainer.explain(\n", - " automl_explainer_setup_obj.X_test_transform, get_raw=True\n", - " )\n", - " # You can return any data type as long as it is JSON-serializable\n", - " return {\n", - " \"predictions\": predictions.tolist(),\n", - " \"engineered_local_importance_values\": engineered_local_importance_values,\n", - " \"raw_local_importance_values\": raw_local_importance_values,\n", - " }" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Create the InferenceConfig \n", - "Create the inference config that will be used when deploying the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "\n", - "inf_config = InferenceConfig(entry_script=\"score.py\", environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Provision the AKS Cluster\n", - "This is a one time setup. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget, AksCompute\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# Choose a name for your cluster.\n", - "aks_name = \"scoring-explain\"\n", - "\n", - "# Verify that cluster does not exist already\n", - "try:\n", - " aks_target = ComputeTarget(workspace=ws, name=aks_name)\n", - " print(\"Found existing cluster, use it.\")\n", - "except ComputeTargetException:\n", - " prov_config = AksCompute.provisioning_configuration(vm_size=\"STANDARD_D3_V2\")\n", - " aks_target = ComputeTarget.create(\n", - " workspace=ws, name=aks_name, provisioning_configuration=prov_config\n", - " )\n", - "aks_target.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Deploy web service to AKS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Set the web service configuration (using default here)\n", - "from azureml.core.webservice import AksWebservice\n", - "from azureml.core.model import Model\n", - "\n", - "aks_config = AksWebservice.deploy_configuration()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aks_service_name = \"model-scoring-local-aks\"\n", - "\n", - "aks_service = Model.deploy(\n", - " workspace=ws,\n", - " name=aks_service_name,\n", - " models=[scoring_explainer_model, original_model],\n", - " inference_config=inf_config,\n", - " deployment_config=aks_config,\n", - " deployment_target=aks_target,\n", - ")\n", - "\n", - "aks_service.wait_for_deployment(show_output=True)\n", - "print(aks_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### View the service logs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aks_service.get_logs()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Consume the web service using run method to do the scoring and explanation of scoring.\n", - "We test the web sevice by passing data. Run() method retrieves API keys behind the scenes to make sure that call is authenticated." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Serialize the first row of the test data into json\n", - "X_test_json = X_test_df[:1].to_json(orient=\"records\")\n", - "print(X_test_json)\n", - "\n", - "# Call the service to get the predictions and the engineered and raw explanations\n", - "output = aks_service.run(X_test_json)\n", - "\n", - "# Print the predicted value\n", - "print(\"predictions:\\n{}\\n\".format(output[\"predictions\"]))\n", - "# Print the engineered feature importances for the predicted value\n", - "print(\n", - " \"engineered_local_importance_values:\\n{}\\n\".format(\n", - " output[\"engineered_local_importance_values\"]\n", - " )\n", - ")\n", - "# Print the raw feature importances for the predicted value\n", - "print(\n", - " \"raw_local_importance_values:\\n{}\\n\".format(output[\"raw_local_importance_values\"])\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Clean up\n", - "Delete the service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aks_service.delete()" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.yml b/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.yml deleted file mode 100644 index 6c817042..00000000 --- a/how-to-use-azureml/automated-machine-learning/local-run-classification-credit-card-fraud/auto-ml-classification-credit-card-fraud-local.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-classification-credit-card-fraud-local -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.yml b/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.yml deleted file mode 100644 index 9db24f2b..00000000 --- a/how-to-use-azureml/automated-machine-learning/regression-explanation-featurization/auto-ml-regression-explanation-featurization.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-regression-explanation-featurization -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.yml b/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.yml deleted file mode 100644 index 4e84e13a..00000000 --- a/how-to-use-azureml/automated-machine-learning/regression/auto-ml-regression.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: auto-ml-regression -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/deployment/accelerated-models/NOTICE.txt b/how-to-use-azureml/deployment/accelerated-models/NOTICE.txt deleted file mode 100644 index 0451fc53..00000000 --- a/how-to-use-azureml/deployment/accelerated-models/NOTICE.txt +++ /dev/null @@ -1,217 +0,0 @@ - -NOTICES AND INFORMATION -Do Not Translate or Localize - -This Azure Machine Learning service example notebooks repository includes material from the projects listed below. - - -1. SSD-Tensorflow (https://github.com/balancap/ssd-tensorflow) - - -%% SSD-Tensorflow NOTICES AND INFORMATION BEGIN HERE -========================================= - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -========================================= -END OF SSD-Tensorflow NOTICES AND INFORMATION diff --git a/how-to-use-azureml/deployment/accelerated-models/README.md b/how-to-use-azureml/deployment/accelerated-models/README.md deleted file mode 100644 index 9ebf26b1..00000000 --- a/how-to-use-azureml/deployment/accelerated-models/README.md +++ /dev/null @@ -1,104 +0,0 @@ - -# Notebooks for Microsoft Azure Machine Learning Hardware Accelerated Models SDK - -Easily create and train a model using various deep neural networks (DNNs) as a featurizer for deployment to Azure or a Data Box Edge device for ultra-low latency inferencing using FPGA's. These models are currently available: - -* ResNet 50 -* ResNet 152 -* DenseNet-121 -* VGG-16 -* SSD-VGG - -To learn more about the azureml-accel-model classes, see the section [Model Classes](#model-classes) below or the [Azure ML Accel Models SDK documentation](https://docs.microsoft.com/en-us/python/api/azureml-accel-models/azureml.accel?view=azure-ml-py). - -### Step 1: Create an Azure ML workspace -Follow [these instructions](https://docs.microsoft.com/en-us/azure/machine-learning/service/setup-create-workspace) to install the Azure ML SDK on your local machine, create an Azure ML workspace, and set up your notebook environment, which is required for the next step. - -### Step 2: Check your FPGA quota -Use the Azure CLI to check whether you have quota. - -```shell -az vm list-usage --location "eastus" -o table -``` - -The other locations are ``southeastasia``, ``westeurope``, and ``westus2``. - -Under the "Name" column, look for "Standard PBS Family vCPUs" and ensure you have at least 6 vCPUs under "CurrentValue." - -If you do not have quota, then submit a request form [here](https://aka.ms/accelerateAI). - -### Step 3: Install the Azure ML Accelerated Models SDK -Once you have set up your environment, install the Azure ML Accel Models SDK. This package requires tensorflow >= 1.6,<2.0 to be installed. - -If you already have tensorflow >= 1.6,<2.0 installed in your development environment, you can install the SDK package using: - -``` -pip install azureml-accel-models -``` - -If you do not have tensorflow >= 1.6,<2.0 and are using a CPU-only development environment, our SDK with tensorflow can be installed using: - -``` -pip install azureml-accel-models[cpu] -``` - -If your machine supports GPU (for example, on an [Azure DSVM](https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/overview)), then you can leverage the tensorflow-gpu functionality using: - -``` -pip install azureml-accel-models[gpu] -``` - -### Step 4: Follow our notebooks - -We provide notebooks to walk through the following scenarios, linked below: -* [Quickstart](https://github.com/Azure/MachineLearningNotebooks/blob/33d6def8c30d3dd3a5bfbea50b9c727788185faf/how-to-use-azureml/deployment/accelerated-models/accelerated-models-quickstart.ipynb), deploy and inference a ResNet50 model trained on ImageNet -* [Object Detection](https://github.com/Azure/MachineLearningNotebooks/blob/33d6def8c30d3dd3a5bfbea50b9c727788185faf/how-to-use-azureml/deployment/accelerated-models/accelerated-models-object-detection.ipynb), deploy and inference an SSD-VGG model that can do object detection -* [Training models](https://github.com/Azure/MachineLearningNotebooks/blob/33d6def8c30d3dd3a5bfbea50b9c727788185faf/how-to-use-azureml/deployment/accelerated-models/accelerated-models-training.ipynb), train one of our accelerated models on the Kaggle Cats and Dogs dataset to see how to improve accuracy on custom datasets - -**Note**: the above notebooks work only for tensorflow >= 1.6,<2.0. - - -## Model Classes -As stated above, we support 5 Accelerated Models. Here's more information on their input and output tensors. - -**Available models and output tensors** - -The available models and the corresponding default classifier output tensors are below. This is the value that you would use during inferencing if you used the default classifier. -* Resnet50, QuantizedResnet50 -`` -output_tensors = "classifier_1/resnet_v1_50/predictions/Softmax:0" -`` -* Resnet152, QuantizedResnet152 -`` -output_tensors = "classifier/resnet_v1_152/predictions/Softmax:0" -`` -* Densenet121, QuantizedDensenet121 -`` -output_tensors = "classifier/densenet121/predictions/Softmax:0" -`` -* Vgg16, QuantizedVgg16 -`` -output_tensors = "classifier/vgg_16/fc8/squeezed:0" -`` -* SsdVgg, QuantizedSsdVgg -`` -output_tensors = ['ssd_300_vgg/block4_box/Reshape_1:0', 'ssd_300_vgg/block7_box/Reshape_1:0', 'ssd_300_vgg/block8_box/Reshape_1:0', 'ssd_300_vgg/block9_box/Reshape_1:0', 'ssd_300_vgg/block10_box/Reshape_1:0', 'ssd_300_vgg/block11_box/Reshape_1:0', 'ssd_300_vgg/block4_box/Reshape:0', 'ssd_300_vgg/block7_box/Reshape:0', 'ssd_300_vgg/block8_box/Reshape:0', 'ssd_300_vgg/block9_box/Reshape:0', 'ssd_300_vgg/block10_box/Reshape:0', 'ssd_300_vgg/block11_box/Reshape:0'] -`` - -For more information, please reference the azureml.accel.models package in the [Azure ML Python SDK documentation](https://docs.microsoft.com/en-us/python/api/azureml-accel-models/azureml.accel.models?view=azure-ml-py). - -**Input tensors** - -The input_tensors value defaults to "Placeholder:0" and is created in the [Image Preprocessing](#construct-model) step in the line: -`` -in_images = tf.placeholder(tf.string) -`` - -You can change the input_tensors name by doing this: -`` -in_images = tf.placeholder(tf.string, name="images") -`` - - -## Resources -* [Read more about FPGAs](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-accelerate-with-fpgas) \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-multi-model/README.md b/how-to-use-azureml/deployment/deploy-multi-model/README.md deleted file mode 100644 index 31d4427f..00000000 --- a/how-to-use-azureml/deployment/deploy-multi-model/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Model Deployment with Azure ML service -You can use Azure Machine Learning to package, debug, validate and deploy inference containers to a variety of compute targets. This process is known as "MLOps" (ML operationalization). -For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where - -## Get Started -To begin, you will need an ML workspace. -For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-workspace - -## Deploy to the cloud -You can deploy to the cloud using the Azure ML CLI or the Azure ML SDK. -- CLI example: https://aka.ms/azmlcli -- Notebook example: [model-register-and-deploy](./model-register-and-deploy.ipynb). - -![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/deploy-multi-model/README.png) \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.ipynb b/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.ipynb deleted file mode 100644 index c1908bf8..00000000 --- a/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.ipynb +++ /dev/null @@ -1,395 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploy Multiple Models as Webservice\n", - "\n", - "This example shows how to deploy a Webservice with multiple models in step-by-step fashion:\n", - "\n", - " 1. Register Models\n", - " 2. Deploy Models as Webservice" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, make sure you go through the [configuration](../../../configuration.ipynb) Notebook first if you haven't." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize Workspace\n", - "\n", - "Initialize a workspace object from persisted configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "create workspace" - ] - }, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Register Models" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this example, we will be using and registering two models. \n", - "\n", - "First we will train two simple models on the [diabetes dataset](https://scikit-learn.org/stable/datasets/toy_dataset.html#diabetes-dataset) included with scikit-learn, serializing them to files in the current directory." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import joblib\n", - "import sklearn\n", - "\n", - "from sklearn.datasets import load_diabetes\n", - "from sklearn.linear_model import BayesianRidge, Ridge\n", - "\n", - "x, y = load_diabetes(return_X_y=True)\n", - "\n", - "first_model = Ridge().fit(x, y)\n", - "second_model = BayesianRidge().fit(x, y)\n", - "\n", - "joblib.dump(first_model, \"first_model.pkl\")\n", - "joblib.dump(second_model, \"second_model.pkl\")\n", - "\n", - "print(\"Trained models using scikit-learn {}.\".format(sklearn.__version__))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that we have our trained models locally, we will register them as Models with the names `my_first_model` and `my_second_model` in the workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "register model from file" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "my_model_1 = Model.register(model_path=\"first_model.pkl\",\n", - " model_name=\"my_first_model\",\n", - " workspace=ws)\n", - "\n", - "my_model_2 = Model.register(model_path=\"second_model.pkl\",\n", - " model_name=\"my_second_model\",\n", - " workspace=ws)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Write the Entry Script\n", - "Write the script that will be used to predict on your models" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Model.get_model_path()\n", - "\n", - "To get the paths of your models, use `Model.get_model_path(model_name, version=None, _workspace=None)` method. This method will find the path to a model using the name of the model registered under the workspace.\n", - "\n", - "In this example, we do not use the optional arguments `version` and `_workspace`.\n", - "\n", - "#### Using environment variable AZUREML_MODEL_DIR\n", - "\n", - "In other [examples](../deploy-to-cloud/score.py) with a single model deployment, we use the environment variable `AZUREML_MODEL_DIR` and model file name to get the model path. \n", - "\n", - "For single model deployments, this environment variable is the path to the model folder (`./azureml-models/$MODEL_NAME/$VERSION`). When we deploy multiple models, the environment variable is set to the folder containing all models (./azureml-models).\n", - "\n", - "If you're using multiple models and you know the versions of the models you deploy, you can use this method to get the model path:\n", - "\n", - "```python\n", - "# Construct the model path using the registered model name, version, and model file name\n", - "model_1_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'my_first_model', '1', 'first_model.pkl')\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import joblib\n", - "import json\n", - "import numpy as np\n", - "\n", - "from azureml.core.model import Model\n", - "\n", - "def init():\n", - " global model_1, model_2\n", - " # Here \"my_first_model\" is the name of the model registered under the workspace.\n", - " # This call will return the path to the .pkl file on the local disk.\n", - " model_1_path = Model.get_model_path(model_name='my_first_model')\n", - " model_2_path = Model.get_model_path(model_name='my_second_model')\n", - " \n", - " # Deserialize the model files back into scikit-learn models.\n", - " model_1 = joblib.load(model_1_path)\n", - " model_2 = joblib.load(model_2_path)\n", - "\n", - "# Note you can pass in multiple rows for scoring.\n", - "def run(raw_data):\n", - " try:\n", - " data = json.loads(raw_data)['data']\n", - " data = np.array(data)\n", - " \n", - " # Call predict() on each model\n", - " result_1 = model_1.predict(data)\n", - " result_2 = model_2.predict(data)\n", - "\n", - " # You can return any JSON-serializable value.\n", - " return {\"prediction1\": result_1.tolist(), \"prediction2\": result_2.tolist()}\n", - " except Exception as e:\n", - " result = str(e)\n", - " return result" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Environment" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can now create and/or use an Environment object when deploying a Webservice. The Environment can have been previously registered with your Workspace, or it will be registered with it as a part of the Webservice deployment. Please note that your environment must include azureml-defaults with verion >= 1.0.45 as a pip dependency, because it contains the functionality needed to host the model as a web service.\n", - "\n", - "More information can be found in our [using environments notebook](../training/using-environments/using-environments.ipynb)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Environment\n", - "\n", - "env = Environment(\"deploytocloudenv\")\n", - "env.python.conda_dependencies.add_pip_package(\"joblib\")\n", - "env.python.conda_dependencies.add_pip_package(\"numpy==1.23\")\n", - "env.python.conda_dependencies.add_pip_package(\"scikit-learn=={}\".format(sklearn.__version__))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Inference Configuration\n", - "\n", - "There is now support for a source directory, you can upload an entire folder from your local machine as dependencies for the Webservice.\n", - "Note: in that case, environments's entry_script and file_path are relative paths to the source_directory path; myenv.docker.base_dockerfile is a string containing extra docker steps or contents of the docker file.\n", - "\n", - "Sample code for using a source directory:\n", - "\n", - "```python\n", - "from azureml.core.environment import Environment\n", - "from azureml.core.model import InferenceConfig\n", - "\n", - "myenv = Environment.from_conda_specification(name='myenv', file_path='env/myenv.yml')\n", - "\n", - "# explicitly set base_image to None when setting base_dockerfile\n", - "myenv.docker.base_image = None\n", - "# add extra docker commends to execute\n", - "myenv.docker.base_dockerfile = \"FROM ubuntu\\n RUN echo \\\"hello\\\"\"\n", - "\n", - "inference_config = InferenceConfig(source_directory=\"C:/abc\",\n", - " entry_script=\"x/y/score.py\",\n", - " environment=myenv)\n", - "```\n", - "\n", - " - file_path: input parameter to Environment constructor. Manages conda and python package dependencies.\n", - " - env.docker.base_dockerfile: any extra steps you want to inject into docker file\n", - " - source_directory: holds source path as string, this entire folder gets added in image so its really easy to access any files within this folder or subfolder\n", - " - entry_script: contains logic specific to initializing your model and running predictions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "create image" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=env)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploy Model as Webservice on Azure Container Instance\n", - "\n", - "Note that the service creation can take few minutes." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "azuremlexception-remarks-sample" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice\n", - "\n", - "aci_service_name = \"aciservice-multimodel\"\n", - "\n", - "deployment_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)\n", - "\n", - "service = Model.deploy(ws, aci_service_name, [my_model_1, my_model_2], inference_config, deployment_config, overwrite=True)\n", - "service.wait_for_deployment(True)\n", - "\n", - "print(service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Test web service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "\n", - "test_sample = json.dumps({'data': x[0:2].tolist()})\n", - "\n", - "prediction = service.run(test_sample)\n", - "\n", - "print(prediction)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Delete ACI to clean up" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "deploy service", - "aci" - ] - }, - "outputs": [], - "source": [ - "service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "jenns" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.yml b/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.yml deleted file mode 100644 index 497c43b4..00000000 --- a/how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: multi-model-register-and-deploy -dependencies: -- pip: - - azureml-sdk - - numpy - - scikit-learn diff --git a/how-to-use-azureml/deployment/deploy-to-local/README.md b/how-to-use-azureml/deployment/deploy-to-local/README.md deleted file mode 100644 index 9f08e5cd..00000000 --- a/how-to-use-azureml/deployment/deploy-to-local/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Model Deployment with Azure ML service -You can use Azure Machine Learning to package, debug, validate and deploy inference containers to a variety of compute targets. This process is known as "MLOps" (ML operationalization). -For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-deploy-and-where - -## Get Started -To begin, you will need an ML workspace. -For more information please check out this article: https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-workspace - -## Deploy locally -You can deploy a model locally for testing & debugging using the Azure ML CLI or the Azure ML SDK. -- CLI example: https://aka.ms/azmlcli -- Notebook example: [register-model-deploy-local](./register-model-deploy-local.ipynb). \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-to-local/helloworld.txt b/how-to-use-azureml/deployment/deploy-to-local/helloworld.txt deleted file mode 100644 index a12521d8..00000000 --- a/how-to-use-azureml/deployment/deploy-to-local/helloworld.txt +++ /dev/null @@ -1 +0,0 @@ -RUN echo "this is test" \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local-advanced.ipynb b/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local-advanced.ipynb deleted file mode 100644 index e41859ce..00000000 --- a/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local-advanced.ipynb +++ /dev/null @@ -1,495 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local-advanced.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register model and deploy locally with advanced usages\n", - "\n", - "This example shows how to deploy a web service in step-by-step fashion:\n", - "\n", - " 1. Register model\n", - " 2. Deploy the image as a web service in a local Docker container.\n", - " 3. Quickly test changes to your entry script by reloading the local service.\n", - " 4. Optionally, you can also make changes to model, conda or extra_docker_file_steps and update local service" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, make sure you go through the [configuration](../../../configuration.ipynb) Notebook first if you haven't." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize Workspace\n", - "\n", - "Initialize a workspace object from persisted configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "create workspace" - ] - }, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create trained model\n", - "\n", - "For this example, we will train a small model on scikit-learn's [diabetes dataset](https://scikit-learn.org/stable/datasets/toy_dataset.html#diabetes-dataset). " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import joblib\n", - "\n", - "from sklearn.datasets import load_diabetes\n", - "from sklearn.linear_model import Ridge\n", - "\n", - "dataset_x, dataset_y = load_diabetes(return_X_y=True)\n", - "\n", - "sk_model = Ridge().fit(dataset_x, dataset_y)\n", - "\n", - "joblib.dump(sk_model, \"sklearn_regression_model.pkl\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Register Model" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can add tags and descriptions to your models. we are using `sklearn_regression_model.pkl` file in the current directory as a model with the name `sklearn_regression_model` in the workspace.\n", - "\n", - "Using tags, you can track useful information such as the name and version of the machine learning library used to train the model, framework, category, target customer etc. Note that tags must be alphanumeric." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "register model from file", - "sample-model-register" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "model = Model.register(model_path=\"sklearn_regression_model.pkl\",\n", - " model_name=\"sklearn_regression_model\",\n", - " tags={'area': \"diabetes\", 'type': \"regression\"},\n", - " description=\"Ridge regression model to predict diabetes\",\n", - " workspace=ws)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Manage your dependencies in a folder" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "source_directory = \"source_directory\"\n", - "\n", - "os.makedirs(source_directory, exist_ok=True)\n", - "os.makedirs(os.path.join(source_directory, \"x/y\"), exist_ok=True)\n", - "os.makedirs(os.path.join(source_directory, \"env\"), exist_ok=True)\n", - "os.makedirs(os.path.join(source_directory, \"dockerstep\"), exist_ok=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Show `score.py`. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile source_directory/x/y/score.py\n", - "import joblib\n", - "import json\n", - "import numpy as np\n", - "import os\n", - "\n", - "from inference_schema.schema_decorators import input_schema, output_schema\n", - "from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment. Join this path with the filename of the model file.\n", - " # It holds the path to the directory that contains the deployed model (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # If there are multiple models, this value is the path to the directory containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # Deserialize the model file back into a sklearn model.\n", - " model = joblib.load(model_path)\n", - "\n", - " global name\n", - " # Note here, the entire source directory from inference config gets added into image.\n", - " # Below is an example of how you can use any extra files in image.\n", - " with open('./source_directory/extradata.json') as json_file:\n", - " data = json.load(json_file)\n", - " name = data[\"people\"][0][\"name\"]\n", - "\n", - "input_sample = np.array([[10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]])\n", - "output_sample = np.array([3726.995])\n", - "\n", - "@input_schema('data', NumpyParameterType(input_sample))\n", - "@output_schema(NumpyParameterType(output_sample))\n", - "def run(data):\n", - " try:\n", - " result = model.predict(data)\n", - " # You can return any JSON-serializable object.\n", - " return \"Hello \" + name + \" here is your result = \" + str(result)\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile source_directory/extradata.json\n", - "{\n", - " \"people\": [\n", - " {\n", - " \"website\": \"microsoft.com\", \n", - " \"from\": \"Seattle\", \n", - " \"name\": \"Mrudula\"\n", - " }\n", - " ]\n", - "}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Inference Configuration\n", - "\n", - " - file_path: input parameter to Environment constructor. Manages conda and python package dependencies.\n", - " - env.docker.base_dockerfile: any extra steps you want to inject into docker file\n", - " - source_directory: holds source path as string, this entire folder gets added in image so its really easy to access any files within this folder or subfolder\n", - " - entry_script: contains logic specific to initializing your model and running predictions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import sklearn\n", - "\n", - "from azureml.core.environment import Environment\n", - "from azureml.core.model import InferenceConfig\n", - "\n", - "\n", - "myenv = Environment('myenv')\n", - "myenv.python.conda_dependencies.add_pip_package(\"inference-schema[numpy-support]\")\n", - "myenv.python.conda_dependencies.add_pip_package(\"joblib\")\n", - "myenv.python.conda_dependencies.add_pip_package(\"scikit-learn=={}\".format(sklearn.__version__))\n", - "\n", - "# explicitly set base_image to None when setting base_dockerfile\n", - "myenv.docker.base_image = None\n", - "myenv.docker.base_dockerfile = \"FROM mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04\\nRUN echo \\\"this is test\\\"\"\n", - "myenv.inferencing_stack_version = \"latest\"\n", - "\n", - "inference_config = InferenceConfig(source_directory=source_directory,\n", - " entry_script=\"x/y/score.py\",\n", - " environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy Model as a Local Docker Web Service\n", - "\n", - "*Make sure you have Docker installed and running.*\n", - "\n", - "Note that the service creation can take few minutes.\n", - "\n", - "NOTE:\n", - "\n", - "The Docker image runs as a Linux container. If you are running Docker for Windows, you need to ensure the Linux Engine is running:\n", - "\n", - " # PowerShell command to switch to Linux engine\n", - " & 'C:\\Program Files\\Docker\\Docker\\DockerCli.exe' -SwitchLinuxEngine" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "deploy service", - "aci" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.webservice import LocalWebservice\n", - "\n", - "# This is optional, if not provided Docker will choose a random unused port.\n", - "deployment_config = LocalWebservice.deploy_configuration(port=6789)\n", - "\n", - "local_service = Model.deploy(ws, \"test\", [model], inference_config, deployment_config)\n", - "\n", - "local_service.wait_for_deployment()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('Local service port: {}'.format(local_service.port))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Check Status and Get Container Logs\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(local_service.get_logs())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Test Web Service" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Call the web service with some input data to get a prediction." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "\n", - "sample_input = json.dumps({\n", - " 'data': dataset_x[0:2].tolist()\n", - "})\n", - "\n", - "print(local_service.run(sample_input))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Reload Service\n", - "\n", - "You can update your score.py file and then call `reload()` to quickly restart the service. This will only reload your execution script and dependency files, it will not rebuild the underlying Docker image. As a result, `reload()` is fast, but if you do need to rebuild the image -- to add a new Conda or pip package, for instance -- you will have to call `update()`, instead (see below)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile source_directory/x/y/score.py\n", - "import joblib\n", - "import json\n", - "import numpy as np\n", - "import os\n", - "\n", - "from inference_schema.schema_decorators import input_schema, output_schema\n", - "from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # Deserialize the model file back into a sklearn model.\n", - " model = joblib.load(model_path)\n", - "\n", - " global name, from_location\n", - " # Note here, the entire source directory from inference config gets added into image.\n", - " # Below is an example of how you can use any extra files in image.\n", - " with open('source_directory/extradata.json') as json_file: \n", - " data = json.load(json_file)\n", - " name = data[\"people\"][0][\"name\"]\n", - " from_location = data[\"people\"][0][\"from\"]\n", - "\n", - "input_sample = np.array([[10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]])\n", - "output_sample = np.array([3726.995])\n", - "\n", - "@input_schema('data', NumpyParameterType(input_sample))\n", - "@output_schema(NumpyParameterType(output_sample))\n", - "def run(data):\n", - " try:\n", - " result = model.predict(data)\n", - " # You can return any JSON-serializable object.\n", - " return \"Hello \" + name + \" from \" + from_location + \" here is your result = \" + str(result)\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_service.reload()\n", - "print(\"--------------------------------------------------------------\")\n", - "\n", - "# After calling reload(), run() will return the updated message.\n", - "local_service.run(sample_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Update Service\n", - "\n", - "If you want to change your model(s), Conda dependencies, or deployment configuration, call `update()` to rebuild the Docker image.\n", - "\n", - "```python\n", - "\n", - "local_service.update(models=[SomeOtherModelObject],\n", - " deployment_config=local_config,\n", - " inference_config=inference_config)\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Delete Service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "keriehm" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb b/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb deleted file mode 100644 index 20959cdf..00000000 --- a/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb +++ /dev/null @@ -1,556 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register model and deploy locally\n", - "\n", - "This example shows how to deploy a web service in step-by-step fashion:\n", - "\n", - " 1. Register model\n", - " 2. Deploy the image as a web service in a local Docker container.\n", - " 3. Quickly test changes to your entry script by reloading the local service.\n", - " 4. Optionally, you can also make changes to model, conda or extra_docker_file_steps and update local service" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, make sure you go through the [configuration](../../../configuration.ipynb) Notebook first if you haven't." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize Workspace\n", - "\n", - "Initialize a workspace object from persisted configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create trained model\n", - "\n", - "For this example, we will train a small model on scikit-learn's [diabetes dataset](https://scikit-learn.org/stable/datasets/toy_dataset.html#diabetes-dataset). " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import joblib\n", - "\n", - "from sklearn.datasets import load_diabetes\n", - "from sklearn.linear_model import Ridge\n", - "\n", - "dataset_x, dataset_y = load_diabetes(return_X_y=True)\n", - "\n", - "sk_model = Ridge().fit(dataset_x, dataset_y)\n", - "\n", - "joblib.dump(sk_model, \"sklearn_regression_model.pkl\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Register Model" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Here we are registering the serialized file `sklearn_regression_model.pkl` in the current directory as a model with the name `sklearn_regression_model` in the workspace.\n", - "\n", - "You can add tags and descriptions to your models. Using tags, you can track useful information such as the name and version of the machine learning library used to train the model, framework, category, target customer etc. Note that tags must be alphanumeric." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "register model from file" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "model = Model.register(model_path=\"sklearn_regression_model.pkl\",\n", - " model_name=\"sklearn_regression_model\",\n", - " tags={'area': \"diabetes\", 'type': \"regression\"},\n", - " description=\"Ridge regression model to predict diabetes\",\n", - " workspace=ws)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Environment" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import sklearn\n", - "\n", - "from azureml.core.environment import Environment\n", - "\n", - "environment = Environment(\"LocalDeploy\")\n", - "environment.python.conda_dependencies.add_pip_package(\"inference-schema[numpy-support]\")\n", - "environment.python.conda_dependencies.add_pip_package(\"joblib\")\n", - "environment.python.conda_dependencies.add_pip_package(\"scikit-learn=={}\".format(sklearn.__version__))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Provide the Scoring Script\n", - "\n", - "This Python script handles the model execution inside the service container. The `init()` method loads the model file, and `run(data)` is called for every input to the service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import joblib\n", - "import json\n", - "import numpy as np\n", - "import os\n", - "\n", - "from inference_schema.schema_decorators import input_schema, output_schema\n", - "from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # Deserialize the model file back into a sklearn model.\n", - " model = joblib.load(model_path)\n", - "\n", - "input_sample = np.array([[10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]])\n", - "output_sample = np.array([3726.995])\n", - "\n", - "@input_schema('data', NumpyParameterType(input_sample))\n", - "@output_schema(NumpyParameterType(output_sample))\n", - "def run(data):\n", - " try:\n", - " result = model.predict(data)\n", - " # You can return any JSON-serializable object.\n", - " return result.tolist()\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create Inference Configuration" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "\n", - "inference_config = InferenceConfig(entry_script=\"score.py\",\n", - " environment=environment)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy Model as a Local Docker Web Service\n", - "\n", - "*Make sure you have Docker installed and running.*\n", - "\n", - "Note that the service creation can take few minutes.\n", - "\n", - "NOTE:\n", - "\n", - "The Docker image runs as a Linux container. If you are running Docker for Windows, you need to ensure the Linux Engine is running:\n", - "\n", - " # PowerShell command to switch to Linux engine\n", - " & 'C:\\Program Files\\Docker\\Docker\\DockerCli.exe' -SwitchLinuxEngine" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "sample-localwebservice-deploy" - ] - }, - "outputs": [], - "source": [ - "from azureml.core.webservice import LocalWebservice\n", - "\n", - "# This is optional, if not provided Docker will choose a random unused port.\n", - "deployment_config = LocalWebservice.deploy_configuration(port=6789)\n", - "\n", - "local_service = Model.deploy(ws, \"test\", [model], inference_config, deployment_config)\n", - "\n", - "local_service.wait_for_deployment()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('Local service port: {}'.format(local_service.port))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Check Status and Get Container Logs\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(local_service.get_logs())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Test Web Service" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Call the web service with some input data to get a prediction." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "\n", - "sample_input = json.dumps({\n", - " 'data': dataset_x[0:2].tolist()\n", - "})\n", - "\n", - "local_service.run(sample_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Reload Service\n", - "\n", - "You can update your score.py file and then call `reload()` to quickly restart the service. This will only reload your execution script and dependency files, it will not rebuild the underlying Docker image. As a result, `reload()` is fast, but if you do need to rebuild the image -- to add a new Conda or pip package, for instance -- you will have to call `update()`, instead (see below)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import joblib\n", - "import json\n", - "import numpy as np\n", - "import os\n", - "\n", - "from inference_schema.schema_decorators import input_schema, output_schema\n", - "from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # Deserialize the model file back into a sklearn model.\n", - " model = joblib.load(model_path)\n", - "\n", - "input_sample = np.array([[10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]])\n", - "output_sample = np.array([3726.995])\n", - "\n", - "@input_schema('data', NumpyParameterType(input_sample))\n", - "@output_schema(NumpyParameterType(output_sample))\n", - "def run(data):\n", - " try:\n", - " result = model.predict(data)\n", - " # You can return any JSON-serializable object.\n", - " return 'Hello from the updated score.py: ' + str(result.tolist())\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_service.reload()\n", - "print(\"--------------------------------------------------------------\")\n", - "\n", - "# After calling reload(), run() will return the updated message.\n", - "local_service.run(sample_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Update Service\n", - "\n", - "If you want to change your model(s), Conda dependencies or deployment configuration, call `update()` to rebuild the Docker image.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_service.update(models=[model],\n", - " inference_config=inference_config,\n", - " deployment_config=deployment_config)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy model to AKS cluster based on the LocalWebservice's configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This is a one time setup for AKS Cluster. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it.\n", - "from azureml.core.compute import AksCompute, ComputeTarget\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# Choose a name for your AKS cluster\n", - "aks_name = 'my-aks-9' \n", - "\n", - "# Verify the cluster does not exist already\n", - "try:\n", - " aks_target = ComputeTarget(workspace=ws, name=aks_name)\n", - " print('Found existing cluster, use it.')\n", - "except ComputeTargetException:\n", - " # Use the default configuration (can also provide parameters to customize)\n", - " prov_config = AksCompute.provisioning_configuration()\n", - "\n", - " # Create the cluster\n", - " aks_target = ComputeTarget.create(workspace = ws, \n", - " name = aks_name, \n", - " provisioning_configuration = prov_config)\n", - "\n", - "if aks_target.get_status() != \"Succeeded\":\n", - " aks_target.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AksWebservice\n", - "# Set the web service configuration (using default here)\n", - "aks_config = AksWebservice.deploy_configuration()\n", - "\n", - "# # Enable token auth and disable (key) auth on the webservice\n", - "# aks_config = AksWebservice.deploy_configuration(token_auth_enabled=True, auth_enabled=False)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service_name ='aks-service-1'\n", - "\n", - "aks_service = local_service.deploy_to_cloud(name=aks_service_name,\n", - " deployment_config=aks_config,\n", - " deployment_target=aks_target)\n", - "\n", - "aks_service.wait_for_deployment(show_output = True)\n", - "print(aks_service.state)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Test aks service\n", - "\n", - "sample_input = json.dumps({\n", - " 'data': dataset_x[0:2].tolist()\n", - "})\n", - "\n", - "aks_service.run(sample_input)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Delete the service if not needed.\n", - "aks_service.delete()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Delete Service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "local_service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "keriehm" - } - ], - "category": "tutorial", - "compute": [ - "Local" - ], - "datasets": [ - "None" - ], - "deployment": [ - "Local" - ], - "exclude_from_index": false, - "framework": [ - "None" - ], - "friendly_name": "Register a model and deploy locally", - "index_order": 1, - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.8" - }, - "star_tag": [], - "tags": [ - "None" - ], - "task": "Deployment" - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.ipynb b/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.ipynb deleted file mode 100644 index 2db72976..00000000 --- a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.ipynb +++ /dev/null @@ -1,498 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Enabling App Insights for Services in Production\n", - "With this notebook, you can learn how to enable App Insights for standard service monitoring, plus, we provide examples for doing custom logging within a scoring files in a model.\n", - "\n", - "\n", - "## What does Application Insights monitor?\n", - "It monitors request rates, response times, failure rates, etc. For more information visit [App Insights docs.](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-overview)\n", - "\n", - "\n", - "## What is different compared to standard production deployment process?\n", - "If you want to enable generic App Insights for a service run:\n", - "```python\n", - "aks_service= Webservice(ws, \"aks-w-dc2\")\n", - "aks_service.update(enable_app_insights=True)```\n", - "Where \"aks-w-dc2\" is your service name. You can also do this from the Azure Portal under your Workspace--> deployments--> Select deployment--> Edit--> Advanced Settings--> Select \"Enable AppInsights diagnostics\"\n", - "\n", - "If you want to log custom traces, you will follow the standard deplyment process for AKS and you will:\n", - "1. Update scoring file.\n", - "2. Update aks configuration.\n", - "3. Deploy the model with this new configuration. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 1. Import your dependencies" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import azureml.core\n", - "import json\n", - "\n", - "from azureml.core import Workspace\n", - "from azureml.core.compute import AksCompute, ComputeTarget\n", - "from azureml.core.webservice import AksWebservice\n", - "\n", - "print(azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2. Set up your configuration and create a workspace\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 3. Register Model\n", - "Register an existing trained model, add descirption and tags." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Model\n", - "\n", - "model = Model.register(model_path=\"sklearn_regression_model.pkl\", # This points to a local file.\n", - " model_name=\"sklearn_regression_model.pkl\", # This is the name the model is registered as.\n", - " tags={'area': \"diabetes\", 'type': \"regression\"},\n", - " description=\"Ridge regression model to predict diabetes\",\n", - " workspace=ws)\n", - "\n", - "print(model.name, model.description, model.version)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 4. *Update your scoring file with custom print statements*\n", - "Here is an example:\n", - "### a. In your init function add:\n", - "```python\n", - "print (\"model initialized\" + time.strftime(\"%H:%M:%S\"))```\n", - "\n", - "### b. In your run function add:\n", - "```python\n", - "print (\"Prediction created\" + time.strftime(\"%H:%M:%S\"))```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import os\n", - "import pickle\n", - "import json\n", - "import numpy\n", - "import joblib\n", - "from sklearn.linear_model import Ridge\n", - "import time\n", - "\n", - "def init():\n", - " global model\n", - " #Print statement for appinsights custom traces:\n", - " print (\"model initialized\" + time.strftime(\"%H:%M:%S\"))\n", - "\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - "\n", - " # deserialize the model file back into a sklearn model\n", - " model = joblib.load(model_path)\n", - "\n", - "\n", - "# note you can pass in multiple rows for scoring\n", - "def run(raw_data):\n", - " try:\n", - " data = json.loads(raw_data)['data']\n", - " data = numpy.array(data)\n", - " result = model.predict(data)\n", - " print (\"Prediction created\" + time.strftime(\"%H:%M:%S\"))\n", - " # you can return any datatype as long as it is JSON-serializable\n", - " return result.tolist()\n", - " except Exception as e:\n", - " error = str(e)\n", - " print (error + time.strftime(\"%H:%M:%S\"))\n", - " return error" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 5. *Create myenv.yml file*\n", - "Please note that you must indicate azureml-defaults with verion >= 1.0.45 as a pip dependency, because it contains the functionality needed to host the model as a web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.conda_dependencies import CondaDependencies\n", - "\n", - "myenv = CondaDependencies.create(conda_packages=['numpy==1.19.5','scikit-learn==0.22.1'],\n", - " pip_packages=['azureml-defaults'])\n", - "\n", - "with open(\"myenv.yml\",\"w\") as f:\n", - " f.write(myenv.serialize_to_string())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 6. Create Inference Configuration" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.environment import Environment\n", - "from azureml.core.model import InferenceConfig\n", - "\n", - "myenv = Environment.from_conda_specification(name=\"myenv\", file_path=\"myenv.yml\")\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy to ACI (Optional)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice\n", - "\n", - "aci_deployment_config = AciWebservice.deploy_configuration(cpu_cores=1,\n", - " memory_gb=1,\n", - " tags={'area': \"diabetes\", 'type': \"regression\"},\n", - " description=\"Predict diabetes using regression model\",\n", - " enable_app_insights=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aci_service_name = \"aci-service-appinsights\"\n", - "\n", - "aci_service = Model.deploy(ws, aci_service_name, [model], inference_config, aci_deployment_config, overwrite=True)\n", - "aci_service.wait_for_deployment(show_output=True)\n", - "\n", - "print(aci_service.state)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if aci_service.state == \"Healthy\":\n", - " test_sample = json.dumps({\n", - " \"data\": [\n", - " [1,28,13,45,54,6,57,8,8,10],\n", - " [101,9,8,37,6,45,4,3,2,41]\n", - " ]\n", - " })\n", - "\n", - " prediction = aci_service.run(test_sample)\n", - "\n", - " print(prediction)\n", - "else:\n", - " raise ValueError(\"Service deployment isn't healthy, can't call the service. Error: \", aci_service.error)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 7. Deploy to AKS service" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create AKS compute if you haven't done so.\n", - "\n", - "> Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget, AksCompute\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "aks_name = \"my-aks-insights\"\n", - "\n", - "creating_compute = False\n", - "try:\n", - " aks_target = ComputeTarget(ws, aks_name)\n", - " print(\"Using existing AKS compute target {}.\".format(aks_name))\n", - "except ComputeTargetException:\n", - " print(\"Creating a new AKS compute target {}.\".format(aks_name))\n", - "\n", - " # Use the default configuration (can also provide parameters to customize).\n", - " prov_config = AksCompute.provisioning_configuration()\n", - " aks_target = ComputeTarget.create(workspace=ws,\n", - " name=aks_name,\n", - " provisioning_configuration=prov_config)\n", - " creating_compute = True" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "if creating_compute and aks_target.provisioning_state != \"Succeeded\":\n", - " aks_target.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(aks_target.provisioning_state)\n", - "print(aks_target.provisioning_errors)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you already have a cluster you can attach the service to it:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "```python\n", - "%%time\n", - "resource_id = '/subscriptions//resourcegroups//providers/Microsoft.ContainerService/managedClusters/'\n", - "create_name= 'myaks4'\n", - "attach_config = AksCompute.attach_configuration(resource_id=resource_id)\n", - "aks_target = ComputeTarget.attach(workspace=ws,\n", - " name=create_name,\n", - " attach_configuration=attach_config)\n", - "## Wait for the operation to complete\n", - "aks_target.wait_for_provisioning(True)```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### a. *Activate App Insights through updating AKS Webservice configuration*\n", - "In order to enable App Insights in your service you will need to update your AKS configuration file:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Set the web service configuration.\n", - "aks_deployment_config = AksWebservice.deploy_configuration(enable_app_insights=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### b. Deploy your service" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if aks_target.provisioning_state == \"Succeeded\":\n", - " aks_service_name = \"aks-service-appinsights\"\n", - " aks_service = Model.deploy(ws,\n", - " aks_service_name,\n", - " [model],\n", - " inference_config,\n", - " aks_deployment_config,\n", - " deployment_target=aks_target,\n", - " overwrite=True)\n", - " aks_service.wait_for_deployment(show_output=True)\n", - " print(aks_service.state)\n", - "else:\n", - " raise ValueError(\"AKS cluster provisioning failed. Error: \", aks_target.provisioning_errors)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 8. Test your service " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "\n", - "if aks_service.state == \"Healthy\":\n", - " test_sample = json.dumps({\n", - " \"data\": [\n", - " [1,28,13,45,54,6,57,8,8,10],\n", - " [101,9,8,37,6,45,4,3,2,41]\n", - " ]\n", - " })\n", - "\n", - " prediction = aks_service.run(input_data=test_sample)\n", - " print(prediction)\n", - "else:\n", - " raise ValueError(\"Service deployment isn't healthy, can't call the service. Error: \", aks_service.error)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 9. See your service telemetry in App Insights\n", - "1. Go to the [Azure Portal](https://portal.azure.com/)\n", - "2. All resources--> Select the subscription/resource group where you created your Workspace--> Select the App Insights type\n", - "3. Click on the AppInsights resource. You'll see a highlevel dashboard with information on Requests, Server response time and availability.\n", - "4. Click on the top banner \"Analytics\"\n", - "5. In the \"Schema\" section select \"traces\" and run your query.\n", - "6. Voila! All your custom traces should be there." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Disable App Insights" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aks_service.update(enable_app_insights=False)\n", - "aks_service.wait_for_deployment(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Clean up" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service.delete()\n", - "aci_service.delete()\n", - "model.delete()\n", - "if creating_compute:\n", - " aks_target.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "gopalv" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.yml b/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.yml deleted file mode 100644 index c716614a..00000000 --- a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: enable-app-insights-in-production-service -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/sklearn_regression_model.pkl b/how-to-use-azureml/deployment/enable-app-insights-in-production-service/sklearn_regression_model.pkl deleted file mode 100644 index d10309b6..00000000 Binary files a/how-to-use-azureml/deployment/enable-app-insights-in-production-service/sklearn_regression_model.pkl and /dev/null differ diff --git a/how-to-use-azureml/deployment/onnx/Dockerfile b/how-to-use-azureml/deployment/onnx/Dockerfile deleted file mode 100644 index 2db89a25..00000000 --- a/how-to-use-azureml/deployment/onnx/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -RUN apt-get update -RUN apt-get install -y libgomp1 diff --git a/how-to-use-azureml/deployment/onnx/README.md b/how-to-use-azureml/deployment/onnx/README.md deleted file mode 100644 index 05869368..00000000 --- a/how-to-use-azureml/deployment/onnx/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# ONNX on Azure Machine Learning - -These tutorials show how to create and deploy Open Neural Network eXchange ([ONNX](http://onnx.ai)) models in Azure Machine Learning environments using [ONNX Runtime](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-build-deploy-onnx) for inference. Once deployed as a web service, you can ping the model with your own set of images to be analyzed! - -## Tutorials - -0. If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, [Configure your Azure Machine Learning Workspace](../../../configuration.ipynb) - -#### Obtain pretrained models from the [ONNX Model Zoo](https://github.com/onnx/models) and deploy with ONNX Runtime -1. [MNIST - Handwritten Digit Classification with ONNX Runtime](onnx-inference-mnist-deploy.ipynb) -2. [Emotion FER+ - Facial Expression Recognition with ONNX Runtime](onnx-inference-facial-expression-recognition-deploy.ipynb) - -#### Train model on Azure ML, convert to ONNX, and deploy with ONNX Runtime -3. [MNIST - Train using PyTorch and deploy with ONNX Runtime](onnx-train-pytorch-aml-deploy-mnist.ipynb) - -#### Demo Notebooks from Microsoft Ignite 2018 -Note that the following notebooks do not have evaluation sections for the models since they were deployed as part of a live demo. You can find the respective pre-processing and post-processing code linked from the ONNX Model Zoo Github pages ([ResNet](https://github.com/onnx/models/tree/master/models/image_classification/resnet), [TinyYoloV2](https://github.com/onnx/models/tree/master/tiny_yolov2)), or experiment with the ONNX models by [running them in the browser](https://microsoft.github.io/onnxjs-demo/#/). - -4. [ResNet50 - Image Recognition with ONNX Runtime](onnx-modelzoo-aml-deploy-resnet50.ipynb) -5. [TinyYoloV2 - Convert from CoreML and deploy with ONNX Runtime](onnx-convert-aml-deploy-tinyyolo.ipynb) - -## Documentation -- [ONNX Runtime Python API Documentation](http://aka.ms/onnxruntime-python) -- [Azure Machine Learning API Documentation](http://aka.ms/aml-docs) - -## Related Articles -- [Building and Deploying ONNX Runtime Models](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-build-deploy-onnx) -- [Azure AI – Making AI Real for Business](https://aka.ms/aml-blog-overview) -- [What’s new in Azure Machine Learning](https://aka.ms/aml-blog-whats-new) - -## License -Copyright (c) Microsoft Corporation. All rights reserved. -Licensed under the MIT License. - -## Acknowledgements -These tutorials were developed by Vinitra Swamy and Prasanth Pulavarthi of the Microsoft AI Frameworks team and adapted for presentation at Microsoft Ignite 2018. - - - ![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/onnx/README.png) diff --git a/how-to-use-azureml/deployment/onnx/mnist-model.onnx b/how-to-use-azureml/deployment/onnx/mnist-model.onnx deleted file mode 100644 index bb189a52..00000000 Binary files a/how-to-use-azureml/deployment/onnx/mnist-model.onnx and /dev/null differ diff --git a/how-to-use-azureml/deployment/onnx/mnist.py b/how-to-use-azureml/deployment/onnx/mnist.py deleted file mode 100644 index c2c344bf..00000000 --- a/how-to-use-azureml/deployment/onnx/mnist.py +++ /dev/null @@ -1,135 +0,0 @@ -# This is a modified version of https://github.com/pytorch/examples/blob/master/mnist/main.py which is -# licensed under BSD 3-Clause (https://github.com/pytorch/examples/blob/master/LICENSE) - -from __future__ import print_function -import argparse -import torch -import torch.nn as nn -import torch.nn.functional as F -import torch.optim as optim -from torchvision import datasets, transforms -import os - - -class Net(nn.Module): - def __init__(self): - super(Net, self).__init__() - self.conv1 = nn.Conv2d(1, 10, kernel_size=5) - self.conv2 = nn.Conv2d(10, 20, kernel_size=5) - self.conv2_drop = nn.Dropout2d() - self.fc1 = nn.Linear(320, 50) - self.fc2 = nn.Linear(50, 10) - - def forward(self, x): - x = F.relu(F.max_pool2d(self.conv1(x), 2)) - x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2)) - x = x.view(-1, 320) - x = F.relu(self.fc1(x)) - x = F.dropout(x, training=self.training) - x = self.fc2(x) - return F.log_softmax(x, dim=1) - - -def train(args, model, device, train_loader, optimizer, epoch, output_dir): - model.train() - for batch_idx, (data, target) in enumerate(train_loader): - data, target = data.to(device), target.to(device) - optimizer.zero_grad() - output = model(data) - loss = F.nll_loss(output, target) - loss.backward() - optimizer.step() - if batch_idx % args.log_interval == 0: - print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format( - epoch, batch_idx * len(data), len(train_loader.dataset), - 100. * batch_idx / len(train_loader), loss.item())) - - -def test(args, model, device, test_loader): - model.eval() - test_loss = 0 - correct = 0 - with torch.no_grad(): - for data, target in test_loader: - data, target = data.to(device), target.to(device) - output = model(data) - test_loss += F.nll_loss(output, target, size_average=False, reduce=True).item() # sum up batch loss - pred = output.max(1, keepdim=True)[1] # get the index of the max log-probability - correct += pred.eq(target.view_as(pred)).sum().item() - - test_loss /= len(test_loader.dataset) - print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format( - test_loss, correct, len(test_loader.dataset), - 100. * correct / len(test_loader.dataset))) - - -def main(): - # Training settings - parser = argparse.ArgumentParser(description='PyTorch MNIST Example') - parser.add_argument('--batch-size', type=int, default=64, metavar='N', - help='input batch size for training (default: 64)') - parser.add_argument('--test-batch-size', type=int, default=1000, metavar='N', - help='input batch size for testing (default: 1000)') - parser.add_argument('--epochs', type=int, default=5, metavar='N', - help='number of epochs to train (default: 5)') - parser.add_argument('--lr', type=float, default=0.01, metavar='LR', - help='learning rate (default: 0.01)') - parser.add_argument('--momentum', type=float, default=0.5, metavar='M', - help='SGD momentum (default: 0.5)') - parser.add_argument('--no-cuda', action='store_true', default=False, - help='disables CUDA training') - parser.add_argument('--seed', type=int, default=1, metavar='S', - help='random seed (default: 1)') - parser.add_argument('--log-interval', type=int, default=10, metavar='N', - help='how many batches to wait before logging training status') - parser.add_argument('--output-dir', type=str, default='outputs') - args = parser.parse_args() - use_cuda = not args.no_cuda and torch.cuda.is_available() - - torch.manual_seed(args.seed) - - device = torch.device("cuda" if use_cuda else "cpu") - - output_dir = args.output_dir - os.makedirs(output_dir, exist_ok=True) - - kwargs = {'num_workers': 1, 'pin_memory': True} if use_cuda else {} - # MNIST dataset - datasets.MNIST.resources = [ - ("train-images-idx3-ubyte.gz", - "f68b3c2dcbeaaa9fbdd348bbdeb94873"), - ("train-labels-idx1-ubyte.gz", - "d53e105ee54ea40749a09fcbcd1e9432"), - ("t10k-images-idx3-ubyte.gz", - "9fb629c4189551a2d022fa330f9573f3"), - ("t10k-labels-idx1-ubyte.gz", - "ec29112dd5afa0611ce80d1b7f02629c") - ] - train_loader = torch.utils.data.DataLoader( - datasets.MNIST('data', train=True, download=True, - transform=transforms.Compose([transforms.ToTensor(), - transforms.Normalize((0.1307,), (0.3081,))]) - ), - batch_size=args.batch_size, shuffle=True, **kwargs) - test_loader = torch.utils.data.DataLoader( - datasets.MNIST('data', train=False, - transform=transforms.Compose([transforms.ToTensor(), - transforms.Normalize((0.1307,), (0.3081,))]) - ), - batch_size=args.test_batch_size, shuffle=True, **kwargs) - - model = Net().to(device) - optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum) - - for epoch in range(1, args.epochs + 1): - train(args, model, device, train_loader, optimizer, epoch, output_dir) - test(args, model, device, test_loader) - - # save model - dummy_input = torch.randn(1, 1, 28, 28, device=device) - model_path = os.path.join(output_dir, 'mnist.onnx') - torch.onnx.export(model, dummy_input, model_path) - - -if __name__ == '__main__': - main() diff --git a/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.ipynb b/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.ipynb deleted file mode 100644 index 83ac283e..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.ipynb +++ /dev/null @@ -1,434 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved. \n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# YOLO Real-time Object Detection using ONNX on AzureML\n", - "\n", - "This example shows how to convert the TinyYOLO model from CoreML to ONNX and operationalize it as a web service using Azure Machine Learning services and the ONNX Runtime.\n", - "\n", - "## What is ONNX\n", - "ONNX is an open format for representing machine learning and deep learning models. ONNX enables open and interoperable AI by enabling data scientists and developers to use the tools of their choice without worrying about lock-in and flexibility to deploy to a variety of platforms. ONNX is developed and supported by a community of partners including Microsoft, Facebook, and Amazon. For more information, explore the [ONNX website](http://onnx.ai).\n", - "\n", - "## YOLO Details\n", - "You Only Look Once (YOLO) is a state-of-the-art, real-time object detection system. For more information about YOLO, please visit the [YOLO website](https://pjreddie.com/darknet/yolo/)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "\n", - "To make the best use of your time, make sure you have done the following:\n", - "\n", - "* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n", - "* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration](../../../configuration.ipynb) notebook to:\n", - " * install the AML SDK\n", - " * create a workspace and its configuration file (config.json)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Install necessary packages\n", - "\n", - "You'll need to run the following commands to use this tutorial:\n", - "\n", - "```sh\n", - "pip install onnxmltools\n", - "pip install coremltools # use this on Linux and Mac\n", - "pip install git+https://github.com/apple/coremltools # use this on Windows\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Convert model to ONNX\n", - "\n", - "First we download the CoreML model. We use the CoreML model from [Matthijs Hollemans's tutorial](https://github.com/hollance/YOLO-CoreML-MPSNNGraph). This may take a few minutes." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import urllib.request\n", - "\n", - "coreml_model_url = \"https://github.com/hollance/YOLO-CoreML-MPSNNGraph/raw/master/TinyYOLO-CoreML/TinyYOLO-CoreML/TinyYOLO.mlmodel\"\n", - "urllib.request.urlretrieve(coreml_model_url, filename=\"TinyYOLO.mlmodel\")\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then we use ONNXMLTools to convert the model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import onnxmltools\n", - "import coremltools\n", - "\n", - "# Load a CoreML model\n", - "coreml_model = coremltools.utils.load_spec('TinyYOLO.mlmodel')\n", - "\n", - "# Convert from CoreML into ONNX\n", - "onnx_model = onnxmltools.convert_coreml(coreml_model, 'TinyYOLOv2')\n", - "\n", - "# Fix the preprocessor bias in the ImageScaler\n", - "for init in onnx_model.graph.initializer:\n", - " if init.name == 'scalerPreprocessor_bias':\n", - " init.dims[1] = 1\n", - "\n", - "# Save ONNX model\n", - "onnxmltools.utils.save_model(onnx_model, 'tinyyolov2.onnx')\n", - "\n", - "import os\n", - "print(os.path.getsize('tinyyolov2.onnx'))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploying as a web service with Azure ML\n", - "\n", - "### Load Azure ML workspace\n", - "\n", - "We begin by instantiating a workspace object from the existing workspace created earlier in the configuration notebook." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.location, ws.resource_group, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Registering your model with Azure ML\n", - "\n", - "Now we upload the model and register it in the workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "model = Model.register(model_path = \"tinyyolov2.onnx\",\n", - " model_name = \"tinyyolov2\",\n", - " tags = {\"onnx\": \"demo\"},\n", - " description = \"TinyYOLO\",\n", - " workspace = ws)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Displaying your registered models\n", - "\n", - "You can optionally list out all the models that you have registered in this workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "models = ws.models\n", - "for name, m in models.items():\n", - " print(\"Name:\", name,\"\\tVersion:\", m.version, \"\\tDescription:\", m.description, m.tags)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write scoring file\n", - "\n", - "We are now going to deploy our ONNX model on Azure ML using the ONNX Runtime. We begin by writing a score.py file that will be invoked by the web service call. The `init()` function is called once when the container is started so we load the model using the ONNX Runtime into a global session object." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import json\n", - "import time\n", - "import sys\n", - "import os\n", - "from azureml.core.model import Model\n", - "import numpy as np # we're going to use numpy to process input and output data\n", - "import onnxruntime # to inference ONNX models, we use the ONNX Runtime\n", - "\n", - "def init():\n", - " global session\n", - " model = Model.get_model_path(model_name = 'tinyyolov2')\n", - " session = onnxruntime.InferenceSession(model)\n", - "\n", - "def preprocess(input_data_json):\n", - " # convert the JSON data into the tensor input\n", - " return np.array(json.loads(input_data_json)['data']).astype('float32')\n", - "\n", - "def postprocess(result):\n", - " return np.array(result).tolist()\n", - "\n", - "def run(input_data_json):\n", - " try:\n", - " start = time.time() # start timer\n", - " input_data = preprocess(input_data_json)\n", - " input_name = session.get_inputs()[0].name # get the id of the first input of the model \n", - " result = session.run([], {input_name: input_data})\n", - " end = time.time() # stop timer\n", - " return {\"result\": postprocess(result),\n", - " \"time\": end - start}\n", - " except Exception as e:\n", - " result = str(e)\n", - " return {\"error\": result}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Setting up inference configuration\n", - "First we create a YAML file that specifies which dependencies we would like to see in our container. Please note that you must include azureml-defaults with verion >= 1.0.45 as a pip dependency, because it contains the functionality needed to host the model as a web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", - "myenv = CondaDependencies.create(pip_packages=[\"numpy\", \"onnxruntime==1.15.1\", \"azureml-core\", \"azureml-defaults\"])\n", - "\n", - "with open(\"myenv.yml\",\"w\") as f:\n", - " f.write(myenv.serialize_to_string())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then we create the inference configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "from azureml.core.environment import Environment\n", - "\n", - "\n", - "myenv = Environment.from_conda_specification(name=\"myenv\", file_path=\"myenv.yml\")\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploy the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice\n", - "\n", - "aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, \n", - " memory_gb = 1, \n", - " tags = {'demo': 'onnx'}, \n", - " description = 'web service for TinyYOLO ONNX model')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following cell will take a few minutes to run as the model gets packaged up and deployed to ACI." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aci_service_name = 'my-aci-service-tiny-yolo'\n", - "print(\"Service\", aci_service_name)\n", - "aci_service = Model.deploy(ws, aci_service_name, [model], inference_config, aciconfig)\n", - "aci_service.wait_for_deployment(True)\n", - "print(aci_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case the deployment fails, you can check the logs. Make sure to delete your aci_service before trying again." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if aci_service.state != 'Healthy':\n", - " # run this command for debugging.\n", - " print(aci_service.get_logs())\n", - " aci_service.delete()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Success!\n", - "\n", - "If you've made it this far, you've deployed a working web service that does object detection using an ONNX model. You can get the URL for the webservice with the code below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(aci_service.scoring_uri)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When you are eventually done using the web service, remember to delete it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aci_service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "viswamy" - } - ], - "category": "deployment", - "compute": [ - "local" - ], - "datasets": [ - "PASCAL VOC" - ], - "deployment": [ - "Azure Container Instance" - ], - "exclude_from_index": false, - "framework": [ - "ONNX" - ], - "friendly_name": "Convert and deploy TinyYolo with ONNX Runtime", - "index_order": 5, - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.5" - }, - "star_tag": [ - "featured" - ], - "tags": [ - "ONNX Converter" - ], - "task": "Object Detection" - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.yml b/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.yml deleted file mode 100644 index e8c7ffb9..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: onnx-convert-aml-deploy-tinyyolo -dependencies: -- pip: - - azureml-sdk - - numpy - - git+https://github.com/apple/coremltools@v2.1 - - onnx<1.7.0 - - onnxmltools diff --git a/how-to-use-azureml/deployment/onnx/onnx-mnist-predict-input.json b/how-to-use-azureml/deployment/onnx/onnx-mnist-predict-input.json deleted file mode 100644 index 5b69977b..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-mnist-predict-input.json +++ /dev/null @@ -1 +0,0 @@ -{"inputs": {"Input3": {"dims": ["1", "1", "28", "28"], "dataType": 1, "rawData": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAPwAAQEAAAAAAAAAAAAAAgEAAAABAAAAAAAAAMEEAAAAAAAAAAAAAYEEAAIA/AAAAAAAAmEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQEEAAAAAAAAAAAAA4EAAAAAAAACAPwAAIEEAAAAAAAAAQAAAAEAAAIBBAAAAAAAAQEAAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4EAAAABBAAAAAAAAAEEAAAAAAAAAAAAAAEEAAAAAAAAAAAAAmEEAAAAAAAAAAAAAgD8AAKhBAAAAAAAAgEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMEEAAAAAAAAAAAAAIEEAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQQQAAAAAAAHBBAAAgQQAA0EEAAAhCAACIQQAAmkIAADVDAAAyQwAADEIAAIBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWQwAAfkMAAHpDAAB7QwAAc0MAAHxDAAB8QwAAf0MAADRCAADAQAAAAAAAAKBAAAAAAAAAEEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOBAAACQQgAATUMAAH9DAABuQwAAc0MAAH9DAAB+QwAAe0MAAHhDAABJQwAARkMAAGRCAAAAAAAAmEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWkMAAH9DAABxQwAAf0MAAHlDAAB6QwAAe0MAAHpDAAB/QwAAf0MAAHJDAABgQwAAREIAAAAAAABAQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgD8AAABAAABAQAAAAEAAAABAAACAPwAAAAAAAIJCAABkQwAAf0MAAH5DAAB0QwAA7kIAAAhCAAAkQgAA3EIAAHpDAAB/QwAAeEMAAPhCAACgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAACAPwAAgD8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBBAAAAAAAAeEIAAM5CAADiQgAA6kIAAAhCAAAAAAAAAAAAAAAAAABIQwAAdEMAAH9DAAB/QwAAAAAAAEBBAAAAAAAAAAAAAAAAAAAAAAAAAEAAAIA/AAAAAAAAAAAAAAAAAAAAAAAAgD8AAABAAAAAAAAAAAAAAABAAACAQAAAAAAAADBBAAAAAAAA4EAAAMBAAAAAAAAAlkIAAHRDAAB/QwAAf0MAAIBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAQAAAQEAAAIBAAACAQAAAAAAAAGBBAAAAAAAAAAAAAAAAAAAQQQAAAAAAAABAAAAAAAAAAAAAAAhCAAB/QwAAf0MAAH1DAAAgQQAAIEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAQAAAQEAAAABAAAAAAAAAAAAAAEBAAAAAQAAAAAAAAFBBAAAwQQAAAAAAAAAAAAAAAAAAwEAAAEBBAADGQgAAf0MAAH5DAAB4QwAAcEEAAEBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIA/AACAPwAAgD8AAAAAAAAAAAAAAAAAAAAAAACAPwAAgD8AAAAAAAAAAAAAoEAAAMBAAAAwQQAAAAAAAAAAAACIQQAAOEMAAHdDAAB/QwAAc0MAAFBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAACAQAAAgEAAAAAAAAAwQQAAAAAAAExCAAC8QgAAqkIAAKBAAACgQAAAyEEAAHZDAAB2QwAAf0MAAFBDAAAAAAAAEEEAAAAAAAAAAAAAAAAAAAAAAACAQAAAgD8AAAAAAAAAAAAAgD8AAOBAAABwQQAAmEEAAMZCAADOQgAANkMAAD1DAABtQwAAfUMAAHxDAAA/QwAAPkMAAGNDAABzQwAAfEMAAFJDAACQQQAA4EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAAAAAAAAAAAAAAABCAADaQgAAOUMAAHdDAAB/QwAAckMAAH9DAAB0QwAAf0MAAH9DAAByQwAAe0MAAH9DAABwQwAAf0MAAH9DAABaQwAA+EIAABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAD+QgAAf0MAAGtDAAB/QwAAf0MAAHdDAABlQwAAVEMAAHJDAAB6QwAAf0MAAH9DAAB4QwAAf0MAAH1DAAB5QwAAf0MAAHNDAAAqQwAAQEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMEEAAAAAAAAQQQAAfUMAAH9DAAB/QwAAaUMAAEpDAACqQgAAAAAAAFRCAABEQwAAbkMAAH9DAABjQwAAbkMAAA5DAADaQgAAQUMAAH9DAABwQwAAf0MAADRDAAAAAAAAAAAAAAAAAAAAAAAAwEAAAAAAAACwQQAAgD8AAHVDAABzQwAAfkMAAH9DAABZQwAAa0MAAGJDAABVQwAAdEMAAHtDAAB/QwAAb0MAAJpCAAAAAAAAAAAAAKBBAAA2QwAAd0MAAG9DAABzQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAAAAlQwAAe0MAAH9DAAB1QwAAf0MAAHJDAAB9QwAAekMAAH9DAABFQwAA1kIAAGxCAAAAAAAAkEEAAABAAADAQAAAAAAAAFhCAAB/QwAAHkMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwEEAAAAAAAAAAAAAwEAAAAhCAAAnQwAAQkMAADBDAAA3QwAAJEMAADBCAAAAQAAAIEEAAMBAAADAQAAAAAAAAAAAAACgQAAAAAAAAIA/AAAAAAAAYEEAAABAAAAAAAAAAAAAAAAAAAAAAAAAIEEAAAAAAABgQQAAAAAAAEBBAAAAAAAAoEAAAAAAAACAPwAAAAAAAMBAAAAAAAAA4EAAAAAAAAAAAAAAAAAAAABBAAAAAAAAIEEAAAAAAACgQAAAAAAAAAAAAAAgQQAAAAAAAAAAAAAAAAAAAAAAAAAAAABgQQAAAAAAAIBAAAAAAAAAAAAAAMhBAAAAAAAAAAAAABBBAAAAAAAAAAAAABBBAAAAAAAAMEEAAAAAAACAPwAAAAAAAAAAAAAAQAAAAAAAAAAAAADgQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="}}, "outputFilter": ["Plus214_Output_0"]} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.ipynb b/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.ipynb deleted file mode 100644 index d21fba44..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.ipynb +++ /dev/null @@ -1,228 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register ONNX model and deploy as webservice\n", - "\n", - "Following this notebook, you will:\n", - "\n", - " - Learn how to register an ONNX in your Azure Machine Learning Workspace.\n", - " - Deploy your model as a web service in an Azure Container Instance." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "\n", - "If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, make sure you go through the [configuration notebook](../../../configuration.ipynb) to install the Azure Machine Learning Python SDK and create a workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import azureml.core\n", - "\n", - "# Check core SDK version number.\n", - "print('SDK version:', azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize workspace\n", - "\n", - "Create a [Workspace](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.workspace%28class%29?view=azure-ml-py) object from your persisted configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "create workspace" - ] - }, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Register model\n", - "\n", - "Register a file or folder as a model by calling [Model.register()](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.model.model?view=azure-ml-py#register-workspace--model-path--model-name--tags-none--properties-none--description-none--datasets-none--model-framework-none--model-framework-version-none--child-paths-none-). For this example, we have provided a trained ONNX MNIST model(`mnist-model.onnx` in the notebook's directory).\n", - "\n", - "In addition to the content of the model file itself, your registered model will also store model metadata -- model description, tags, and framework information -- that will be useful when managing and deploying models in your workspace. Using tags, for instance, you can categorize your models and apply filters when listing models in your workspace. Also, marking this model with the scikit-learn framework will simplify deploying it as a web service, as we'll see later." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "register model from file" - ] - }, - "outputs": [], - "source": [ - "from azureml.core import Model\n", - "\n", - "model = Model.register(workspace=ws,\n", - " model_name='mnist-sample', # Name of the registered model in your workspace.\n", - " model_path='mnist-model.onnx', # Local ONNX model to upload and register as a model.\n", - " model_framework=Model.Framework.ONNX , # Framework used to create the model.\n", - " model_framework_version='1.3', # Version of ONNX used to create the model.\n", - " description='Onnx MNIST model')\n", - "\n", - "print('Name:', model.name)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy model\n", - "\n", - "Deploy your model as a web service using [Model.deploy()](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.model.model?view=azure-ml-py#deploy-workspace--name--models--inference-config--deployment-config-none--deployment-target-none-). Web services take one or more models, load them in an environment, and run them on one of several supported deployment targets.\n", - "\n", - "For this example, we will deploy the ONNX model to an Azure Container Instance (ACI)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Use a default environment (for supported models)\n", - "\n", - "The Azure Machine Learning service provides a default environment for supported model frameworks, including ONNX, based on the metadata you provided when registering your model. This is the easiest way to deploy your model.\n", - "\n", - "**Note**: This step can take several minutes." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Webservice\n", - "from azureml.exceptions import WebserviceException\n", - "\n", - "service_name = 'onnx-mnist-service'\n", - "\n", - "# Remove any existing service under the same name.\n", - "try:\n", - " Webservice(ws, service_name).delete()\n", - "except WebserviceException:\n", - " pass\n", - "\n", - "service = Model.deploy(ws, service_name, [model])\n", - "service.wait_for_deployment(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "After your model is deployed, perform a call to the web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import requests\n", - "\n", - "headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}\n", - "\n", - "if service.auth_enabled:\n", - " headers['Authorization'] = 'Bearer '+ service.get_keys()[0]\n", - "elif service.token_auth_enabled:\n", - " headers['Authorization'] = 'Bearer '+ service.get_token()[0]\n", - "\n", - "scoring_uri = service.scoring_uri\n", - "print(scoring_uri)\n", - "with open('onnx-mnist-predict-input.json', 'rb') as data_file:\n", - " response = requests.post(\n", - " scoring_uri, data=data_file, headers=headers)\n", - "print(response.status_code)\n", - "print(response.elapsed)\n", - "print(response.json())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When you are finished testing your service, clean up the deployment." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "vaidyas" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.yml b/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.yml deleted file mode 100644 index 4671dc87..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: onnx-model-register-and-deploy -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.ipynb b/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.ipynb deleted file mode 100644 index 04d04c3f..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.ipynb +++ /dev/null @@ -1,416 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved. \n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# ResNet50 Image Classification using ONNX and AzureML\n", - "\n", - "This example shows how to deploy the ResNet50 ONNX model as a web service using Azure Machine Learning services and the ONNX Runtime.\n", - "\n", - "## What is ONNX\n", - "ONNX is an open format for representing machine learning and deep learning models. ONNX enables open and interoperable AI by enabling data scientists and developers to use the tools of their choice without worrying about lock-in and flexibility to deploy to a variety of platforms. ONNX is developed and supported by a community of partners including Microsoft, Facebook, and Amazon. For more information, explore the [ONNX website](http://onnx.ai).\n", - "\n", - "## ResNet50 Details\n", - "ResNet classifies the major object in an input image into a set of 1000 pre-defined classes. For more information about the ResNet50 model and how it was created can be found on the [ONNX Model Zoo github](https://github.com/onnx/models/tree/master/vision/classification/resnet). " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "\n", - "To make the best use of your time, make sure you have done the following:\n", - "\n", - "* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n", - "* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration notebook](../../../configuration.ipynb) to:\n", - " * install the AML SDK\n", - " * create a workspace and its configuration file (config.json)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Download pre-trained ONNX model from ONNX Model Zoo.\n", - "\n", - "Download the [ResNet50v2 model and test data](https://s3.amazonaws.com/onnx-model-zoo/resnet/resnet50v2/resnet50v2.tar.gz) and extract it in the same folder as this tutorial notebook.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import urllib.request\n", - "\n", - "onnx_model_url = \"https://s3.amazonaws.com/onnx-model-zoo/resnet/resnet50v2/resnet50v2.tar.gz\"\n", - "urllib.request.urlretrieve(onnx_model_url, filename=\"resnet50v2.tar.gz\")\n", - "\n", - "!tar xvzf resnet50v2.tar.gz" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploying as a web service with Azure ML" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Load your Azure ML workspace\n", - "\n", - "We begin by instantiating a workspace object from the existing workspace created earlier in the configuration notebook." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.location, ws.resource_group, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Register your model with Azure ML\n", - "\n", - "Now we upload the model and register it in the workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "model = Model.register(model_path = \"resnet50v2/resnet50v2.onnx\",\n", - " model_name = \"resnet50v2\",\n", - " tags = {\"onnx\": \"demo\"},\n", - " description = \"ResNet50v2 from ONNX Model Zoo\",\n", - " workspace = ws)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Displaying your registered models\n", - "\n", - "You can optionally list out all the models that you have registered in this workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "models = ws.models\n", - "for name, m in models.items():\n", - " print(\"Name:\", name,\"\\tVersion:\", m.version, \"\\tDescription:\", m.description, m.tags)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write scoring file\n", - "\n", - "We are now going to deploy our ONNX model on Azure ML using the ONNX Runtime. We begin by writing a score.py file that will be invoked by the web service call. The `init()` function is called once when the container is started so we load the model using the ONNX Runtime into a global session object." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import json\n", - "import time\n", - "import sys\n", - "import os\n", - "import numpy as np # we're going to use numpy to process input and output data\n", - "import onnxruntime # to inference ONNX models, we use the ONNX Runtime\n", - "\n", - "def softmax(x):\n", - " x = x.reshape(-1)\n", - " e_x = np.exp(x - np.max(x))\n", - " return e_x / e_x.sum(axis=0)\n", - "\n", - "def init():\n", - " global session\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'resnet50v2.onnx')\n", - " session = onnxruntime.InferenceSession(model, None)\n", - "\n", - "def preprocess(input_data_json):\n", - " # convert the JSON data into the tensor input\n", - " img_data = np.array(json.loads(input_data_json)['data']).astype('float32')\n", - " \n", - " #normalize\n", - " mean_vec = np.array([0.485, 0.456, 0.406])\n", - " stddev_vec = np.array([0.229, 0.224, 0.225])\n", - " norm_img_data = np.zeros(img_data.shape).astype('float32')\n", - " for i in range(img_data.shape[0]):\n", - " norm_img_data[i,:,:] = (img_data[i,:,:]/255 - mean_vec[i]) / stddev_vec[i]\n", - "\n", - " return norm_img_data\n", - "\n", - "def postprocess(result):\n", - " return softmax(np.array(result)).tolist()\n", - "\n", - "def run(input_data_json):\n", - " try:\n", - " start = time.time()\n", - " # load in our data which is expected as NCHW 224x224 image\n", - " input_data = preprocess(input_data_json)\n", - " input_name = session.get_inputs()[0].name # get the id of the first input of the model \n", - " result = session.run([], {input_name: input_data})\n", - " end = time.time() # stop timer\n", - " return {\"result\": postprocess(result),\n", - " \"time\": end - start}\n", - " except Exception as e:\n", - " result = str(e)\n", - " return {\"error\": result}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create inference configuration" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "First we create a YAML file that specifies which dependencies we would like to see in our container." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", - "\n", - "myenv = CondaDependencies.create(pip_packages=[\"numpy\", \"onnxruntime==1.15.1\", \"azureml-core\", \"azureml-defaults\"])\n", - "\n", - "with open(\"myenv.yml\",\"w\") as f:\n", - " f.write(myenv.serialize_to_string())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create the inference configuration object. Please note that you must indicate azureml-defaults with verion >= 1.0.45 as a pip dependency, because it contains the functionality needed to host the model as a web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "from azureml.core.environment import Environment\n", - "\n", - "\n", - "myenv = Environment.from_conda_specification(name=\"myenv\", file_path=\"myenv.yml\")\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploy the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice\n", - "\n", - "aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, \n", - " memory_gb = 1, \n", - " tags = {'demo': 'onnx'}, \n", - " description = 'web service for ResNet50 ONNX model')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following cell will likely take a few minutes to run as well." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from random import randint\n", - "\n", - "aci_service_name = 'onnx-demo-resnet50'+str(randint(0,100))\n", - "print(\"Service\", aci_service_name)\n", - "aci_service = Model.deploy(ws, aci_service_name, [model], inference_config, aciconfig)\n", - "aci_service.wait_for_deployment(True)\n", - "print(aci_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case the deployment fails, you can check the logs. Make sure to delete your aci_service before trying again." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if aci_service.state != 'Healthy':\n", - " # run this command for debugging.\n", - " print(aci_service.get_logs())\n", - " aci_service.delete()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Success!\n", - "\n", - "If you've made it this far, you've deployed a working web service that does image classification using an ONNX model. You can get the URL for the webservice with the code below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(aci_service.scoring_uri)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When you are eventually done using the web service, remember to delete it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aci_service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "viswamy" - } - ], - "category": "deployment", - "compute": [ - "Local" - ], - "datasets": [ - "ImageNet" - ], - "deployment": [ - "Azure Container Instance" - ], - "exclude_from_index": false, - "framework": [ - "ONNX" - ], - "friendly_name": "Deploy ResNet50 with ONNX Runtime", - "index_order": 4, - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.5" - }, - "star_tag": [], - "tags": [ - "ONNX Model Zoo" - ], - "task": "Image Classification" - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.yml b/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.yml deleted file mode 100644 index a80e6bb0..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: onnx-modelzoo-aml-deploy-resnet50 -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.ipynb b/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.ipynb deleted file mode 100644 index ee84a916..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.ipynb +++ /dev/null @@ -1,659 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved. \n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# MNIST Handwritten Digit Classification using ONNX and AzureML\n", - "\n", - "This example shows how to train a model on the MNIST data using PyTorch, save it as an ONNX model, and deploy it as a web service using Azure Machine Learning services and the ONNX Runtime.\n", - "\n", - "## What is ONNX\n", - "ONNX is an open format for representing machine learning and deep learning models. ONNX enables open and interoperable AI by enabling data scientists and developers to use the tools of their choice without worrying about lock-in and flexibility to deploy to a variety of platforms. ONNX is developed and supported by a community of partners including Microsoft, Facebook, and Amazon. For more information, explore the [ONNX website](http://onnx.ai).\n", - "\n", - "## MNIST Details\n", - "The Modified National Institute of Standards and Technology (MNIST) dataset consists of 70,000 grayscale images. Each image is a handwritten digit of 28x28 pixels, representing numbers from 0 to 9. For more information about the MNIST dataset, please visit [Yan LeCun's website](http://yann.lecun.com/exdb/mnist/). For more information about the MNIST model and how it was created can be found on the [ONNX Model Zoo github](https://github.com/onnx/models/tree/master/vision/classification/mnist). " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n", - "* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration notebook](../../../configuration.ipynb) to:\n", - " * install the AML SDK\n", - " * create a workspace and its configuration file (`config.json`)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize workspace\n", - "Initialize a [Workspace](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#workspace) object from the existing workspace you created in the Prerequisites step. `Workspace.from_config()` creates a workspace object from the details stored in `config.json`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.workspace import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print('Workspace name: ' + ws.name, \n", - " 'Azure region: ' + ws.location, \n", - " 'Resource group: ' + ws.resource_group, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Train model\n", - "\n", - "### Create a remote compute target\n", - "You will need to create a [compute target](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#compute-target) to execute your training script on. In this tutorial, you create an [Azure Batch AI](https://docs.microsoft.com/azure/batch-ai/overview) cluster as your training compute resource. This code creates a cluster for you if it does not already exist in your workspace.\n", - "\n", - "**Creation of the cluster takes approximately 5 minutes.** If the cluster is already in your workspace this code will skip the cluster creation process." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget, AmlCompute\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# choose a name for your cluster\n", - "cluster_name = \"gpu-cluster\"\n", - "\n", - "try:\n", - " compute_target = ComputeTarget(workspace=ws, name=cluster_name)\n", - " print('Found existing compute target.')\n", - "except ComputeTargetException:\n", - " print('Creating a new compute target...')\n", - " compute_config = AmlCompute.provisioning_configuration(vm_size='Standard_NC6s_v3', \n", - " max_nodes=6)\n", - "\n", - " # create the cluster\n", - " compute_target = ComputeTarget.create(ws, cluster_name, compute_config)\n", - "\n", - "compute_target.wait_for_completion(show_output=True)\n", - "\n", - "# Use the 'status' property to get a detailed status for the current cluster. \n", - "print(compute_target.status.serialize())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The above code creates a GPU cluster. If you instead want to create a CPU cluster, provide a different VM size to the `vm_size` parameter, such as `STANDARD_D2_V2`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create a project directory\n", - "Create a directory that will contain all the necessary code from your local machine that you will need access to on the remote resource. This includes the training script and any additional files your training script depends on." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "project_folder = './pytorch-mnist'\n", - "os.makedirs(project_folder, exist_ok=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copy the training script [`mnist.py`](mnist.py) into your project directory. Make sure the training script has the following code to create an ONNX file:\n", - "```python\n", - "dummy_input = torch.randn(1, 1, 28, 28, device=device)\n", - "model_path = os.path.join(output_dir, 'mnist.onnx')\n", - "torch.onnx.export(model, dummy_input, model_path)\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import shutil\n", - "shutil.copy('mnist.py', project_folder)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create an experiment\n", - "Create an [Experiment](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#experiment) to track all the runs in your workspace for this transfer learning PyTorch tutorial. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Experiment\n", - "\n", - "experiment_name = 'pytorch1-mnist'\n", - "experiment = Experiment(ws, name=experiment_name)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create a PyTorch estimator\n", - "The AML SDK's PyTorch estimator enables you to easily submit PyTorch training jobs for both single-node and distributed runs. For more information on the PyTorch estimator, refer [here](https://docs.microsoft.com/azure/machine-learning/service/how-to-train-pytorch). The following code will define a single-node PyTorch job." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Environment, ScriptRunConfig\n", - "\n", - "pytorch_env = Environment.get(ws, name='AzureML-acpt-pytorch-1.13-cuda11.7')\n", - "\n", - "estimator = ScriptRunConfig(source_directory=project_folder,\n", - " compute_target=compute_target,\n", - " script='mnist.py',\n", - " environment=pytorch_env)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `script_params` parameter is a dictionary containing the command-line arguments to your training script `entry_script`. Please note the following:\n", - "- We specified the output directory as `./outputs`. The `outputs` directory is specially treated by AML in that all the content in this directory gets uploaded to your workspace as part of your run history. The files written to this directory are therefore accessible even once your remote run is over. In this tutorial, we will save our trained model to this output directory.\n", - "\n", - "To leverage the Azure VM's GPU for training, we set `use_gpu=True`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Submit job\n", - "Run your experiment by submitting your estimator object. Note that this call is asynchronous." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "run = experiment.submit(estimator)\n", - "print(run.get_details())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Monitor your run\n", - "You can monitor the progress of the run with a Jupyter widget. Like the run submission, the widget is asynchronous and provides live updates every 10-15 seconds until the job completes." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.widgets import RunDetails\n", - "RunDetails(run).show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Alternatively, you can block until the script has completed training before running more code." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "run.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Download the model (optional)\n", - "\n", - "Once the run completes, you can choose to download the ONNX model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# list all the files from the run\n", - "run.get_file_names()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model_path = os.path.join('outputs', 'mnist.onnx')\n", - "run.download_file(model_path, output_file_path=model_path)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Register the model\n", - "You can also register the model from your run to your workspace. The `model_path` parameter takes in the relative path on the remote VM to the model file in your `outputs` directory. You can then deploy this registered model as a web service through the AML SDK." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "model = run.register_model(model_name='mnist', model_path=model_path)\n", - "print(model.name, model.id, model.version, sep = '\\t')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Displaying your registered models (optional)\n", - "\n", - "You can optionally list out all the models that you have registered in this workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "models = ws.models\n", - "for name, m in models.items():\n", - " print(\"Name:\", name,\"\\tVersion:\", m.version, \"\\tDescription:\", m.description, m.tags)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploying as a web service\n", - "\n", - "### Write scoring file\n", - "\n", - "We are now going to deploy our ONNX model on Azure ML using the ONNX Runtime. We begin by writing a score.py file that will be invoked by the web service call. The `init()` function is called once when the container is started so we load the model using the ONNX Runtime into a global session object." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import json\n", - "import time\n", - "import sys\n", - "import os\n", - "from azureml.core.model import Model\n", - "import numpy as np # we're going to use numpy to process input and output data\n", - "import onnxruntime # to inference ONNX models, we use the ONNX Runtime\n", - "\n", - "def init():\n", - " global session\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'mnist.onnx')\n", - " session = onnxruntime.InferenceSession(model)\n", - "\n", - "def preprocess(input_data_json):\n", - " # convert the JSON data into the tensor input\n", - " return np.array(json.loads(input_data_json)['data']).astype('float32')\n", - "\n", - "def postprocess(result):\n", - " # We use argmax to pick the highest confidence label\n", - " return int(np.argmax(np.array(result).squeeze(), axis=0))\n", - "\n", - "def run(input_data_json):\n", - " try:\n", - " start = time.time() # start timer\n", - " input_data = preprocess(input_data_json)\n", - " input_name = session.get_inputs()[0].name # get the id of the first input of the model \n", - " result = session.run([], {input_name: input_data})\n", - " end = time.time() # stop timer\n", - " return {\"result\": postprocess(result),\n", - " \"time\": end - start}\n", - " except Exception as e:\n", - " result = str(e)\n", - " return {\"error\": result}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create inference configuration\n", - "First we create a YAML file that specifies which dependencies we would like to see in our container. Please note that you must indicate azureml-defaults with verion >= 1.0.45 as a pip dependency, because it contains the functionality needed to host the model as a web service." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", - "myenv = CondaDependencies.create(pip_packages=[\"numpy\",\"onnxruntime==1.15.1\",\"azureml-core\", \"azureml-defaults\"])\n", - "\n", - "with open(\"myenv.yml\",\"w\") as f:\n", - " f.write(myenv.serialize_to_string())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then we setup the inference configuration " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "from azureml.core.environment import Environment\n", - "\n", - "\n", - "myenv = Environment.from_conda_specification(name=\"myenv\", file_path=\"myenv.yml\")\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Deploy the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.webservice import AciWebservice\n", - "\n", - "aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, \n", - " memory_gb = 1, \n", - " tags = {'demo': 'onnx'}, \n", - " description = 'web service for MNIST ONNX model')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following cell will likely take a few minutes to run as well." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "from random import randint\n", - "\n", - "aci_service_name = 'onnx-demo-mnist'+str(randint(0,100))\n", - "print(\"Service\", aci_service_name)\n", - "aci_service = Model.deploy(ws, aci_service_name, [model], inference_config, aciconfig)\n", - "aci_service.wait_for_deployment(True)\n", - "print(aci_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case the deployment fails, you can check the logs. Make sure to delete your aci_service before trying again." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if aci_service.state != 'Healthy':\n", - " # run this command for debugging.\n", - " print(aci_service.get_logs())\n", - " aci_service.delete()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Success!\n", - "\n", - "If you've made it this far, you've deployed a working web service that does handwritten digit classification using an ONNX model. You can get the URL for the webservice with the code below." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(aci_service.scoring_uri)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When you are eventually done using the web service, remember to delete it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "aci_service.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "viswamy" - } - ], - "category": "deployment", - "compute": [ - "AML Compute" - ], - "datasets": [ - "MNIST" - ], - "deployment": [ - "Azure Container Instance" - ], - "exclude_from_index": false, - "framework": [ - "ONNX" - ], - "friendly_name": "Train MNIST in PyTorch, convert, and deploy with ONNX Runtime", - "index_order": 3, - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.18" - }, - "star_tag": [], - "tags": [ - "ONNX Converter" - ], - "task": "Image Classification", - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "state": { - "c899ddfc2b134ca9b89a4f278ac7c997": { - "model_module": "@jupyter-widgets/base", - "model_module_version": "1.1.0", - "model_name": "LayoutModel", - "state": {} - }, - "d146cbdbd4e04710b3eebc15a66957ce": { - "model_module": "azureml_widgets", - "model_module_version": "1.0.0", - "model_name": "ShowRunDetailsModel", - "state": { - "child_runs_metrics": {}, - "compute_target_status": { - "current_node_count": 1, - "node_state_counts": { - "idleNodeCount": 1, - "leavingNodeCount": 0, - "preparingNodeCount": 0, - "runningNodeCount": 0, - "unusableNodeCount": 0 - }, - "provisioning_errors": null, - "provisioning_state": "Succeeded", - "requested_node_count": 1, - "scale_settings": { - "autoScale": { - "initialNodeCount": 0, - "maximumNodeCount": 4, - "minimumNodeCount": 0 - }, - "manual": null - }, - "vm_size": "Standard_NC6s_v3" - }, - "error": "", - "layout": "IPY_MODEL_c899ddfc2b134ca9b89a4f278ac7c997", - "run_id": "pytorch1-mnist_1537876563990", - "run_logs": "Uploading experiment status to history service.\nAdding run profile attachment azureml-logs/60_control_log.txt\nUploading experiment status to history service.\nAdding run profile attachment azureml-logs/80_driver_log.txt\nScript process exited with code 0\nUploading driver log...\nFinalizing run...\n\nDownloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz\nDownloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz\nDownloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz\nDownloading http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz\nProcessing...\nDone!\nTrain Epoch: 1 [0/60000 (0%)]\tLoss: 2.365850\nTrain Epoch: 1 [640/60000 (1%)]\tLoss: 2.305295\nTrain Epoch: 1 [1280/60000 (2%)]\tLoss: 2.301407\nTrain Epoch: 1 [1920/60000 (3%)]\tLoss: 2.316538\nTrain Epoch: 1 [2560/60000 (4%)]\tLoss: 2.255810\nTrain Epoch: 1 [3200/60000 (5%)]\tLoss: 2.224511\nTrain Epoch: 1 [3840/60000 (6%)]\tLoss: 2.216569\nTrain Epoch: 1 [4480/60000 (7%)]\tLoss: 2.181396\nTrain Epoch: 1 [5120/60000 (9%)]\tLoss: 2.116898\nTrain Epoch: 1 [5760/60000 (10%)]\tLoss: 2.045963\nTrain Epoch: 1 [6400/60000 (11%)]\tLoss: 1.973494\nTrain Epoch: 1 [7040/60000 (12%)]\tLoss: 1.968609\nTrain Epoch: 1 [7680/60000 (13%)]\tLoss: 1.787280\nTrain Epoch: 1 [8320/60000 (14%)]\tLoss: 1.735044\nTrain Epoch: 1 [8960/60000 (15%)]\tLoss: 1.680426\nTrain Epoch: 1 [9600/60000 (16%)]\tLoss: 1.486279\nTrain Epoch: 1 [10240/60000 (17%)]\tLoss: 1.545747\nTrain Epoch: 1 [10880/60000 (18%)]\tLoss: 1.193543\nTrain Epoch: 1 [11520/60000 (19%)]\tLoss: 1.652350\nTrain Epoch: 1 [12160/60000 (20%)]\tLoss: 0.982182\nTrain Epoch: 1 [12800/60000 (21%)]\tLoss: 1.331902\nTrain Epoch: 1 [13440/60000 (22%)]\tLoss: 1.089598\nTrain Epoch: 1 [14080/60000 (23%)]\tLoss: 0.998703\nTrain Epoch: 1 [14720/60000 (25%)]\tLoss: 0.992036\nTrain Epoch: 1 [15360/60000 (26%)]\tLoss: 0.979473\nTrain Epoch: 1 [16000/60000 (27%)]\tLoss: 1.141276\nTrain Epoch: 1 [16640/60000 (28%)]\tLoss: 0.836921\nTrain Epoch: 1 [17280/60000 (29%)]\tLoss: 0.764657\nTrain Epoch: 1 [17920/60000 (30%)]\tLoss: 0.826818\nTrain Epoch: 1 [18560/60000 (31%)]\tLoss: 0.837834\nTrain Epoch: 1 [19200/60000 (32%)]\tLoss: 0.899033\nTrain Epoch: 1 [19840/60000 (33%)]\tLoss: 0.868245\nTrain Epoch: 1 [20480/60000 (34%)]\tLoss: 0.930491\nTrain Epoch: 1 [21120/60000 (35%)]\tLoss: 0.795202\nTrain Epoch: 1 [21760/60000 (36%)]\tLoss: 0.575117\nTrain Epoch: 1 [22400/60000 (37%)]\tLoss: 0.577884\nTrain Epoch: 1 [23040/60000 (38%)]\tLoss: 0.708801\nTrain Epoch: 1 [23680/60000 (39%)]\tLoss: 0.927512\nTrain Epoch: 1 [24320/60000 (41%)]\tLoss: 0.598836\nTrain Epoch: 1 [24960/60000 (42%)]\tLoss: 0.944021\nTrain Epoch: 1 [25600/60000 (43%)]\tLoss: 0.811654\nTrain Epoch: 1 [26240/60000 (44%)]\tLoss: 0.590322\nTrain Epoch: 1 [26880/60000 (45%)]\tLoss: 0.555104\nTrain Epoch: 1 [27520/60000 (46%)]\tLoss: 0.795565\nTrain Epoch: 1 [28160/60000 (47%)]\tLoss: 0.603378\nTrain Epoch: 1 [28800/60000 (48%)]\tLoss: 0.552437\nTrain Epoch: 1 [29440/60000 (49%)]\tLoss: 0.662064\nTrain Epoch: 1 [30080/60000 (50%)]\tLoss: 0.682541\nTrain Epoch: 1 [30720/60000 (51%)]\tLoss: 0.659051\nTrain Epoch: 1 [31360/60000 (52%)]\tLoss: 0.781052\nTrain Epoch: 1 [32000/60000 (53%)]\tLoss: 0.595491\nTrain Epoch: 1 [32640/60000 (54%)]\tLoss: 0.367289\nTrain Epoch: 1 [33280/60000 (55%)]\tLoss: 0.459428\nTrain Epoch: 1 [33920/60000 (57%)]\tLoss: 0.819237\nTrain Epoch: 1 [34560/60000 (58%)]\tLoss: 0.773166\nTrain Epoch: 1 [35200/60000 (59%)]\tLoss: 0.557691\nTrain Epoch: 1 [35840/60000 (60%)]\tLoss: 0.854719\nTrain Epoch: 1 [36480/60000 (61%)]\tLoss: 0.497524\nTrain Epoch: 1 [37120/60000 (62%)]\tLoss: 0.582861\nTrain Epoch: 1 [37760/60000 (63%)]\tLoss: 0.839674\nTrain Epoch: 1 [38400/60000 (64%)]\tLoss: 0.557275\nTrain Epoch: 1 [39040/60000 (65%)]\tLoss: 0.419819\nTrain Epoch: 1 [39680/60000 (66%)]\tLoss: 0.694659\nTrain Epoch: 1 [40320/60000 (67%)]\tLoss: 0.678524\nTrain Epoch: 1 [40960/60000 (68%)]\tLoss: 0.514364\nTrain Epoch: 1 [41600/60000 (69%)]\tLoss: 0.400510\nTrain Epoch: 1 [42240/60000 (70%)]\tLoss: 0.526099\nTrain Epoch: 1 [42880/60000 (71%)]\tLoss: 0.387087\nTrain Epoch: 1 [43520/60000 (72%)]\tLoss: 0.730123\nTrain Epoch: 1 [44160/60000 (74%)]\tLoss: 0.678924\nTrain Epoch: 1 [44800/60000 (75%)]\tLoss: 0.425195\nTrain Epoch: 1 [45440/60000 (76%)]\tLoss: 0.656437\nTrain Epoch: 1 [46080/60000 (77%)]\tLoss: 0.348130\nTrain Epoch: 1 [46720/60000 (78%)]\tLoss: 0.487442\nTrain Epoch: 1 [47360/60000 (79%)]\tLoss: 0.649533\nTrain Epoch: 1 [48000/60000 (80%)]\tLoss: 0.541395\nTrain Epoch: 1 [48640/60000 (81%)]\tLoss: 0.464202\nTrain Epoch: 1 [49280/60000 (82%)]\tLoss: 0.750336\nTrain Epoch: 1 [49920/60000 (83%)]\tLoss: 0.548484\nTrain Epoch: 1 [50560/60000 (84%)]\tLoss: 0.421382\nTrain Epoch: 1 [51200/60000 (85%)]\tLoss: 0.680766\nTrain Epoch: 1 [51840/60000 (86%)]\tLoss: 0.483003\nTrain Epoch: 1 [52480/60000 (87%)]\tLoss: 0.610840\nTrain Epoch: 1 [53120/60000 (88%)]\tLoss: 0.483278\nTrain Epoch: 1 [53760/60000 (90%)]\tLoss: 0.553161\nTrain Epoch: 1 [54400/60000 (91%)]\tLoss: 0.465237\nTrain Epoch: 1 [55040/60000 (92%)]\tLoss: 0.558884\nTrain Epoch: 1 [55680/60000 (93%)]\tLoss: 0.528969\nTrain Epoch: 1 [56320/60000 (94%)]\tLoss: 0.370189\nTrain Epoch: 1 [56960/60000 (95%)]\tLoss: 0.379404\nTrain Epoch: 1 [57600/60000 (96%)]\tLoss: 0.263894\nTrain Epoch: 1 [58240/60000 (97%)]\tLoss: 0.432745\nTrain Epoch: 1 [58880/60000 (98%)]\tLoss: 0.455681\nTrain Epoch: 1 [59520/60000 (99%)]\tLoss: 0.483901\n/azureml-envs/azureml_de892a6d0f01a442356c3959dd42e13b/lib/python3.6/site-packages/torch/nn/functional.py:54: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.\n warnings.warn(warning.format(ret))\n\nTest set: Average loss: 0.2073, Accuracy: 9384/10000 (94%)\n\nTrain Epoch: 2 [0/60000 (0%)]\tLoss: 0.390797\nTrain Epoch: 2 [640/60000 (1%)]\tLoss: 0.214512\nTrain Epoch: 2 [1280/60000 (2%)]\tLoss: 0.226415\nTrain Epoch: 2 [1920/60000 (3%)]\tLoss: 0.491764\nTrain Epoch: 2 [2560/60000 (4%)]\tLoss: 0.333604\nTrain Epoch: 2 [3200/60000 (5%)]\tLoss: 0.514239\nTrain Epoch: 2 [3840/60000 (6%)]\tLoss: 0.430618\nTrain Epoch: 2 [4480/60000 (7%)]\tLoss: 0.579474\nTrain Epoch: 2 [5120/60000 (9%)]\tLoss: 0.259456\nTrain Epoch: 2 [5760/60000 (10%)]\tLoss: 0.651198\nTrain Epoch: 2 [6400/60000 (11%)]\tLoss: 0.338269\nTrain Epoch: 2 [7040/60000 (12%)]\tLoss: 0.335233\nTrain Epoch: 2 [7680/60000 (13%)]\tLoss: 0.518132\nTrain Epoch: 2 [8320/60000 (14%)]\tLoss: 0.363488\nTrain Epoch: 2 [8960/60000 (15%)]\tLoss: 0.437092\nTrain Epoch: 2 [9600/60000 (16%)]\tLoss: 0.362660\nTrain Epoch: 2 [10240/60000 (17%)]\tLoss: 0.432337\nTrain Epoch: 2 [10880/60000 (18%)]\tLoss: 0.360611\nTrain Epoch: 2 [11520/60000 (19%)]\tLoss: 0.305427\nTrain Epoch: 2 [12160/60000 (20%)]\tLoss: 0.347859\nTrain Epoch: 2 [12800/60000 (21%)]\tLoss: 0.408770\nTrain Epoch: 2 [13440/60000 (22%)]\tLoss: 0.469975\nTrain Epoch: 2 [14080/60000 (23%)]\tLoss: 0.673716\nTrain Epoch: 2 [14720/60000 (25%)]\tLoss: 0.388876\nTrain Epoch: 2 [15360/60000 (26%)]\tLoss: 0.462371\nTrain Epoch: 2 [16000/60000 (27%)]\tLoss: 0.530107\nTrain Epoch: 2 [16640/60000 (28%)]\tLoss: 0.448767\nTrain Epoch: 2 [17280/60000 (29%)]\tLoss: 0.412764\nTrain Epoch: 2 [17920/60000 (30%)]\tLoss: 0.301494\nTrain Epoch: 2 [18560/60000 (31%)]\tLoss: 0.465599\nTrain Epoch: 2 [19200/60000 (32%)]\tLoss: 0.434249\nTrain Epoch: 2 [19840/60000 (33%)]\tLoss: 0.324006\nTrain Epoch: 2 [20480/60000 (34%)]\tLoss: 0.447446\nTrain Epoch: 2 [21120/60000 (35%)]\tLoss: 0.291222\nTrain Epoch: 2 [21760/60000 (36%)]\tLoss: 0.557065\nTrain Epoch: 2 [22400/60000 (37%)]\tLoss: 0.552659\nTrain Epoch: 2 [23040/60000 (38%)]\tLoss: 0.378901\nTrain Epoch: 2 [23680/60000 (39%)]\tLoss: 0.360550\nTrain Epoch: 2 [24320/60000 (41%)]\tLoss: 0.283795\nTrain Epoch: 2 [24960/60000 (42%)]\tLoss: 0.475816\nTrain Epoch: 2 [25600/60000 (43%)]\tLoss: 0.283652\nTrain Epoch: 2 [26240/60000 (44%)]\tLoss: 0.276265\nTrain Epoch: 2 [26880/60000 (45%)]\tLoss: 0.527902\nTrain Epoch: 2 [27520/60000 (46%)]\tLoss: 0.437130\nTrain Epoch: 2 [28160/60000 (47%)]\tLoss: 0.277132\nTrain Epoch: 2 [28800/60000 (48%)]\tLoss: 0.471580\nTrain Epoch: 2 [29440/60000 (49%)]\tLoss: 0.380154\nTrain Epoch: 2 [30080/60000 (50%)]\tLoss: 0.232072\nTrain Epoch: 2 [30720/60000 (51%)]\tLoss: 0.366567\nTrain Epoch: 2 [31360/60000 (52%)]\tLoss: 0.469628\nTrain Epoch: 2 [32000/60000 (53%)]\tLoss: 0.440017\nTrain Epoch: 2 [32640/60000 (54%)]\tLoss: 0.421814\nTrain Epoch: 2 [33280/60000 (55%)]\tLoss: 0.367687\nTrain Epoch: 2 [33920/60000 (57%)]\tLoss: 0.448384\nTrain Epoch: 2 [34560/60000 (58%)]\tLoss: 0.550283\nTrain Epoch: 2 [35200/60000 (59%)]\tLoss: 0.609798\nTrain Epoch: 2 [35840/60000 (60%)]\tLoss: 0.461334\nTrain Epoch: 2 [36480/60000 (61%)]\tLoss: 0.443838\nTrain Epoch: 2 [37120/60000 (62%)]\tLoss: 0.306666\nTrain Epoch: 2 [37760/60000 (63%)]\tLoss: 0.432083\nTrain Epoch: 2 [38400/60000 (64%)]\tLoss: 0.277025\nTrain Epoch: 2 [39040/60000 (65%)]\tLoss: 0.298752\nTrain Epoch: 2 [39680/60000 (66%)]\tLoss: 0.427435\nTrain Epoch: 2 [40320/60000 (67%)]\tLoss: 0.374736\nTrain Epoch: 2 [40960/60000 (68%)]\tLoss: 0.246496\nTrain Epoch: 2 [41600/60000 (69%)]\tLoss: 0.662259\nTrain Epoch: 2 [42240/60000 (70%)]\tLoss: 0.497635\nTrain Epoch: 2 [42880/60000 (71%)]\tLoss: 0.237556\nTrain Epoch: 2 [43520/60000 (72%)]\tLoss: 0.194535\nTrain Epoch: 2 [44160/60000 (74%)]\tLoss: 0.258943\nTrain Epoch: 2 [44800/60000 (75%)]\tLoss: 0.437360\nTrain Epoch: 2 [45440/60000 (76%)]\tLoss: 0.355489\nTrain Epoch: 2 [46080/60000 (77%)]\tLoss: 0.335020\nTrain Epoch: 2 [46720/60000 (78%)]\tLoss: 0.565189\nTrain Epoch: 2 [47360/60000 (79%)]\tLoss: 0.430366\nTrain Epoch: 2 [48000/60000 (80%)]\tLoss: 0.266303\nTrain Epoch: 2 [48640/60000 (81%)]\tLoss: 0.172954\nTrain Epoch: 2 [49280/60000 (82%)]\tLoss: 0.245803\nTrain Epoch: 2 [49920/60000 (83%)]\tLoss: 0.426530\nTrain Epoch: 2 [50560/60000 (84%)]\tLoss: 0.468984\nTrain Epoch: 2 [51200/60000 (85%)]\tLoss: 0.370892\nTrain Epoch: 2 [51840/60000 (86%)]\tLoss: 0.300021\nTrain Epoch: 2 [52480/60000 (87%)]\tLoss: 0.392199\nTrain Epoch: 2 [53120/60000 (88%)]\tLoss: 0.510658\nTrain Epoch: 2 [53760/60000 (90%)]\tLoss: 0.376290\nTrain Epoch: 2 [54400/60000 (91%)]\tLoss: 0.273752\nTrain Epoch: 2 [55040/60000 (92%)]\tLoss: 0.234505\nTrain Epoch: 2 [55680/60000 (93%)]\tLoss: 0.610978\nTrain Epoch: 2 [56320/60000 (94%)]\tLoss: 0.154850\nTrain Epoch: 2 [56960/60000 (95%)]\tLoss: 0.374254\nTrain Epoch: 2 [57600/60000 (96%)]\tLoss: 0.292167\nTrain Epoch: 2 [58240/60000 (97%)]\tLoss: 0.478376\nTrain Epoch: 2 [58880/60000 (98%)]\tLoss: 0.303128\nTrain Epoch: 2 [59520/60000 (99%)]\tLoss: 0.376779\n\nTest set: Average loss: 0.1297, Accuracy: 9597/10000 (96%)\n\nTrain Epoch: 3 [0/60000 (0%)]\tLoss: 0.450588\nTrain Epoch: 3 [640/60000 (1%)]\tLoss: 0.361118\nTrain Epoch: 3 [1280/60000 (2%)]\tLoss: 0.374497\nTrain Epoch: 3 [1920/60000 (3%)]\tLoss: 0.312127\nTrain Epoch: 3 [2560/60000 (4%)]\tLoss: 0.353896\nTrain Epoch: 3 [3200/60000 (5%)]\tLoss: 0.320840\nTrain Epoch: 3 [3840/60000 (6%)]\tLoss: 0.218477\nTrain Epoch: 3 [4480/60000 (7%)]\tLoss: 0.295629\nTrain Epoch: 3 [5120/60000 (9%)]\tLoss: 0.339400\nTrain Epoch: 3 [5760/60000 (10%)]\tLoss: 0.170357\nTrain Epoch: 3 [6400/60000 (11%)]\tLoss: 0.416447\nTrain Epoch: 3 [7040/60000 (12%)]\tLoss: 0.320326\nTrain Epoch: 3 [7680/60000 (13%)]\tLoss: 0.318410\nTrain Epoch: 3 [8320/60000 (14%)]\tLoss: 0.384793\nTrain Epoch: 3 [8960/60000 (15%)]\tLoss: 0.343415\nTrain Epoch: 3 [9600/60000 (16%)]\tLoss: 0.284627\nTrain Epoch: 3 [10240/60000 (17%)]\tLoss: 0.151805\nTrain Epoch: 3 [10880/60000 (18%)]\tLoss: 0.401332\nTrain Epoch: 3 [11520/60000 (19%)]\tLoss: 0.253159\nTrain Epoch: 3 [12160/60000 (20%)]\tLoss: 0.339563\nTrain Epoch: 3 [12800/60000 (21%)]\tLoss: 0.237430\nTrain Epoch: 3 [13440/60000 (22%)]\tLoss: 0.311402\nTrain Epoch: 3 [14080/60000 (23%)]\tLoss: 0.241667\nTrain Epoch: 3 [14720/60000 (25%)]\tLoss: 0.265347\nTrain Epoch: 3 [15360/60000 (26%)]\tLoss: 0.367453\nTrain Epoch: 3 [16000/60000 (27%)]\tLoss: 0.190671\nTrain Epoch: 3 [16640/60000 (28%)]\tLoss: 0.313052\nTrain Epoch: 3 [17280/60000 (29%)]\tLoss: 0.368028\nTrain Epoch: 3 [17920/60000 (30%)]\tLoss: 0.268639\nTrain Epoch: 3 [18560/60000 (31%)]\tLoss: 0.341066\nTrain Epoch: 3 [19200/60000 (32%)]\tLoss: 0.457961\nTrain Epoch: 3 [19840/60000 (33%)]\tLoss: 0.732400\nTrain Epoch: 3 [20480/60000 (34%)]\tLoss: 0.330679\nTrain Epoch: 3 [21120/60000 (35%)]\tLoss: 0.279778\nTrain Epoch: 3 [21760/60000 (36%)]\tLoss: 0.305972\nTrain Epoch: 3 [22400/60000 (37%)]\tLoss: 0.402131\nTrain Epoch: 3 [23040/60000 (38%)]\tLoss: 0.345302\nTrain Epoch: 3 [23680/60000 (39%)]\tLoss: 0.251726\nTrain Epoch: 3 [24320/60000 (41%)]\tLoss: 0.152062\nTrain Epoch: 3 [24960/60000 (42%)]\tLoss: 0.149305\nTrain Epoch: 3 [25600/60000 (43%)]\tLoss: 0.364678\nTrain Epoch: 3 [26240/60000 (44%)]\tLoss: 0.067165\nTrain Epoch: 3 [26880/60000 (45%)]\tLoss: 0.229927\nTrain Epoch: 3 [27520/60000 (46%)]\tLoss: 0.236894\nTrain Epoch: 3 [28160/60000 (47%)]\tLoss: 0.486373\nTrain Epoch: 3 [28800/60000 (48%)]\tLoss: 0.453053\nTrain Epoch: 3 [29440/60000 (49%)]\tLoss: 0.283823\nTrain Epoch: 3 [30080/60000 (50%)]\tLoss: 0.185119\nTrain Epoch: 3 [30720/60000 (51%)]\tLoss: 0.381274\nTrain Epoch: 3 [31360/60000 (52%)]\tLoss: 0.394533\nTrain Epoch: 3 [32000/60000 (53%)]\tLoss: 0.392791\nTrain Epoch: 3 [32640/60000 (54%)]\tLoss: 0.230672\nTrain Epoch: 3 [33280/60000 (55%)]\tLoss: 0.393846\nTrain Epoch: 3 [33920/60000 (57%)]\tLoss: 0.676802\nTrain Epoch: 3 [34560/60000 (58%)]\tLoss: 0.160434\nTrain Epoch: 3 [35200/60000 (59%)]\tLoss: 0.211318\nTrain Epoch: 3 [35840/60000 (60%)]\tLoss: 0.245763\nTrain Epoch: 3 [36480/60000 (61%)]\tLoss: 0.198454\nTrain Epoch: 3 [37120/60000 (62%)]\tLoss: 0.243536\nTrain Epoch: 3 [37760/60000 (63%)]\tLoss: 0.151804\nTrain Epoch: 3 [38400/60000 (64%)]\tLoss: 0.176093\nTrain Epoch: 3 [39040/60000 (65%)]\tLoss: 0.237228\nTrain Epoch: 3 [39680/60000 (66%)]\tLoss: 0.146441\nTrain Epoch: 3 [40320/60000 (67%)]\tLoss: 0.345162\nTrain Epoch: 3 [40960/60000 (68%)]\tLoss: 0.400378\nTrain Epoch: 3 [41600/60000 (69%)]\tLoss: 0.259152\nTrain Epoch: 3 [42240/60000 (70%)]\tLoss: 0.569659\nTrain Epoch: 3 [42880/60000 (71%)]\tLoss: 0.166401\nTrain Epoch: 3 [43520/60000 (72%)]\tLoss: 0.220592\nTrain Epoch: 3 [44160/60000 (74%)]\tLoss: 0.303227\nTrain Epoch: 3 [44800/60000 (75%)]\tLoss: 0.193691\nTrain Epoch: 3 [45440/60000 (76%)]\tLoss: 0.257408\nTrain Epoch: 3 [46080/60000 (77%)]\tLoss: 0.391211\nTrain Epoch: 3 [46720/60000 (78%)]\tLoss: 0.419841\nTrain Epoch: 3 [47360/60000 (79%)]\tLoss: 0.121861\nTrain Epoch: 3 [48000/60000 (80%)]\tLoss: 0.176442\nTrain Epoch: 3 [48640/60000 (81%)]\tLoss: 0.534631\nTrain Epoch: 3 [49280/60000 (82%)]\tLoss: 0.296596\nTrain Epoch: 3 [49920/60000 (83%)]\tLoss: 0.190096\nTrain Epoch: 3 [50560/60000 (84%)]\tLoss: 0.360826\nTrain Epoch: 3 [51200/60000 (85%)]\tLoss: 0.427482\nTrain Epoch: 3 [51840/60000 (86%)]\tLoss: 0.251076\nTrain Epoch: 3 [52480/60000 (87%)]\tLoss: 0.319904\nTrain Epoch: 3 [53120/60000 (88%)]\tLoss: 0.228778\nTrain Epoch: 3 [53760/60000 (90%)]\tLoss: 0.180340\nTrain Epoch: 3 [54400/60000 (91%)]\tLoss: 0.236512\nTrain Epoch: 3 [55040/60000 (92%)]\tLoss: 0.206779\nTrain Epoch: 3 [55680/60000 (93%)]\tLoss: 0.323677\nTrain Epoch: 3 [56320/60000 (94%)]\tLoss: 0.406382\nTrain Epoch: 3 [56960/60000 (95%)]\tLoss: 0.426768\nTrain Epoch: 3 [57600/60000 (96%)]\tLoss: 0.595419\nTrain Epoch: 3 [58240/60000 (97%)]\tLoss: 0.175457\nTrain Epoch: 3 [58880/60000 (98%)]\tLoss: 0.301019\nTrain Epoch: 3 [59520/60000 (99%)]\tLoss: 0.419139\n\nTest set: Average loss: 0.1049, Accuracy: 9686/10000 (97%)\n\nTrain Epoch: 4 [0/60000 (0%)]\tLoss: 0.352631\nTrain Epoch: 4 [640/60000 (1%)]\tLoss: 0.343671\nTrain Epoch: 4 [1280/60000 (2%)]\tLoss: 0.170439\nTrain Epoch: 4 [1920/60000 (3%)]\tLoss: 0.289486\nTrain Epoch: 4 [2560/60000 (4%)]\tLoss: 0.096597\nTrain Epoch: 4 [3200/60000 (5%)]\tLoss: 0.263759\nTrain Epoch: 4 [3840/60000 (6%)]\tLoss: 0.369941\nTrain Epoch: 4 [4480/60000 (7%)]\tLoss: 0.326594\nTrain Epoch: 4 [5120/60000 (9%)]\tLoss: 0.174094\nTrain Epoch: 4 [5760/60000 (10%)]\tLoss: 0.442069\nTrain Epoch: 4 [6400/60000 (11%)]\tLoss: 0.179002\nTrain Epoch: 4 [7040/60000 (12%)]\tLoss: 0.292742\nTrain Epoch: 4 [7680/60000 (13%)]\tLoss: 0.209898\nTrain Epoch: 4 [8320/60000 (14%)]\tLoss: 0.401671\nTrain Epoch: 4 [8960/60000 (15%)]\tLoss: 0.205146\nTrain Epoch: 4 [9600/60000 (16%)]\tLoss: 0.250836\nTrain Epoch: 4 [10240/60000 (17%)]\tLoss: 0.156622\nTrain Epoch: 4 [10880/60000 (18%)]\tLoss: 0.214578\nTrain Epoch: 4 [11520/60000 (19%)]\tLoss: 0.155916\nTrain Epoch: 4 [12160/60000 (20%)]\tLoss: 0.416294\nTrain Epoch: 4 [12800/60000 (21%)]\tLoss: 0.197429\nTrain Epoch: 4 [13440/60000 (22%)]\tLoss: 0.154103\nTrain Epoch: 4 [14080/60000 (23%)]\tLoss: 0.377950\nTrain Epoch: 4 [14720/60000 (25%)]\tLoss: 0.338084\nTrain Epoch: 4 [15360/60000 (26%)]\tLoss: 0.242834\nTrain Epoch: 4 [16000/60000 (27%)]\tLoss: 0.139219\nTrain Epoch: 4 [16640/60000 (28%)]\tLoss: 0.242067\nTrain Epoch: 4 [17280/60000 (29%)]\tLoss: 0.189929\nTrain Epoch: 4 [17920/60000 (30%)]\tLoss: 0.358215\nTrain Epoch: 4 [18560/60000 (31%)]\tLoss: 0.354969\nTrain Epoch: 4 [19200/60000 (32%)]\tLoss: 0.303644\nTrain Epoch: 4 [19840/60000 (33%)]\tLoss: 0.322343\nTrain Epoch: 4 [20480/60000 (34%)]\tLoss: 0.225422\nTrain Epoch: 4 [21120/60000 (35%)]\tLoss: 0.614347\nTrain Epoch: 4 [21760/60000 (36%)]\tLoss: 0.448674\nTrain Epoch: 4 [22400/60000 (37%)]\tLoss: 0.362976\nTrain Epoch: 4 [23040/60000 (38%)]\tLoss: 0.100357\nTrain Epoch: 4 [23680/60000 (39%)]\tLoss: 0.289331\nTrain Epoch: 4 [24320/60000 (41%)]\tLoss: 0.405818\nTrain Epoch: 4 [24960/60000 (42%)]\tLoss: 0.212617\nTrain Epoch: 4 [25600/60000 (43%)]\tLoss: 0.348597\nTrain Epoch: 4 [26240/60000 (44%)]\tLoss: 0.351009\nTrain Epoch: 4 [26880/60000 (45%)]\tLoss: 0.341456\nTrain Epoch: 4 [27520/60000 (46%)]\tLoss: 0.297527\nTrain Epoch: 4 [28160/60000 (47%)]\tLoss: 0.281190\nTrain Epoch: 4 [28800/60000 (48%)]\tLoss: 0.187359\nTrain Epoch: 4 [29440/60000 (49%)]\tLoss: 0.178844\nTrain Epoch: 4 [30080/60000 (50%)]\tLoss: 0.201243\nTrain Epoch: 4 [30720/60000 (51%)]\tLoss: 0.305701\nTrain Epoch: 4 [31360/60000 (52%)]\tLoss: 0.370592\nTrain Epoch: 4 [32000/60000 (53%)]\tLoss: 0.241955\nTrain Epoch: 4 [32640/60000 (54%)]\tLoss: 0.278765\nTrain Epoch: 4 [33280/60000 (55%)]\tLoss: 0.284302\nTrain Epoch: 4 [33920/60000 (57%)]\tLoss: 0.337426\nTrain Epoch: 4 [34560/60000 (58%)]\tLoss: 0.277304\nTrain Epoch: 4 [35200/60000 (59%)]\tLoss: 0.221228\nTrain Epoch: 4 [35840/60000 (60%)]\tLoss: 0.150985\nTrain Epoch: 4 [36480/60000 (61%)]\tLoss: 0.312087\nTrain Epoch: 4 [37120/60000 (62%)]\tLoss: 0.170111\nTrain Epoch: 4 [37760/60000 (63%)]\tLoss: 0.291135\nTrain Epoch: 4 [38400/60000 (64%)]\tLoss: 0.160971\nTrain Epoch: 4 [39040/60000 (65%)]\tLoss: 0.390679\nTrain Epoch: 4 [39680/60000 (66%)]\tLoss: 0.434802\nTrain Epoch: 4 [40320/60000 (67%)]\tLoss: 0.281539\nTrain Epoch: 4 [40960/60000 (68%)]\tLoss: 0.172577\nTrain Epoch: 4 [41600/60000 (69%)]\tLoss: 0.348624\nTrain Epoch: 4 [42240/60000 (70%)]\tLoss: 0.380416\nTrain Epoch: 4 [42880/60000 (71%)]\tLoss: 0.483520\nTrain Epoch: 4 [43520/60000 (72%)]\tLoss: 0.216825\nTrain Epoch: 4 [44160/60000 (74%)]\tLoss: 0.320874\nTrain Epoch: 4 [44800/60000 (75%)]\tLoss: 0.213358\nTrain Epoch: 4 [45440/60000 (76%)]\tLoss: 0.218650\nTrain Epoch: 4 [46080/60000 (77%)]\tLoss: 0.221090\nTrain Epoch: 4 [46720/60000 (78%)]\tLoss: 0.325981\nTrain Epoch: 4 [47360/60000 (79%)]\tLoss: 0.283184\nTrain Epoch: 4 [48000/60000 (80%)]\tLoss: 0.072845\nTrain Epoch: 4 [48640/60000 (81%)]\tLoss: 0.206940\nTrain Epoch: 4 [49280/60000 (82%)]\tLoss: 0.423454\nTrain Epoch: 4 [49920/60000 (83%)]\tLoss: 0.475285\nTrain Epoch: 4 [50560/60000 (84%)]\tLoss: 0.128978\nTrain Epoch: 4 [51200/60000 (85%)]\tLoss: 0.195609\nTrain Epoch: 4 [51840/60000 (86%)]\tLoss: 0.125730\nTrain Epoch: 4 [52480/60000 (87%)]\tLoss: 0.137783\nTrain Epoch: 4 [53120/60000 (88%)]\tLoss: 0.375247\nTrain Epoch: 4 [53760/60000 (90%)]\tLoss: 0.243497\nTrain Epoch: 4 [54400/60000 (91%)]\tLoss: 0.236100\nTrain Epoch: 4 [55040/60000 (92%)]\tLoss: 0.266795\nTrain Epoch: 4 [55680/60000 (93%)]\tLoss: 0.229095\nTrain Epoch: 4 [56320/60000 (94%)]\tLoss: 0.167610\nTrain Epoch: 4 [56960/60000 (95%)]\tLoss: 0.240640\nTrain Epoch: 4 [57600/60000 (96%)]\tLoss: 0.153999\nTrain Epoch: 4 [58240/60000 (97%)]\tLoss: 0.753790\nTrain Epoch: 4 [58880/60000 (98%)]\tLoss: 0.143998\nTrain Epoch: 4 [59520/60000 (99%)]\tLoss: 0.310583\n\nTest set: Average loss: 0.0843, Accuracy: 9739/10000 (97%)\n\nTrain Epoch: 5 [0/60000 (0%)]\tLoss: 0.227892\nTrain Epoch: 5 [640/60000 (1%)]\tLoss: 0.162702\nTrain Epoch: 5 [1280/60000 (2%)]\tLoss: 0.227571\nTrain Epoch: 5 [1920/60000 (3%)]\tLoss: 0.148511\nTrain Epoch: 5 [2560/60000 (4%)]\tLoss: 0.187414\nTrain Epoch: 5 [3200/60000 (5%)]\tLoss: 0.194418\nTrain Epoch: 5 [3840/60000 (6%)]\tLoss: 0.276495\nTrain Epoch: 5 [4480/60000 (7%)]\tLoss: 0.268769\nTrain Epoch: 5 [5120/60000 (9%)]\tLoss: 0.163968\nTrain Epoch: 5 [5760/60000 (10%)]\tLoss: 0.349296\nTrain Epoch: 5 [6400/60000 (11%)]\tLoss: 0.217248\nTrain Epoch: 5 [7040/60000 (12%)]\tLoss: 0.195263\nTrain Epoch: 5 [7680/60000 (13%)]\tLoss: 0.339447\nTrain Epoch: 5 [8320/60000 (14%)]\tLoss: 0.224461\nTrain Epoch: 5 [8960/60000 (15%)]\tLoss: 0.095605\nTrain Epoch: 5 [9600/60000 (16%)]\tLoss: 0.196891\nTrain Epoch: 5 [10240/60000 (17%)]\tLoss: 0.218742\nTrain Epoch: 5 [10880/60000 (18%)]\tLoss: 0.071347\nTrain Epoch: 5 [11520/60000 (19%)]\tLoss: 0.403286\nTrain Epoch: 5 [12160/60000 (20%)]\tLoss: 0.149740\nTrain Epoch: 5 [12800/60000 (21%)]\tLoss: 0.160939\nTrain Epoch: 5 [13440/60000 (22%)]\tLoss: 0.236512\nTrain Epoch: 5 [14080/60000 (23%)]\tLoss: 0.348727\nTrain Epoch: 5 [14720/60000 (25%)]\tLoss: 0.190054\nTrain Epoch: 5 [15360/60000 (26%)]\tLoss: 0.272029\nTrain Epoch: 5 [16000/60000 (27%)]\tLoss: 0.427739\nTrain Epoch: 5 [16640/60000 (28%)]\tLoss: 0.322332\nTrain Epoch: 5 [17280/60000 (29%)]\tLoss: 0.141410\nTrain Epoch: 5 [17920/60000 (30%)]\tLoss: 0.098900\nTrain Epoch: 5 [18560/60000 (31%)]\tLoss: 0.252387\nTrain Epoch: 5 [19200/60000 (32%)]\tLoss: 0.182150\nTrain Epoch: 5 [19840/60000 (33%)]\tLoss: 0.133239\nTrain Epoch: 5 [20480/60000 (34%)]\tLoss: 0.126683\nTrain Epoch: 5 [21120/60000 (35%)]\tLoss: 0.370189\nTrain Epoch: 5 [21760/60000 (36%)]\tLoss: 0.162514\nTrain Epoch: 5 [22400/60000 (37%)]\tLoss: 0.272352\nTrain Epoch: 5 [23040/60000 (38%)]\tLoss: 0.298543\nTrain Epoch: 5 [23680/60000 (39%)]\tLoss: 0.235891\nTrain Epoch: 5 [24320/60000 (41%)]\tLoss: 0.187710\nTrain Epoch: 5 [24960/60000 (42%)]\tLoss: 0.185363\nTrain Epoch: 5 [25600/60000 (43%)]\tLoss: 0.193369\nTrain Epoch: 5 [26240/60000 (44%)]\tLoss: 0.155984\nTrain Epoch: 5 [26880/60000 (45%)]\tLoss: 0.388923\nTrain Epoch: 5 [27520/60000 (46%)]\tLoss: 0.192868\nTrain Epoch: 5 [28160/60000 (47%)]\tLoss: 0.535787\nTrain Epoch: 5 [28800/60000 (48%)]\tLoss: 0.161020\nTrain Epoch: 5 [29440/60000 (49%)]\tLoss: 0.242179\nTrain Epoch: 5 [30080/60000 (50%)]\tLoss: 0.136554\nTrain Epoch: 5 [30720/60000 (51%)]\tLoss: 0.190672\nTrain Epoch: 5 [31360/60000 (52%)]\tLoss: 0.118027\nTrain Epoch: 5 [32000/60000 (53%)]\tLoss: 0.278750\nTrain Epoch: 5 [32640/60000 (54%)]\tLoss: 0.418058\nTrain Epoch: 5 [33280/60000 (55%)]\tLoss: 0.287063\nTrain Epoch: 5 [33920/60000 (57%)]\tLoss: 0.279596\nTrain Epoch: 5 [34560/60000 (58%)]\tLoss: 0.181579\nTrain Epoch: 5 [35200/60000 (59%)]\tLoss: 0.443592\nTrain Epoch: 5 [35840/60000 (60%)]\tLoss: 0.095470\nTrain Epoch: 5 [36480/60000 (61%)]\tLoss: 0.277385\nTrain Epoch: 5 [37120/60000 (62%)]\tLoss: 0.263358\nTrain Epoch: 5 [37760/60000 (63%)]\tLoss: 0.190867\nTrain Epoch: 5 [38400/60000 (64%)]\tLoss: 0.176580\nTrain Epoch: 5 [39040/60000 (65%)]\tLoss: 0.360235\nTrain Epoch: 5 [39680/60000 (66%)]\tLoss: 0.172416\nTrain Epoch: 5 [40320/60000 (67%)]\tLoss: 0.174126\nTrain Epoch: 5 [40960/60000 (68%)]\tLoss: 0.202162\nTrain Epoch: 5 [41600/60000 (69%)]\tLoss: 0.196991\nTrain Epoch: 5 [42240/60000 (70%)]\tLoss: 0.224622\nTrain Epoch: 5 [42880/60000 (71%)]\tLoss: 0.180406\nTrain Epoch: 5 [43520/60000 (72%)]\tLoss: 0.060447\nTrain Epoch: 5 [44160/60000 (74%)]\tLoss: 0.322497\nTrain Epoch: 5 [44800/60000 (75%)]\tLoss: 0.239324\nTrain Epoch: 5 [45440/60000 (76%)]\tLoss: 0.348920\nTrain Epoch: 5 [46080/60000 (77%)]\tLoss: 0.240017\nTrain Epoch: 5 [46720/60000 (78%)]\tLoss: 0.237575\nTrain Epoch: 5 [47360/60000 (79%)]\tLoss: 0.142648\nTrain Epoch: 5 [48000/60000 (80%)]\tLoss: 0.227562\nTrain Epoch: 5 [48640/60000 (81%)]\tLoss: 0.254358\nTrain Epoch: 5 [49280/60000 (82%)]\tLoss: 0.135818\nTrain Epoch: 5 [49920/60000 (83%)]\tLoss: 0.386120\nTrain Epoch: 5 [50560/60000 (84%)]\tLoss: 0.328150\nTrain Epoch: 5 [51200/60000 (85%)]\tLoss: 0.276833\nTrain Epoch: 5 [51840/60000 (86%)]\tLoss: 0.308869\nTrain Epoch: 5 [52480/60000 (87%)]\tLoss: 0.246442\nTrain Epoch: 5 [53120/60000 (88%)]\tLoss: 0.240874\nTrain Epoch: 5 [53760/60000 (90%)]\tLoss: 0.114337\nTrain Epoch: 5 [54400/60000 (91%)]\tLoss: 0.217325\nTrain Epoch: 5 [55040/60000 (92%)]\tLoss: 0.223010\nTrain Epoch: 5 [55680/60000 (93%)]\tLoss: 0.138459\nTrain Epoch: 5 [56320/60000 (94%)]\tLoss: 0.283678\nTrain Epoch: 5 [56960/60000 (95%)]\tLoss: 0.158834\nTrain Epoch: 5 [57600/60000 (96%)]\tLoss: 0.164267\nTrain Epoch: 5 [58240/60000 (97%)]\tLoss: 0.290795\nTrain Epoch: 5 [58880/60000 (98%)]\tLoss: 0.451639\nTrain Epoch: 5 [59520/60000 (99%)]\tLoss: 0.349018\n\nTest set: Average loss: 0.0797, Accuracy: 9758/10000 (98%)\n\nTrain Epoch: 6 [0/60000 (0%)]\tLoss: 0.311334\nTrain Epoch: 6 [640/60000 (1%)]\tLoss: 0.129143\nTrain Epoch: 6 [1280/60000 (2%)]\tLoss: 0.227222\nTrain Epoch: 6 [1920/60000 (3%)]\tLoss: 0.157591\nTrain Epoch: 6 [2560/60000 (4%)]\tLoss: 0.205490\nTrain Epoch: 6 [3200/60000 (5%)]\tLoss: 0.421089\nTrain Epoch: 6 [3840/60000 (6%)]\tLoss: 0.157544\nTrain Epoch: 6 [4480/60000 (7%)]\tLoss: 0.087023\nTrain Epoch: 6 [5120/60000 (9%)]\tLoss: 0.130669\nTrain Epoch: 6 [5760/60000 (10%)]\tLoss: 0.059450\nTrain Epoch: 6 [6400/60000 (11%)]\tLoss: 0.121786\nTrain Epoch: 6 [7040/60000 (12%)]\tLoss: 0.177859\nTrain Epoch: 6 [7680/60000 (13%)]\tLoss: 0.217464\nTrain Epoch: 6 [8320/60000 (14%)]\tLoss: 0.183426\nTrain Epoch: 6 [8960/60000 (15%)]\tLoss: 0.237282\nTrain Epoch: 6 [9600/60000 (16%)]\tLoss: 0.210031\nTrain Epoch: 6 [10240/60000 (17%)]\tLoss: 0.256110\nTrain Epoch: 6 [10880/60000 (18%)]\tLoss: 0.155481\nTrain Epoch: 6 [11520/60000 (19%)]\tLoss: 0.166967\nTrain Epoch: 6 [12160/60000 (20%)]\tLoss: 0.144590\nTrain Epoch: 6 [12800/60000 (21%)]\tLoss: 0.229593\nTrain Epoch: 6 [13440/60000 (22%)]\tLoss: 0.092102\nTrain Epoch: 6 [14080/60000 (23%)]\tLoss: 0.144247\nTrain Epoch: 6 [14720/60000 (25%)]\tLoss: 0.459083\nTrain Epoch: 6 [15360/60000 (26%)]\tLoss: 0.174974\nTrain Epoch: 6 [16000/60000 (27%)]\tLoss: 0.146433\nTrain Epoch: 6 [16640/60000 (28%)]\tLoss: 0.291392\nTrain Epoch: 6 [17280/60000 (29%)]\tLoss: 0.203127\nTrain Epoch: 6 [17920/60000 (30%)]\tLoss: 0.255063\nTrain Epoch: 6 [18560/60000 (31%)]\tLoss: 0.167576\nTrain Epoch: 6 [19200/60000 (32%)]\tLoss: 0.171914\nTrain Epoch: 6 [19840/60000 (33%)]\tLoss: 0.215950\nTrain Epoch: 6 [20480/60000 (34%)]\tLoss: 0.246624\nTrain Epoch: 6 [21120/60000 (35%)]\tLoss: 0.242730\nTrain Epoch: 6 [21760/60000 (36%)]\tLoss: 0.345666\nTrain Epoch: 6 [22400/60000 (37%)]\tLoss: 0.229078\nTrain Epoch: 6 [23040/60000 (38%)]\tLoss: 0.283169\nTrain Epoch: 6 [23680/60000 (39%)]\tLoss: 0.246430\nTrain Epoch: 6 [24320/60000 (41%)]\tLoss: 0.217211\nTrain Epoch: 6 [24960/60000 (42%)]\tLoss: 0.168141\nTrain Epoch: 6 [25600/60000 (43%)]\tLoss: 0.297715\nTrain Epoch: 6 [26240/60000 (44%)]\tLoss: 0.200130\nTrain Epoch: 6 [26880/60000 (45%)]\tLoss: 0.344390\nTrain Epoch: 6 [27520/60000 (46%)]\tLoss: 0.246202\nTrain Epoch: 6 [28160/60000 (47%)]\tLoss: 0.272422\nTrain Epoch: 6 [28800/60000 (48%)]\tLoss: 0.117001\nTrain Epoch: 6 [29440/60000 (49%)]\tLoss: 0.246031\nTrain Epoch: 6 [30080/60000 (50%)]\tLoss: 0.138119\nTrain Epoch: 6 [30720/60000 (51%)]\tLoss: 0.214345\nTrain Epoch: 6 [31360/60000 (52%)]\tLoss: 0.134483\nTrain Epoch: 6 [32000/60000 (53%)]\tLoss: 0.201771\nTrain Epoch: 6 [32640/60000 (54%)]\tLoss: 0.201668\nTrain Epoch: 6 [33280/60000 (55%)]\tLoss: 0.111183\nTrain Epoch: 6 [33920/60000 (57%)]\tLoss: 0.093289\nTrain Epoch: 6 [34560/60000 (58%)]\tLoss: 0.171475\nTrain Epoch: 6 [35200/60000 (59%)]\tLoss: 0.178729\nTrain Epoch: 6 [35840/60000 (60%)]\tLoss: 0.144986\nTrain Epoch: 6 [36480/60000 (61%)]\tLoss: 0.302206\nTrain Epoch: 6 [37120/60000 (62%)]\tLoss: 0.389723\nTrain Epoch: 6 [37760/60000 (63%)]\tLoss: 0.268302\nTrain Epoch: 6 [38400/60000 (64%)]\tLoss: 0.358240\nTrain Epoch: 6 [39040/60000 (65%)]\tLoss: 0.241359\nTrain Epoch: 6 [39680/60000 (66%)]\tLoss: 0.282464\nTrain Epoch: 6 [40320/60000 (67%)]\tLoss: 0.205064\nTrain Epoch: 6 [40960/60000 (68%)]\tLoss: 0.106739\nTrain Epoch: 6 [41600/60000 (69%)]\tLoss: 0.076333\nTrain Epoch: 6 [42240/60000 (70%)]\tLoss: 0.157558\nTrain Epoch: 6 [42880/60000 (71%)]\tLoss: 0.217494\nTrain Epoch: 6 [43520/60000 (72%)]\tLoss: 0.183687\nTrain Epoch: 6 [44160/60000 (74%)]\tLoss: 0.217155\nTrain Epoch: 6 [44800/60000 (75%)]\tLoss: 0.108482\nTrain Epoch: 6 [45440/60000 (76%)]\tLoss: 0.324247\nTrain Epoch: 6 [46080/60000 (77%)]\tLoss: 0.352494\nTrain Epoch: 6 [46720/60000 (78%)]\tLoss: 0.163462\nTrain Epoch: 6 [47360/60000 (79%)]\tLoss: 0.154820\nTrain Epoch: 6 [48000/60000 (80%)]\tLoss: 0.174164\nTrain Epoch: 6 [48640/60000 (81%)]\tLoss: 0.196258\nTrain Epoch: 6 [49280/60000 (82%)]\tLoss: 0.226030\nTrain Epoch: 6 [49920/60000 (83%)]\tLoss: 0.306971\nTrain Epoch: 6 [50560/60000 (84%)]\tLoss: 0.387282\nTrain Epoch: 6 [51200/60000 (85%)]\tLoss: 0.213550\nTrain Epoch: 6 [51840/60000 (86%)]\tLoss: 0.133755\nTrain Epoch: 6 [52480/60000 (87%)]\tLoss: 0.176044\nTrain Epoch: 6 [53120/60000 (88%)]\tLoss: 0.282900\nTrain Epoch: 6 [53760/60000 (90%)]\tLoss: 0.154157\nTrain Epoch: 6 [54400/60000 (91%)]\tLoss: 0.138895\nTrain Epoch: 6 [55040/60000 (92%)]\tLoss: 0.254137\nTrain Epoch: 6 [55680/60000 (93%)]\tLoss: 0.107765\nTrain Epoch: 6 [56320/60000 (94%)]\tLoss: 0.118788\nTrain Epoch: 6 [56960/60000 (95%)]\tLoss: 0.142051\nTrain Epoch: 6 [57600/60000 (96%)]\tLoss: 0.176375\nTrain Epoch: 6 [58240/60000 (97%)]\tLoss: 0.131573\nTrain Epoch: 6 [58880/60000 (98%)]\tLoss: 0.347166\nTrain Epoch: 6 [59520/60000 (99%)]\tLoss: 0.217951\n\nTest set: Average loss: 0.0690, Accuracy: 9776/10000 (98%)\n\nTrain Epoch: 7 [0/60000 (0%)]\tLoss: 0.142441\nTrain Epoch: 7 [640/60000 (1%)]\tLoss: 0.078599\nTrain Epoch: 7 [1280/60000 (2%)]\tLoss: 0.121731\nTrain Epoch: 7 [1920/60000 (3%)]\tLoss: 0.070044\nTrain Epoch: 7 [2560/60000 (4%)]\tLoss: 0.224216\nTrain Epoch: 7 [3200/60000 (5%)]\tLoss: 0.104122\nTrain Epoch: 7 [3840/60000 (6%)]\tLoss: 0.228575\nTrain Epoch: 7 [4480/60000 (7%)]\tLoss: 0.377044\nTrain Epoch: 7 [5120/60000 (9%)]\tLoss: 0.296184\nTrain Epoch: 7 [5760/60000 (10%)]\tLoss: 0.099891\nTrain Epoch: 7 [6400/60000 (11%)]\tLoss: 0.269691\nTrain Epoch: 7 [7040/60000 (12%)]\tLoss: 0.240640\nTrain Epoch: 7 [7680/60000 (13%)]\tLoss: 0.171192\nTrain Epoch: 7 [8320/60000 (14%)]\tLoss: 0.306889\nTrain Epoch: 7 [8960/60000 (15%)]\tLoss: 0.238503\nTrain Epoch: 7 [9600/60000 (16%)]\tLoss: 0.286252\nTrain Epoch: 7 [10240/60000 (17%)]\tLoss: 0.171058\nTrain Epoch: 7 [10880/60000 (18%)]\tLoss: 0.208866\nTrain Epoch: 7 [11520/60000 (19%)]\tLoss: 0.418091\nTrain Epoch: 7 [12160/60000 (20%)]\tLoss: 0.115058\nTrain Epoch: 7 [12800/60000 (21%)]\tLoss: 0.159557\nTrain Epoch: 7 [13440/60000 (22%)]\tLoss: 0.085076\nTrain Epoch: 7 [14080/60000 (23%)]\tLoss: 0.244673\nTrain Epoch: 7 [14720/60000 (25%)]\tLoss: 0.316326\nTrain Epoch: 7 [15360/60000 (26%)]\tLoss: 0.370775\nTrain Epoch: 7 [16000/60000 (27%)]\tLoss: 0.235262\nTrain Epoch: 7 [16640/60000 (28%)]\tLoss: 0.296188\nTrain Epoch: 7 [17280/60000 (29%)]\tLoss: 0.224960\nTrain Epoch: 7 [17920/60000 (30%)]\tLoss: 0.162341\nTrain Epoch: 7 [18560/60000 (31%)]\tLoss: 0.136551\nTrain Epoch: 7 [19200/60000 (32%)]\tLoss: 0.111435\nTrain Epoch: 7 [19840/60000 (33%)]\tLoss: 0.173483\nTrain Epoch: 7 [20480/60000 (34%)]\tLoss: 0.170351\nTrain Epoch: 7 [21120/60000 (35%)]\tLoss: 0.109828\nTrain Epoch: 7 [21760/60000 (36%)]\tLoss: 0.219692\nTrain Epoch: 7 [22400/60000 (37%)]\tLoss: 0.085780\nTrain Epoch: 7 [23040/60000 (38%)]\tLoss: 0.076800\nTrain Epoch: 7 [23680/60000 (39%)]\tLoss: 0.163377\nTrain Epoch: 7 [24320/60000 (41%)]\tLoss: 0.178391\nTrain Epoch: 7 [24960/60000 (42%)]\tLoss: 0.311988\nTrain Epoch: 7 [25600/60000 (43%)]\tLoss: 0.215559\nTrain Epoch: 7 [26240/60000 (44%)]\tLoss: 0.199207\nTrain Epoch: 7 [26880/60000 (45%)]\tLoss: 0.201917\nTrain Epoch: 7 [27520/60000 (46%)]\tLoss: 0.163283\nTrain Epoch: 7 [28160/60000 (47%)]\tLoss: 0.107533\nTrain Epoch: 7 [28800/60000 (48%)]\tLoss: 0.046209\nTrain Epoch: 7 [29440/60000 (49%)]\tLoss: 0.173062\nTrain Epoch: 7 [30080/60000 (50%)]\tLoss: 0.088925\nTrain Epoch: 7 [30720/60000 (51%)]\tLoss: 0.068962\nTrain Epoch: 7 [31360/60000 (52%)]\tLoss: 0.223214\nTrain Epoch: 7 [32000/60000 (53%)]\tLoss: 0.096083\nTrain Epoch: 7 [32640/60000 (54%)]\tLoss: 0.327635\nTrain Epoch: 7 [33280/60000 (55%)]\tLoss: 0.278620\nTrain Epoch: 7 [33920/60000 (57%)]\tLoss: 0.223806\nTrain Epoch: 7 [34560/60000 (58%)]\tLoss: 0.121638\nTrain Epoch: 7 [35200/60000 (59%)]\tLoss: 0.182739\nTrain Epoch: 7 [35840/60000 (60%)]\tLoss: 0.172866\nTrain Epoch: 7 [36480/60000 (61%)]\tLoss: 0.180873\nTrain Epoch: 7 [37120/60000 (62%)]\tLoss: 0.298984\nTrain Epoch: 7 [37760/60000 (63%)]\tLoss: 0.251939\nTrain Epoch: 7 [38400/60000 (64%)]\tLoss: 0.105321\nTrain Epoch: 7 [39040/60000 (65%)]\tLoss: 0.200500\nTrain Epoch: 7 [39680/60000 (66%)]\tLoss: 0.309791\nTrain Epoch: 7 [40320/60000 (67%)]\tLoss: 0.114949\nTrain Epoch: 7 [40960/60000 (68%)]\tLoss: 0.066153\nTrain Epoch: 7 [41600/60000 (69%)]\tLoss: 0.327437\nTrain Epoch: 7 [42240/60000 (70%)]\tLoss: 0.179023\nTrain Epoch: 7 [42880/60000 (71%)]\tLoss: 0.089861\nTrain Epoch: 7 [43520/60000 (72%)]\tLoss: 0.111230\nTrain Epoch: 7 [44160/60000 (74%)]\tLoss: 0.108233\nTrain Epoch: 7 [44800/60000 (75%)]\tLoss: 0.145669\nTrain Epoch: 7 [45440/60000 (76%)]\tLoss: 0.122024\nTrain Epoch: 7 [46080/60000 (77%)]\tLoss: 0.083490\nTrain Epoch: 7 [46720/60000 (78%)]\tLoss: 0.116002\nTrain Epoch: 7 [47360/60000 (79%)]\tLoss: 0.200240\nTrain Epoch: 7 [48000/60000 (80%)]\tLoss: 0.363707\nTrain Epoch: 7 [48640/60000 (81%)]\tLoss: 0.294594\nTrain Epoch: 7 [49280/60000 (82%)]\tLoss: 0.127643\nTrain Epoch: 7 [49920/60000 (83%)]\tLoss: 0.202008\nTrain Epoch: 7 [50560/60000 (84%)]\tLoss: 0.159551\nTrain Epoch: 7 [51200/60000 (85%)]\tLoss: 0.221197\nTrain Epoch: 7 [51840/60000 (86%)]\tLoss: 0.266463\nTrain Epoch: 7 [52480/60000 (87%)]\tLoss: 0.073967\nTrain Epoch: 7 [53120/60000 (88%)]\tLoss: 0.350092\nTrain Epoch: 7 [53760/60000 (90%)]\tLoss: 0.106500\nTrain Epoch: 7 [54400/60000 (91%)]\tLoss: 0.208859\nTrain Epoch: 7 [55040/60000 (92%)]\tLoss: 0.209937\nTrain Epoch: 7 [55680/60000 (93%)]\tLoss: 0.215286\nTrain Epoch: 7 [56320/60000 (94%)]\tLoss: 0.117026\nTrain Epoch: 7 [56960/60000 (95%)]\tLoss: 0.132321\nTrain Epoch: 7 [57600/60000 (96%)]\tLoss: 0.286004\nTrain Epoch: 7 [58240/60000 (97%)]\tLoss: 0.170485\nTrain Epoch: 7 [58880/60000 (98%)]\tLoss: 0.196613\nTrain Epoch: 7 [59520/60000 (99%)]\tLoss: 0.293870\n\nTest set: Average loss: 0.0657, Accuracy: 9801/10000 (98%)\n\nTrain Epoch: 8 [0/60000 (0%)]\tLoss: 0.315451\nTrain Epoch: 8 [640/60000 (1%)]\tLoss: 0.114413\nTrain Epoch: 8 [1280/60000 (2%)]\tLoss: 0.129036\nTrain Epoch: 8 [1920/60000 (3%)]\tLoss: 0.141999\nTrain Epoch: 8 [2560/60000 (4%)]\tLoss: 0.118697\nTrain Epoch: 8 [3200/60000 (5%)]\tLoss: 0.126823\nTrain Epoch: 8 [3840/60000 (6%)]\tLoss: 0.053924\nTrain Epoch: 8 [4480/60000 (7%)]\tLoss: 0.296224\nTrain Epoch: 8 [5120/60000 (9%)]\tLoss: 0.121338\nTrain Epoch: 8 [5760/60000 (10%)]\tLoss: 0.255161\nTrain Epoch: 8 [6400/60000 (11%)]\tLoss: 0.170684\nTrain Epoch: 8 [7040/60000 (12%)]\tLoss: 0.092008\nTrain Epoch: 8 [7680/60000 (13%)]\tLoss: 0.283091\nTrain Epoch: 8 [8320/60000 (14%)]\tLoss: 0.027133\nTrain Epoch: 8 [8960/60000 (15%)]\tLoss: 0.195686\nTrain Epoch: 8 [9600/60000 (16%)]\tLoss: 0.343612\nTrain Epoch: 8 [10240/60000 (17%)]\tLoss: 0.108563\nTrain Epoch: 8 [10880/60000 (18%)]\tLoss: 0.223832\nTrain Epoch: 8 [11520/60000 (19%)]\tLoss: 0.175617\nTrain Epoch: 8 [12160/60000 (20%)]\tLoss: 0.145828\nTrain Epoch: 8 [12800/60000 (21%)]\tLoss: 0.178722\nTrain Epoch: 8 [13440/60000 (22%)]\tLoss: 0.151158\nTrain Epoch: 8 [14080/60000 (23%)]\tLoss: 0.183155\nTrain Epoch: 8 [14720/60000 (25%)]\tLoss: 0.110281\nTrain Epoch: 8 [15360/60000 (26%)]\tLoss: 0.282224\nTrain Epoch: 8 [16000/60000 (27%)]\tLoss: 0.097411\nTrain Epoch: 8 [16640/60000 (28%)]\tLoss: 0.264533\nTrain Epoch: 8 [17280/60000 (29%)]\tLoss: 0.194778\nTrain Epoch: 8 [17920/60000 (30%)]\tLoss: 0.235924\nTrain Epoch: 8 [18560/60000 (31%)]\tLoss: 0.236801\nTrain Epoch: 8 [19200/60000 (32%)]\tLoss: 0.178174\nTrain Epoch: 8 [19840/60000 (33%)]\tLoss: 0.218752\nTrain Epoch: 8 [20480/60000 (34%)]\tLoss: 0.208353\nTrain Epoch: 8 [21120/60000 (35%)]\tLoss: 0.193034\nTrain Epoch: 8 [21760/60000 (36%)]\tLoss: 0.138453\nTrain Epoch: 8 [22400/60000 (37%)]\tLoss: 0.175271\nTrain Epoch: 8 [23040/60000 (38%)]\tLoss: 0.157295\nTrain Epoch: 8 [23680/60000 (39%)]\tLoss: 0.156248\nTrain Epoch: 8 [24320/60000 (41%)]\tLoss: 0.153413\nTrain Epoch: 8 [24960/60000 (42%)]\tLoss: 0.084870\nTrain Epoch: 8 [25600/60000 (43%)]\tLoss: 0.150966\nTrain Epoch: 8 [26240/60000 (44%)]\tLoss: 0.160973\nTrain Epoch: 8 [26880/60000 (45%)]\tLoss: 0.231433\nTrain Epoch: 8 [27520/60000 (46%)]\tLoss: 0.144396\nTrain Epoch: 8 [28160/60000 (47%)]\tLoss: 0.200417\nTrain Epoch: 8 [28800/60000 (48%)]\tLoss: 0.152939\nTrain Epoch: 8 [29440/60000 (49%)]\tLoss: 0.109962\nTrain Epoch: 8 [30080/60000 (50%)]\tLoss: 0.134907\nTrain Epoch: 8 [30720/60000 (51%)]\tLoss: 0.088782\nTrain Epoch: 8 [31360/60000 (52%)]\tLoss: 0.129031\nTrain Epoch: 8 [32000/60000 (53%)]\tLoss: 0.184744\nTrain Epoch: 8 [32640/60000 (54%)]\tLoss: 0.155463\nTrain Epoch: 8 [33280/60000 (55%)]\tLoss: 0.174192\nTrain Epoch: 8 [33920/60000 (57%)]\tLoss: 0.172103\nTrain Epoch: 8 [34560/60000 (58%)]\tLoss: 0.201503\nTrain Epoch: 8 [35200/60000 (59%)]\tLoss: 0.287885\nTrain Epoch: 8 [35840/60000 (60%)]\tLoss: 0.133675\nTrain Epoch: 8 [36480/60000 (61%)]\tLoss: 0.243534\nTrain Epoch: 8 [37120/60000 (62%)]\tLoss: 0.196020\nTrain Epoch: 8 [37760/60000 (63%)]\tLoss: 0.101380\nTrain Epoch: 8 [38400/60000 (64%)]\tLoss: 0.108299\nTrain Epoch: 8 [39040/60000 (65%)]\tLoss: 0.159048\nTrain Epoch: 8 [39680/60000 (66%)]\tLoss: 0.204734\nTrain Epoch: 8 [40320/60000 (67%)]\tLoss: 0.238383\nTrain Epoch: 8 [40960/60000 (68%)]\tLoss: 0.592663\nTrain Epoch: 8 [41600/60000 (69%)]\tLoss: 0.116080\nTrain Epoch: 8 [42240/60000 (70%)]\tLoss: 0.039719\nTrain Epoch: 8 [42880/60000 (71%)]\tLoss: 0.148190\nTrain Epoch: 8 [43520/60000 (72%)]\tLoss: 0.241765\nTrain Epoch: 8 [44160/60000 (74%)]\tLoss: 0.235942\nTrain Epoch: 8 [44800/60000 (75%)]\tLoss: 0.175277\nTrain Epoch: 8 [45440/60000 (76%)]\tLoss: 0.143608\nTrain Epoch: 8 [46080/60000 (77%)]\tLoss: 0.114853\nTrain Epoch: 8 [46720/60000 (78%)]\tLoss: 0.232284\nTrain Epoch: 8 [47360/60000 (79%)]\tLoss: 0.321072\nTrain Epoch: 8 [48000/60000 (80%)]\tLoss: 0.310765\nTrain Epoch: 8 [48640/60000 (81%)]\tLoss: 0.102070\nTrain Epoch: 8 [49280/60000 (82%)]\tLoss: 0.372137\nTrain Epoch: 8 [49920/60000 (83%)]\tLoss: 0.109344\nTrain Epoch: 8 [50560/60000 (84%)]\tLoss: 0.382866\nTrain Epoch: 8 [51200/60000 (85%)]\tLoss: 0.270467\nTrain Epoch: 8 [51840/60000 (86%)]\tLoss: 0.061211\nTrain Epoch: 8 [52480/60000 (87%)]\tLoss: 0.233812\nTrain Epoch: 8 [53120/60000 (88%)]\tLoss: 0.176510\nTrain Epoch: 8 [53760/60000 (90%)]\tLoss: 0.120536\nTrain Epoch: 8 [54400/60000 (91%)]\tLoss: 0.241959\nTrain Epoch: 8 [55040/60000 (92%)]\tLoss: 0.183966\nTrain Epoch: 8 [55680/60000 (93%)]\tLoss: 0.125279\nTrain Epoch: 8 [56320/60000 (94%)]\tLoss: 0.152849\nTrain Epoch: 8 [56960/60000 (95%)]\tLoss: 0.219788\nTrain Epoch: 8 [57600/60000 (96%)]\tLoss: 0.077843\nTrain Epoch: 8 [58240/60000 (97%)]\tLoss: 0.304191\nTrain Epoch: 8 [58880/60000 (98%)]\tLoss: 0.363550\nTrain Epoch: 8 [59520/60000 (99%)]\tLoss: 0.326421\n\nTest set: Average loss: 0.0632, Accuracy: 9807/10000 (98%)\n\nTrain Epoch: 9 [0/60000 (0%)]\tLoss: 0.140965\nTrain Epoch: 9 [640/60000 (1%)]\tLoss: 0.206063\nTrain Epoch: 9 [1280/60000 (2%)]\tLoss: 0.189364\nTrain Epoch: 9 [1920/60000 (3%)]\tLoss: 0.367962\nTrain Epoch: 9 [2560/60000 (4%)]\tLoss: 0.108362\nTrain Epoch: 9 [3200/60000 (5%)]\tLoss: 0.109142\nTrain Epoch: 9 [3840/60000 (6%)]\tLoss: 0.270022\nTrain Epoch: 9 [4480/60000 (7%)]\tLoss: 0.200647\nTrain Epoch: 9 [5120/60000 (9%)]\tLoss: 0.162118\nTrain Epoch: 9 [5760/60000 (10%)]\tLoss: 0.167245\nTrain Epoch: 9 [6400/60000 (11%)]\tLoss: 0.188903\nTrain Epoch: 9 [7040/60000 (12%)]\tLoss: 0.280550\nTrain Epoch: 9 [7680/60000 (13%)]\tLoss: 0.116265\nTrain Epoch: 9 [8320/60000 (14%)]\tLoss: 0.602693\nTrain Epoch: 9 [8960/60000 (15%)]\tLoss: 0.148682\nTrain Epoch: 9 [9600/60000 (16%)]\tLoss: 0.225477\nTrain Epoch: 9 [10240/60000 (17%)]\tLoss: 0.133642\nTrain Epoch: 9 [10880/60000 (18%)]\tLoss: 0.116083\nTrain Epoch: 9 [11520/60000 (19%)]\tLoss: 0.348113\nTrain Epoch: 9 [12160/60000 (20%)]\tLoss: 0.219562\nTrain Epoch: 9 [12800/60000 (21%)]\tLoss: 0.117716\nTrain Epoch: 9 [13440/60000 (22%)]\tLoss: 0.218508\nTrain Epoch: 9 [14080/60000 (23%)]\tLoss: 0.323755\nTrain Epoch: 9 [14720/60000 (25%)]\tLoss: 0.211174\nTrain Epoch: 9 [15360/60000 (26%)]\tLoss: 0.451853\nTrain Epoch: 9 [16000/60000 (27%)]\tLoss: 0.155174\nTrain Epoch: 9 [16640/60000 (28%)]\tLoss: 0.134905\nTrain Epoch: 9 [17280/60000 (29%)]\tLoss: 0.172428\nTrain Epoch: 9 [17920/60000 (30%)]\tLoss: 0.306172\nTrain Epoch: 9 [18560/60000 (31%)]\tLoss: 0.133085\nTrain Epoch: 9 [19200/60000 (32%)]\tLoss: 0.449040\nTrain Epoch: 9 [19840/60000 (33%)]\tLoss: 0.084722\nTrain Epoch: 9 [20480/60000 (34%)]\tLoss: 0.188086\nTrain Epoch: 9 [21120/60000 (35%)]\tLoss: 0.222472\nTrain Epoch: 9 [21760/60000 (36%)]\tLoss: 0.275132\nTrain Epoch: 9 [22400/60000 (37%)]\tLoss: 0.287421\nTrain Epoch: 9 [23040/60000 (38%)]\tLoss: 0.105733\nTrain Epoch: 9 [23680/60000 (39%)]\tLoss: 0.157949\nTrain Epoch: 9 [24320/60000 (41%)]\tLoss: 0.073462\nTrain Epoch: 9 [24960/60000 (42%)]\tLoss: 0.240201\nTrain Epoch: 9 [25600/60000 (43%)]\tLoss: 0.060848\nTrain Epoch: 9 [26240/60000 (44%)]\tLoss: 0.173801\nTrain Epoch: 9 [26880/60000 (45%)]\tLoss: 0.148143\nTrain Epoch: 9 [27520/60000 (46%)]\tLoss: 0.180779\nTrain Epoch: 9 [28160/60000 (47%)]\tLoss: 0.393192\nTrain Epoch: 9 [28800/60000 (48%)]\tLoss: 0.239243\nTrain Epoch: 9 [29440/60000 (49%)]\tLoss: 0.064345\nTrain Epoch: 9 [30080/60000 (50%)]\tLoss: 0.315658\nTrain Epoch: 9 [30720/60000 (51%)]\tLoss: 0.105739\nTrain Epoch: 9 [31360/60000 (52%)]\tLoss: 0.246439\nTrain Epoch: 9 [32000/60000 (53%)]\tLoss: 0.145221\nTrain Epoch: 9 [32640/60000 (54%)]\tLoss: 0.287615\nTrain Epoch: 9 [33280/60000 (55%)]\tLoss: 0.310717\nTrain Epoch: 9 [33920/60000 (57%)]\tLoss: 0.322760\nTrain Epoch: 9 [34560/60000 (58%)]\tLoss: 0.294462\nTrain Epoch: 9 [35200/60000 (59%)]\tLoss: 0.168697\nTrain Epoch: 9 [35840/60000 (60%)]\tLoss: 0.153495\nTrain Epoch: 9 [36480/60000 (61%)]\tLoss: 0.146843\nTrain Epoch: 9 [37120/60000 (62%)]\tLoss: 0.176622\nTrain Epoch: 9 [37760/60000 (63%)]\tLoss: 0.400825\nTrain Epoch: 9 [38400/60000 (64%)]\tLoss: 0.197533\nTrain Epoch: 9 [39040/60000 (65%)]\tLoss: 0.109741\nTrain Epoch: 9 [39680/60000 (66%)]\tLoss: 0.049689\nTrain Epoch: 9 [40320/60000 (67%)]\tLoss: 0.253087\nTrain Epoch: 9 [40960/60000 (68%)]\tLoss: 0.222971\nTrain Epoch: 9 [41600/60000 (69%)]\tLoss: 0.095467\nTrain Epoch: 9 [42240/60000 (70%)]\tLoss: 0.043052\nTrain Epoch: 9 [42880/60000 (71%)]\tLoss: 0.105347\nTrain Epoch: 9 [43520/60000 (72%)]\tLoss: 0.133342\nTrain Epoch: 9 [44160/60000 (74%)]\tLoss: 0.266375\nTrain Epoch: 9 [44800/60000 (75%)]\tLoss: 0.156081\nTrain Epoch: 9 [45440/60000 (76%)]\tLoss: 0.206747\nTrain Epoch: 9 [46080/60000 (77%)]\tLoss: 0.158561\nTrain Epoch: 9 [46720/60000 (78%)]\tLoss: 0.416148\nTrain Epoch: 9 [47360/60000 (79%)]\tLoss: 0.147991\nTrain Epoch: 9 [48000/60000 (80%)]\tLoss: 0.112567\nTrain Epoch: 9 [48640/60000 (81%)]\tLoss: 0.100846\nTrain Epoch: 9 [49280/60000 (82%)]\tLoss: 0.103345\nTrain Epoch: 9 [49920/60000 (83%)]\tLoss: 0.205922\nTrain Epoch: 9 [50560/60000 (84%)]\tLoss: 0.097610\nTrain Epoch: 9 [51200/60000 (85%)]\tLoss: 0.071967\nTrain Epoch: 9 [51840/60000 (86%)]\tLoss: 0.068125\nTrain Epoch: 9 [52480/60000 (87%)]\tLoss: 0.057313\nTrain Epoch: 9 [53120/60000 (88%)]\tLoss: 0.162428\nTrain Epoch: 9 [53760/60000 (90%)]\tLoss: 0.097614\nTrain Epoch: 9 [54400/60000 (91%)]\tLoss: 0.075174\nTrain Epoch: 9 [55040/60000 (92%)]\tLoss: 0.095530\nTrain Epoch: 9 [55680/60000 (93%)]\tLoss: 0.142529\nTrain Epoch: 9 [56320/60000 (94%)]\tLoss: 0.132163\nTrain Epoch: 9 [56960/60000 (95%)]\tLoss: 0.201932\nTrain Epoch: 9 [57600/60000 (96%)]\tLoss: 0.238939\nTrain Epoch: 9 [58240/60000 (97%)]\tLoss: 0.037396\nTrain Epoch: 9 [58880/60000 (98%)]\tLoss: 0.077772\nTrain Epoch: 9 [59520/60000 (99%)]\tLoss: 0.177759\n\nTest set: Average loss: 0.0559, Accuracy: 9813/10000 (98%)\n\nTrain Epoch: 10 [0/60000 (0%)]\tLoss: 0.112115\nTrain Epoch: 10 [640/60000 (1%)]\tLoss: 0.089035\nTrain Epoch: 10 [1280/60000 (2%)]\tLoss: 0.177925\nTrain Epoch: 10 [1920/60000 (3%)]\tLoss: 0.147350\nTrain Epoch: 10 [2560/60000 (4%)]\tLoss: 0.170561\nTrain Epoch: 10 [3200/60000 (5%)]\tLoss: 0.207891\nTrain Epoch: 10 [3840/60000 (6%)]\tLoss: 0.340160\nTrain Epoch: 10 [4480/60000 (7%)]\tLoss: 0.229032\nTrain Epoch: 10 [5120/60000 (9%)]\tLoss: 0.335419\nTrain Epoch: 10 [5760/60000 (10%)]\tLoss: 0.101219\nTrain Epoch: 10 [6400/60000 (11%)]\tLoss: 0.085085\nTrain Epoch: 10 [7040/60000 (12%)]\tLoss: 0.053658\nTrain Epoch: 10 [7680/60000 (13%)]\tLoss: 0.106224\nTrain Epoch: 10 [8320/60000 (14%)]\tLoss: 0.146947\nTrain Epoch: 10 [8960/60000 (15%)]\tLoss: 0.210157\nTrain Epoch: 10 [9600/60000 (16%)]\tLoss: 0.167598\nTrain Epoch: 10 [10240/60000 (17%)]\tLoss: 0.184822\nTrain Epoch: 10 [10880/60000 (18%)]\tLoss: 0.149518\nTrain Epoch: 10 [11520/60000 (19%)]\tLoss: 0.091374\nTrain Epoch: 10 [12160/60000 (20%)]\tLoss: 0.331635\nTrain Epoch: 10 [12800/60000 (21%)]\tLoss: 0.345818\nTrain Epoch: 10 [13440/60000 (22%)]\tLoss: 0.057789\nTrain Epoch: 10 [14080/60000 (23%)]\tLoss: 0.189208\nTrain Epoch: 10 [14720/60000 (25%)]\tLoss: 0.116747\nTrain Epoch: 10 [15360/60000 (26%)]\tLoss: 0.101344\nTrain Epoch: 10 [16000/60000 (27%)]\tLoss: 0.116675\nTrain Epoch: 10 [16640/60000 (28%)]\tLoss: 0.158562\nTrain Epoch: 10 [17280/60000 (29%)]\tLoss: 0.173697\nTrain Epoch: 10 [17920/60000 (30%)]\tLoss: 0.167972\nTrain Epoch: 10 [18560/60000 (31%)]\tLoss: 0.125186\nTrain Epoch: 10 [19200/60000 (32%)]\tLoss: 0.116458\nTrain Epoch: 10 [19840/60000 (33%)]\tLoss: 0.107688\nTrain Epoch: 10 [20480/60000 (34%)]\tLoss: 0.131942\nTrain Epoch: 10 [21120/60000 (35%)]\tLoss: 0.189690\nTrain Epoch: 10 [21760/60000 (36%)]\tLoss: 0.106075\nTrain Epoch: 10 [22400/60000 (37%)]\tLoss: 0.100791\nTrain Epoch: 10 [23040/60000 (38%)]\tLoss: 0.151750\nTrain Epoch: 10 [23680/60000 (39%)]\tLoss: 0.242852\nTrain Epoch: 10 [24320/60000 (41%)]\tLoss: 0.367772\nTrain Epoch: 10 [24960/60000 (42%)]\tLoss: 0.160668\nTrain Epoch: 10 [25600/60000 (43%)]\tLoss: 0.209858\nTrain Epoch: 10 [26240/60000 (44%)]\tLoss: 0.267443\nTrain Epoch: 10 [26880/60000 (45%)]\tLoss: 0.134159\nTrain Epoch: 10 [27520/60000 (46%)]\tLoss: 0.176844\nTrain Epoch: 10 [28160/60000 (47%)]\tLoss: 0.083609\nTrain Epoch: 10 [28800/60000 (48%)]\tLoss: 0.093472\nTrain Epoch: 10 [29440/60000 (49%)]\tLoss: 0.133502\nTrain Epoch: 10 [30080/60000 (50%)]\tLoss: 0.207314\nTrain Epoch: 10 [30720/60000 (51%)]\tLoss: 0.095819\nTrain Epoch: 10 [31360/60000 (52%)]\tLoss: 0.165338\nTrain Epoch: 10 [32000/60000 (53%)]\tLoss: 0.172792\nTrain Epoch: 10 [32640/60000 (54%)]\tLoss: 0.200346\nTrain Epoch: 10 [33280/60000 (55%)]\tLoss: 0.188566\nTrain Epoch: 10 [33920/60000 (57%)]\tLoss: 0.063107\nTrain Epoch: 10 [34560/60000 (58%)]\tLoss: 0.208076\nTrain Epoch: 10 [35200/60000 (59%)]\tLoss: 0.336500\nTrain Epoch: 10 [35840/60000 (60%)]\tLoss: 0.098523\nTrain Epoch: 10 [36480/60000 (61%)]\tLoss: 0.239501\nTrain Epoch: 10 [37120/60000 (62%)]\tLoss: 0.108441\nTrain Epoch: 10 [37760/60000 (63%)]\tLoss: 0.161891\nTrain Epoch: 10 [38400/60000 (64%)]\tLoss: 0.232178\nTrain Epoch: 10 [39040/60000 (65%)]\tLoss: 0.281599\nTrain Epoch: 10 [39680/60000 (66%)]\tLoss: 0.202701\nTrain Epoch: 10 [40320/60000 (67%)]\tLoss: 0.313276\nTrain Epoch: 10 [40960/60000 (68%)]\tLoss: 0.149932\nTrain Epoch: 10 [41600/60000 (69%)]\tLoss: 0.078690\nTrain Epoch: 10 [42240/60000 (70%)]\tLoss: 0.068174\nTrain Epoch: 10 [42880/60000 (71%)]\tLoss: 0.114682\nTrain Epoch: 10 [43520/60000 (72%)]\tLoss: 0.278032\nTrain Epoch: 10 [44160/60000 (74%)]\tLoss: 0.207701\nTrain Epoch: 10 [44800/60000 (75%)]\tLoss: 0.149129\nTrain Epoch: 10 [45440/60000 (76%)]\tLoss: 0.209997\nTrain Epoch: 10 [46080/60000 (77%)]\tLoss: 0.181944\nTrain Epoch: 10 [46720/60000 (78%)]\tLoss: 0.071149\nTrain Epoch: 10 [47360/60000 (79%)]\tLoss: 0.088598\nTrain Epoch: 10 [48000/60000 (80%)]\tLoss: 0.196593\nTrain Epoch: 10 [48640/60000 (81%)]\tLoss: 0.195960\nTrain Epoch: 10 [49280/60000 (82%)]\tLoss: 0.227564\nTrain Epoch: 10 [49920/60000 (83%)]\tLoss: 0.051203\nTrain Epoch: 10 [50560/60000 (84%)]\tLoss: 0.105916\nTrain Epoch: 10 [51200/60000 (85%)]\tLoss: 0.176384\nTrain Epoch: 10 [51840/60000 (86%)]\tLoss: 0.054657\nTrain Epoch: 10 [52480/60000 (87%)]\tLoss: 0.107465\nTrain Epoch: 10 [53120/60000 (88%)]\tLoss: 0.072626\nTrain Epoch: 10 [53760/60000 (90%)]\tLoss: 0.187904\nTrain Epoch: 10 [54400/60000 (91%)]\tLoss: 0.104509\nTrain Epoch: 10 [55040/60000 (92%)]\tLoss: 0.174006\nTrain Epoch: 10 [55680/60000 (93%)]\tLoss: 0.122760\nTrain Epoch: 10 [56320/60000 (94%)]\tLoss: 0.150131\nTrain Epoch: 10 [56960/60000 (95%)]\tLoss: 0.076365\nTrain Epoch: 10 [57600/60000 (96%)]\tLoss: 0.127536\nTrain Epoch: 10 [58240/60000 (97%)]\tLoss: 0.233154\nTrain Epoch: 10 [58880/60000 (98%)]\tLoss: 0.113188\nTrain Epoch: 10 [59520/60000 (99%)]\tLoss: 0.282389\n\nTest set: Average loss: 0.0531, Accuracy: 9837/10000 (98%)\n\n\n\nThe experiment completed successfully. Finalizing run...\nLogging experiment finalizing status in history service\n\n\nRun is completed.", - "run_properties": { - "SendToClient": "1", - "arguments": "--output-dir ./outputs", - "created_utc": "2018-09-25T11:56:04.832205Z", - "distributed_processes": [], - "end_time_utc": "2018-09-25T12:15:57.841467Z", - "log_files": { - "azureml-logs/55_batchai_execution.txt": "https://onnxamlistorageekgyifen.blob.core.windows.net/azureml/ExperimentRun/pytorch1-mnist_1537876563990/azureml-logs/55_batchai_execution.txt?sv=2017-04-17&sr=b&sig=NNkIC62xdG1h6156XtjtgwTJ1ScXlfxhBiBicNNoExE%3D&st=2018-09-25T12%3A06%3A00Z&se=2018-09-25T20%3A16%3A00Z&sp=r", - "azureml-logs/60_control_log.txt": "https://onnxamlistorageekgyifen.blob.core.windows.net/azureml/ExperimentRun/pytorch1-mnist_1537876563990/azureml-logs/60_control_log.txt?sv=2017-04-17&sr=b&sig=i2mtPt6w5xHkEjpkyfl%2BSD1GPpIdpzIbY6sVUQ62QMo%3D&st=2018-09-25T12%3A06%3A00Z&se=2018-09-25T20%3A16%3A00Z&sp=r", - "azureml-logs/80_driver_log.txt": "https://onnxamlistorageekgyifen.blob.core.windows.net/azureml/ExperimentRun/pytorch1-mnist_1537876563990/azureml-logs/80_driver_log.txt?sv=2017-04-17&sr=b&sig=CvqNHP18huWuXWdi%2BeiPcnztgJfI1iQQ6fV6Li25z1Y%3D&st=2018-09-25T12%3A06%3A00Z&se=2018-09-25T20%3A16%3A00Z&sp=r", - "azureml-logs/azureml.log": "https://onnxamlistorageekgyifen.blob.core.windows.net/azureml/ExperimentRun/pytorch1-mnist_1537876563990/azureml-logs/azureml.log?sv=2017-04-17&sr=b&sig=UTaxvUU4Ua%2FpsXPwQnSIV%2FbKK1zERtclIIjcTfbcSzQ%3D&st=2018-09-25T12%3A06%3A00Z&se=2018-09-25T20%3A16%3A00Z&sp=r" - }, - "properties": { - "ContentSnapshotId": "727976ee-33bf-44c7-af65-ef1a1cbd2980", - "azureml.runsource": "experiment" - }, - "run_duration": "0:19:53", - "run_id": "pytorch1-mnist_1537876563990", - "script_name": "mnist.py", - "status": "Completed", - "tags": {} - }, - "widget_settings": {}, - "workbench_uri": "https://mlworkspace.azure.ai/portal/subscriptions/75f78a03-482f-4fd8-8c71-5ddc08f92726/resourceGroups/onnxdemos/providers/Microsoft.MachineLearningServices/workspaces/onnx-aml-ignite-demo/experiment/pytorch1-mnist/run/pytorch1-mnist_1537876563990" - } - } - }, - "version_major": 2, - "version_minor": 0 - } - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.yml b/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.yml deleted file mode 100644 index c0145ec0..00000000 --- a/how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: onnx-train-pytorch-aml-deploy-mnist -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.ipynb b/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.ipynb deleted file mode 100644 index 292db2a6..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.ipynb +++ /dev/null @@ -1,355 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploying a web service to Azure Kubernetes Service (AKS)\n", - "This notebook shows the steps for deploying a service: registering a model, creating an image, provisioning a cluster (one time action), and deploying a service to it. \n", - "We then test and delete the service, image and model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import azureml.core\n", - "print(azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Get workspace\n", - "Load existing workspace from the config file info." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.workspace import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Download the model\n", - "\n", - "Prior to registering the model, you should have a TensorFlow [Saved Model](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md) in the `resnet50` directory. This cell will download a [pretrained resnet50](http://download.tensorflow.org/models/official/20181001_resnet/savedmodels/resnet_v1_fp32_savedmodel_NCHW_jpg.tar.gz) and unpack it to that directory." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import requests\n", - "import shutil\n", - "import tarfile\n", - "import tempfile\n", - "\n", - "from io import BytesIO\n", - "\n", - "model_url = \"http://download.tensorflow.org/models/official/20181001_resnet/savedmodels/resnet_v1_fp32_savedmodel_NCHW_jpg.tar.gz\"\n", - "\n", - "archive_prefix = \"./resnet_v1_fp32_savedmodel_NCHW_jpg/1538686758/\"\n", - "target_folder = \"resnet50\"\n", - "\n", - "if not os.path.exists(target_folder):\n", - " response = requests.get(model_url)\n", - " archive = tarfile.open(fileobj=BytesIO(response.content))\n", - " with tempfile.TemporaryDirectory() as temp_folder:\n", - " archive.extractall(temp_folder)\n", - " shutil.copytree(os.path.join(temp_folder, archive_prefix), target_folder)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register the model\n", - "Register an existing trained model, add description and tags." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import Model\n", - "\n", - "model = Model.register(model_path=\"resnet50\", # This points to the local directory to upload.\n", - " model_name=\"resnet50\", # This is the name the model is registered as.\n", - " tags={'area': \"Image classification\", 'type': \"classification\"},\n", - " description=\"Image classification trained on Imagenet Dataset\",\n", - " workspace=ws)\n", - "\n", - "print(model.name, model.description, model.version)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Provision the AKS Cluster\n", - "This is a one time setup. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget, AksCompute\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# Choose a name for your GPU cluster\n", - "gpu_cluster_name = \"aks-gpu-cluster\"\n", - "\n", - "# Choose a location for your GPU cluster\n", - "gpu_cluster_location = \"eastus\"\n", - "\n", - "# Verify that cluster does not exist already\n", - "try:\n", - " gpu_cluster = ComputeTarget(workspace=ws, name=gpu_cluster_name)\n", - " print(\"Found existing gpu cluster\")\n", - "except ComputeTargetException:\n", - " print(\"Creating new gpu-cluster\")\n", - " \n", - " # Specify the configuration for the new cluster\n", - " compute_config = AksCompute.provisioning_configuration(cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST,\n", - " agent_count=1,\n", - " vm_size=\"Standard_NC6s_v3\",\n", - " location=gpu_cluster_location)\n", - " # Create the cluster with the specified name and configuration\n", - " gpu_cluster = ComputeTarget.create(ws, gpu_cluster_name, compute_config)\n", - "\n", - " # Wait for the cluster to complete, show the output log\n", - " gpu_cluster.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploy the model as a web service to AKS\n", - "\n", - "First create a scoring script" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import tensorflow.compat.v1 as tf\n", - "import numpy as np\n", - "import json\n", - "import os\n", - "from azureml.contrib.services.aml_request import AMLRequest, rawhttp\n", - "from azureml.contrib.services.aml_response import AMLResponse\n", - "\n", - "def init():\n", - " global session\n", - " global input_name\n", - " global output_name\n", - " \n", - " session = tf.Session()\n", - "\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'resnet50')\n", - " model = tf.saved_model.loader.load(session, ['serve'], model_path)\n", - " if len(model.signature_def['serving_default'].inputs) > 1:\n", - " raise ValueError(\"This score.py only supports one input\")\n", - " input_name = [tensor.name for tensor in model.signature_def['serving_default'].inputs.values()][0]\n", - " output_name = [tensor.name for tensor in model.signature_def['serving_default'].outputs.values()]\n", - " \n", - "\n", - "@rawhttp\n", - "def run(request):\n", - " if request.method == 'POST':\n", - " reqBody = request.get_data(False)\n", - " resp = score(reqBody)\n", - " return AMLResponse(resp, 200)\n", - " if request.method == 'GET':\n", - " respBody = str.encode(\"GET is not supported\")\n", - " return AMLResponse(respBody, 405)\n", - " return AMLResponse(\"bad request\", 500)\n", - "\n", - "def score(data):\n", - " result = session.run(output_name, {input_name: [data]})\n", - " return json.dumps(result[1].tolist())\n", - "\n", - "if __name__ == \"__main__\":\n", - " init()\n", - " with open(\"test_image.jpg\", 'rb') as f:\n", - " content = f.read()\n", - " print(score(content))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now create the deployment configuration objects and deploy the model as a webservice." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Set the web service configuration (using default here)\n", - "from azureml.core.model import InferenceConfig\n", - "from azureml.core.webservice import AksWebservice\n", - "from azureml.core.conda_dependencies import CondaDependencies\n", - "from azureml.core.environment import Environment, DEFAULT_GPU_IMAGE\n", - "\n", - "env = Environment('deploytocloudenv')\n", - "# Please see [Azure ML Containers repository](https://github.com/Azure/AzureML-Containers#featured-tags)\n", - "# for open-sourced GPU base images.\n", - "env.docker.base_image = DEFAULT_GPU_IMAGE\n", - "env.python.conda_dependencies = CondaDependencies.create(python_version=\"3.8\", pin_sdk_version=False,\n", - " conda_packages=['tensorflow-gpu','numpy'],\n", - " pip_packages=['azureml-contrib-services', 'azureml-defaults'])\n", - "\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=env)\n", - "aks_config = AksWebservice.deploy_configuration()\n", - "\n", - "# # Enable token auth and disable (key) auth on the webservice\n", - "# aks_config = AksWebservice.deploy_configuration(token_auth_enabled=True, auth_enabled=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service_name ='gpu-rn50'\n", - "\n", - "aks_service = Model.deploy(workspace=ws,\n", - " name=aks_service_name,\n", - " models=[model],\n", - " inference_config=inference_config,\n", - " deployment_config=aks_config,\n", - " deployment_target=gpu_cluster)\n", - "\n", - "aks_service.wait_for_deployment(show_output = True)\n", - "print(aks_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test the web service\n", - "We test the web sevice by passing the test images content." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "import requests\n", - "\n", - "# if (key) auth is enabled, fetch keys and include in the request\n", - "key1, key2 = aks_service.get_keys()\n", - "\n", - "headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + key1}\n", - "\n", - "# # if token auth is enabled, fetch token and include in the request\n", - "# access_token, fetch_after = aks_service.get_token()\n", - "# headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + access_token}\n", - "\n", - "test_sample = open('snowleopardgaze.jpg', 'rb').read()\n", - "resp = requests.post(aks_service.scoring_uri, test_sample, headers=headers)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Clean up\n", - "Delete the service, image, model and compute target" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service.delete()\n", - "model.delete()\n", - "gpu_cluster.delete()\n" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "vaidyas" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.yml b/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.yml deleted file mode 100644 index 48e39a5a..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: production-deploy-to-aks-gpu -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/snowleopardgaze.jpg b/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/snowleopardgaze.jpg deleted file mode 100644 index 80450160..00000000 Binary files a/how-to-use-azureml/deployment/production-deploy-to-aks-gpu/snowleopardgaze.jpg and /dev/null differ diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.ipynb b/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.ipynb deleted file mode 100644 index 81bf460a..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.ipynb +++ /dev/null @@ -1,356 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploying a web service to Azure Kubernetes Service (AKS)\n", - "This notebook shows the steps for deploying a service: registering a model, provisioning a cluster with ssl (one time action), and deploying a service to it. \n", - "We then test and delete the service, image and model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "from azureml.core.compute import AksCompute, ComputeTarget\n", - "from azureml.core.webservice import Webservice, AksWebservice\n", - "from azureml.core.model import Model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import azureml.core\n", - "print(azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Get workspace\n", - "Load existing workspace from the config file info." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.workspace import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register the model\n", - "Register an existing trained model, add descirption and tags." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Register the model\n", - "from azureml.core.model import Model\n", - "model = Model.register(model_path = \"sklearn_regression_model.pkl\", # this points to a local file\n", - " model_name = \"sklearn_model\", # this is the name the model is registered as\n", - " tags = {'area': \"diabetes\", 'type': \"regression\"},\n", - " description = \"Ridge regression model to predict diabetes\",\n", - " workspace = ws)\n", - "\n", - "print(model.name, model.description, model.version)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Create the Environment\n", - "Create an environment that the model will be deployed with" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Environment\n", - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", - "conda_deps = CondaDependencies.create(conda_packages=['numpy', 'scikit-learn==0.22.1', 'scipy'], pip_packages=['azureml-defaults', 'inference-schema'])\n", - "myenv = Environment(name='myenv')\n", - "myenv.python.conda_dependencies = conda_deps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Use a custom Docker image\n", - "\n", - "You can also specify a custom Docker image to be used as base image if you don't want to use the default base image provided by Azure ML. Please make sure the custom Docker image has Ubuntu >= 16.04, Conda >= 4.5.\\* and Python(3.5.\\* or 3.6.\\*).\n", - "\n", - "Only supported with `python` runtime.\n", - "```python\n", - "# use an image available in public Container Registry without authentication\n", - "myenv.docker.base_image = \"mcr.microsoft.com/azureml/o16n-sample-user-base/ubuntu-miniconda\"\n", - "\n", - "# or, use an image available in a private Container Registry\n", - "myenv.docker.base_image = \"myregistry.azurecr.io/mycustomimage:1.0\"\n", - "myenv.docker.base_image_registry.address = \"myregistry.azurecr.io\"\n", - "myenv.docker.base_image_registry.username = \"username\"\n", - "myenv.docker.base_image_registry.password = \"password\"\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Write the Entry Script\n", - "Write the script that will be used to predict on your model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score_ssl.py\n", - "import os\n", - "import pickle\n", - "import json\n", - "import numpy\n", - "import joblib\n", - "from sklearn.linear_model import Ridge\n", - "from inference_schema.schema_decorators import input_schema, output_schema\n", - "from inference_schema.parameter_types.standard_py_parameter_type import StandardPythonParameterType\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # deserialize the model file back into a sklearn model\n", - " model = joblib.load(model_path)\n", - "\n", - "\n", - "standard_sample_input = {'a': 10, 'b': 9, 'c': 8, 'd': 7, 'e': 6, 'f': 5, 'g': 4, 'h': 3, 'i': 2, 'j': 1 }\n", - "standard_sample_output = {'outcome': 1}\n", - "\n", - "@input_schema('param', StandardPythonParameterType(standard_sample_input))\n", - "@output_schema(StandardPythonParameterType(standard_sample_output))\n", - "def run(param):\n", - " try:\n", - " raw_data = [param['a'], param['b'], param['c'], param['d'], param['e'], param['f'], param['g'], param['h'], param['i'], param['j']]\n", - " data = numpy.array([raw_data])\n", - " result = model.predict(data)\n", - " return { 'outcome' : result[0] }\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Create the InferenceConfig\n", - "Create the inference config that will be used when deploying the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "\n", - "inf_config = InferenceConfig(entry_script='score_ssl.py', environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Provision the AKS Cluster with SSL\n", - "This is a one time setup. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it.\n", - "\n", - "> Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.\n", - "\n", - "See code snippet below. Check the documentation [here](https://docs.microsoft.com/azure/machine-learning/v1/how-to-secure-web-service) for more details" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Use the default configuration (can also provide parameters to customize)\n", - "\n", - "provisioning_config = AksCompute.provisioning_configuration()\n", - "# Leaf domain label generates a name using the formula\n", - "# \"######..cloudapp.azure.net\"\n", - "# where \"######\" is a random series of characters\n", - "provisioning_config.enable_ssl(leaf_domain_label = \"contoso\", overwrite_existing_domain = True)\n", - "\n", - "aks_name = 'my-aks-ssl-1' \n", - "# Create the cluster\n", - "aks_target = ComputeTarget.create(workspace = ws, \n", - " name = aks_name, \n", - " provisioning_configuration = provisioning_config)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_target.wait_for_completion(show_output = True)\n", - "print(aks_target.provisioning_state)\n", - "print(aks_target.provisioning_errors)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploy web service to AKS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "sample-deploy-to-aks" - ] - }, - "outputs": [], - "source": [ - "%%time\n", - "\n", - "aks_config = AksWebservice.deploy_configuration()\n", - "\n", - "aks_service_name ='aks-service-ssl-1'\n", - "\n", - "aks_service = Model.deploy(workspace=ws,\n", - " name=aks_service_name,\n", - " models=[model],\n", - " inference_config=inf_config,\n", - " deployment_config=aks_config,\n", - " deployment_target=aks_target,\n", - " overwrite=True)\n", - "\n", - "aks_service.wait_for_deployment(show_output = True)\n", - "print(aks_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test the web service using run method\n", - "We test the web sevice by passing data.\n", - "Run() method retrieves API keys behind the scenes to make sure that call is authenticated." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "import json\n", - "\n", - "standard_sample_input = json.dumps({'param': {'a': 10, 'b': 9, 'c': 8, 'd': 7, 'e': 6, 'f': 5, 'g': 4, 'h': 3, 'i': 2, 'j': 1 }})\n", - "\n", - "aks_service.run(input_data=standard_sample_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Clean up\n", - "Delete the service, image and model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service.delete()\n", - "model.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "vaidyas" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.yml b/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.yml deleted file mode 100644 index b2743ef4..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: production-deploy-to-aks-ssl -dependencies: -- pip: - - azureml-sdk - - matplotlib - - tqdm - - scipy - - scikit-learn diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.ipynb b/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.ipynb deleted file mode 100644 index 6b231918..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.ipynb +++ /dev/null @@ -1,625 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploying a web service to Azure Kubernetes Service (AKS)\n", - "This notebook shows the steps for deploying a service: registering a model, creating an image, provisioning a cluster (one time action), and deploying a service to it. \n", - "We then test and delete the service, image and model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Workspace\n", - "from azureml.core.compute import AksCompute, ComputeTarget\n", - "from azureml.core.webservice import Webservice, AksWebservice\n", - "from azureml.core.model import Model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import azureml.core\n", - "print(azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Get workspace\n", - "Load existing workspace from the config file info." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.workspace import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Register the model\n", - "Register an existing trained model, add descirption and tags." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Register the model\n", - "from azureml.core.model import Model\n", - "model = Model.register(model_path = \"sklearn_regression_model.pkl\", # this points to a local file\n", - " model_name = \"sklearn_regression_model.pkl\", # this is the name the model is registered as\n", - " tags = {'area': \"diabetes\", 'type': \"regression\"},\n", - " description = \"Ridge regression model to predict diabetes\",\n", - " workspace = ws)\n", - "\n", - "print(model.name, model.description, model.version)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Create the Environment\n", - "Create an environment that the model will be deployed with" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Environment\n", - "from azureml.core.conda_dependencies import CondaDependencies \n", - "\n", - "conda_deps = CondaDependencies.create(conda_packages=['numpy','scikit-learn==0.22.1','scipy'], pip_packages=['azureml-defaults', 'inference-schema'])\n", - "myenv = Environment(name='myenv')\n", - "myenv.python.conda_dependencies = conda_deps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Use a custom Docker image\n", - "\n", - "You can also specify a custom Docker image to be used as base image if you don't want to use the default base image provided by Azure ML. Please make sure the custom Docker image has Ubuntu >= 16.04, Conda >= 4.5.\\* and Python(3.5.\\* or 3.6.\\*).\n", - "\n", - "Only supported with `python` runtime.\n", - "```python\n", - "# use an image available in public Container Registry without authentication\n", - "myenv.docker.base_image = \"mcr.microsoft.com/azureml/o16n-sample-user-base/ubuntu-miniconda\"\n", - "\n", - "# or, use an image available in a private Container Registry\n", - "myenv.docker.base_image = \"myregistry.azurecr.io/mycustomimage:1.0\"\n", - "myenv.docker.base_image_registry.address = \"myregistry.azurecr.io\"\n", - "myenv.docker.base_image_registry.username = \"username\"\n", - "myenv.docker.base_image_registry.password = \"password\"\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Write the Entry Script\n", - "Write the script that will be used to predict on your model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%writefile score.py\n", - "import os\n", - "import pickle\n", - "import json\n", - "import numpy\n", - "import joblib\n", - "from sklearn.linear_model import Ridge\n", - "\n", - "def init():\n", - " global model\n", - " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", - " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", - " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", - " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'sklearn_regression_model.pkl')\n", - " # deserialize the model file back into a sklearn model\n", - " model = joblib.load(model_path)\n", - "\n", - "# note you can pass in multiple rows for scoring\n", - "def run(raw_data):\n", - " try:\n", - " data = json.loads(raw_data)['data']\n", - " data = numpy.array(data)\n", - " result = model.predict(data)\n", - " # you can return any data type as long as it is JSON-serializable\n", - " return result.tolist()\n", - " except Exception as e:\n", - " error = str(e)\n", - " return error" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Create the InferenceConfig\n", - "Create the inference config that will be used when deploying the model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.model import InferenceConfig\n", - "\n", - "inf_config = InferenceConfig(entry_script='score.py', environment=myenv)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Model Profiling\n", - "\n", - "Profile your model to understand how much CPU and memory the service, created as a result of its deployment, will need. Profiling returns information such as CPU usage, memory usage, and response latency. It also provides a CPU and memory recommendation based on the resource usage. You can profile your model (or more precisely the service built based on your model) on any CPU and/or memory combination where 0.1 <= CPU <= 3.5 and 0.1GB <= memory <= 15GB. If you do not provide a CPU and/or memory requirement, we will test it on the default configuration of 3.5 CPU and 15GB memory.\n", - "\n", - "In order to profile your model you will need:\n", - "- a registered model\n", - "- an entry script\n", - "- an inference configuration\n", - "- a single column tabular dataset, where each row contains a string representing sample request data sent to the service.\n", - "\n", - "Please, note that profiling is a long running operation and can take up to 25 minutes depending on the size of the dataset.\n", - "\n", - "At this point we only support profiling of services that expect their request data to be a string, for example: string serialized json, text, string serialized image, etc. The content of each row of the dataset (string) will be put into the body of the HTTP request and sent to the service encapsulating the model for scoring.\n", - "\n", - "Below is an example of how you can construct an input dataset to profile a service which expects its incoming requests to contain serialized json. In this case we created a dataset based one hundred instances of the same request data. In real world scenarios however, we suggest that you use larger datasets with various inputs, especially if your model resource usage/behavior is input dependent." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You may want to register datasets using the register() method to your workspace so they can be shared with others, reused and referred to by name in your script.\n", - "You can try get the dataset first to see if it's already registered." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "from azureml.core import Datastore\n", - "from azureml.core.dataset import Dataset\n", - "from azureml.data import dataset_type_definitions\n", - "\n", - "dataset_name='sample_request_data'\n", - "\n", - "dataset_registered = False\n", - "try:\n", - " sample_request_data = Dataset.get_by_name(workspace = ws, name = dataset_name)\n", - " dataset_registered = True\n", - "except:\n", - " print(\"The dataset {} is not registered in workspace yet.\".format(dataset_name))\n", - "\n", - "if not dataset_registered:\n", - " input_json = {'data': [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n", - " [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]}\n", - " # create a string that can be put in the body of the request\n", - " serialized_input_json = json.dumps(input_json)\n", - " dataset_content = []\n", - " for i in range(100):\n", - " dataset_content.append(serialized_input_json)\n", - " sample_request_data = '\\n'.join(dataset_content)\n", - " file_name = \"{}.txt\".format(dataset_name)\n", - " f = open(file_name, 'w')\n", - " f.write(sample_request_data)\n", - " f.close()\n", - "\n", - " # upload the txt file created above to the Datastore and create a dataset from it\n", - " data_store = Datastore.get_default(ws)\n", - " data_store.upload_files(['./' + file_name], target_path='sample_request_data')\n", - " datastore_path = [(data_store, 'sample_request_data' +'/' + file_name)]\n", - " sample_request_data = Dataset.Tabular.from_delimited_files(\n", - " datastore_path,\n", - " separator='\\n',\n", - " infer_column_types=True,\n", - " header=dataset_type_definitions.PromoteHeadersBehavior.NO_HEADERS)\n", - " sample_request_data = sample_request_data.register(workspace=ws,\n", - " name=dataset_name,\n", - " create_new_version=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now that we have an input dataset we are ready to go ahead with profiling. In this case we are testing the previously introduced sklearn regression model on 1 CPU and 0.5 GB memory. The memory usage and recommendation presented in the result is measured in Gigabytes. The CPU usage and recommendation is measured in CPU cores." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from datetime import datetime\n", - "from azureml.core import Environment\n", - "from azureml.core.conda_dependencies import CondaDependencies\n", - "from azureml.core.model import Model, InferenceConfig\n", - "\n", - "\n", - "environment = Environment('my-sklearn-environment')\n", - "environment.python.conda_dependencies = CondaDependencies.create(conda_packages=[\n", - " 'pip==20.2.4'],\n", - " pip_packages=[\n", - " 'azureml-defaults',\n", - " 'inference-schema[numpy-support]',\n", - " 'joblib',\n", - " 'numpy',\n", - " 'scikit-learn==0.22.1',\n", - " 'scipy'\n", - "])\n", - "inference_config = InferenceConfig(entry_script='score.py', environment=environment)\n", - "# if cpu and memory_in_gb parameters are not provided\n", - "# the model will be profiled on default configuration of\n", - "# 3.5CPU and 15GB memory\n", - "profile = Model.profile(ws,\n", - " 'sklearn-%s' % datetime.now().strftime('%m%d%Y-%H%M%S'),\n", - " [model],\n", - " inference_config,\n", - " input_dataset=sample_request_data,\n", - " cpu=1.0,\n", - " memory_in_gb=0.5)\n", - "\n", - "# profiling is a long running operation and may take up to 25 min\n", - "profile.wait_for_completion(True)\n", - "details = profile.get_details()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Provision the AKS Cluster\n", - "This is a one time setup. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it.\n", - "\n", - "> Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# Choose a name for your AKS cluster\n", - "aks_name = 'my-aks-9' \n", - "\n", - "# Verify that cluster does not exist already\n", - "try:\n", - " aks_target = ComputeTarget(workspace=ws, name=aks_name)\n", - " print('Found existing cluster, use it.')\n", - "except ComputeTargetException:\n", - " # Use the default configuration (can also provide parameters to customize)\n", - " prov_config = AksCompute.provisioning_configuration()\n", - "\n", - " # Create the cluster\n", - " aks_target = ComputeTarget.create(workspace = ws, \n", - " name = aks_name, \n", - " provisioning_configuration = prov_config)\n", - "\n", - "if aks_target.get_status() != \"Succeeded\":\n", - " aks_target.wait_for_completion(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Create AKS Cluster in an existing virtual network (optional)\n", - "See code snippet below. Check the documentation [here](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-network-security-overview) for more details." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# from azureml.core.compute import ComputeTarget, AksCompute\n", - "\n", - "# # Create the compute configuration and set virtual network information\n", - "# config = AksCompute.provisioning_configuration(location=\"eastus2\")\n", - "# config.vnet_resourcegroup_name = \"mygroup\"\n", - "# config.vnet_name = \"mynetwork\"\n", - "# config.subnet_name = \"default\"\n", - "# config.service_cidr = \"10.0.0.0/16\"\n", - "# config.dns_service_ip = \"10.0.0.10\"\n", - "# config.docker_bridge_cidr = \"172.17.0.1/16\"\n", - "\n", - "# # Create the compute target\n", - "# aks_target = ComputeTarget.create(workspace = ws,\n", - "# name = \"myaks\",\n", - "# provisioning_configuration = config)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Enable SSL on the AKS Cluster (optional)\n", - "See code snippet below. Check the documentation [here](https://docs.microsoft.com/en-us/azure/machine-learning/how-to-network-security-overview#secure-the-inferencing-environment-v1) for more details" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# provisioning_config = AksCompute.provisioning_configuration(ssl_cert_pem_file=\"cert.pem\", ssl_key_pem_file=\"key.pem\", ssl_cname=\"www.contoso.com\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_target.wait_for_completion(show_output = True)\n", - "print(aks_target.provisioning_state)\n", - "print(aks_target.provisioning_errors)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Optional step: Attach existing AKS cluster\n", - "\n", - "If you have existing AKS cluster in your Azure subscription, you can attach it to the Workspace." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # Use the default configuration (can also provide parameters to customize)\n", - "# resource_id = '/subscriptions/92c76a2f-0e1c-4216-b65e-abf7a3f34c1e/resourcegroups/raymondsdk0604/providers/Microsoft.ContainerService/managedClusters/my-aks-0605d37425356b7d01'\n", - "\n", - "# create_name='my-existing-aks' \n", - "# # Create the cluster\n", - "# attach_config = AksCompute.attach_configuration(resource_id=resource_id)\n", - "# aks_target = ComputeTarget.attach(workspace=ws, name=create_name, attach_configuration=attach_config)\n", - "# # Wait for the operation to complete\n", - "# aks_target.wait_for_completion(True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Deploy web service to AKS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "sample-deploy-to-aks" - ] - }, - "outputs": [], - "source": [ - "# Set the web service configuration (using default here)\n", - "aks_config = AksWebservice.deploy_configuration()\n", - "\n", - "# # Enable token auth and disable (key) auth on the webservice\n", - "# aks_config = AksWebservice.deploy_configuration(token_auth_enabled=True, auth_enabled=False)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [ - "sample-deploy-to-aks" - ] - }, - "outputs": [], - "source": [ - "%%time\n", - "aks_service_name ='aks-service-1'\n", - "\n", - "aks_service = Model.deploy(workspace=ws,\n", - " name=aks_service_name,\n", - " models=[model],\n", - " inference_config=inf_config,\n", - " deployment_config=aks_config,\n", - " deployment_target=aks_target)\n", - "\n", - "aks_service.wait_for_deployment(show_output = True)\n", - "print(aks_service.state)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test the web service using run method\n", - "We test the web sevice by passing data.\n", - "Run() method retrieves API keys behind the scenes to make sure that call is authenticated." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "import json\n", - "\n", - "test_sample = json.dumps({'data': [\n", - " [1,2,3,4,5,6,7,8,9,10], \n", - " [10,9,8,7,6,5,4,3,2,1]\n", - "]})\n", - "test_sample = bytes(test_sample,encoding = 'utf8')\n", - "\n", - "prediction = aks_service.run(input_data = test_sample)\n", - "print(prediction)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Test the web service using raw HTTP request (optional)\n", - "Alternatively you can construct a raw HTTP request and send it to the service. In this case you need to explicitly pass the HTTP header. This process is shown in the next 2 cells." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # if (key) auth is enabled, retrieve the API keys. AML generates two keys.\n", - "# key1, Key2 = aks_service.get_keys()\n", - "# print(key1)\n", - "\n", - "# # if token auth is enabled, retrieve the token.\n", - "# access_token, refresh_after = aks_service.get_token()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# construct raw HTTP request and send to the service\n", - "# %%time\n", - "\n", - "# import requests\n", - "\n", - "# import json\n", - "\n", - "# test_sample = json.dumps({'data': [\n", - "# [1,2,3,4,5,6,7,8,9,10], \n", - "# [10,9,8,7,6,5,4,3,2,1]\n", - "# ]})\n", - "# test_sample = bytes(test_sample,encoding = 'utf8')\n", - "\n", - "# # If (key) auth is enabled, don't forget to add key to the HTTP header.\n", - "# headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + key1}\n", - "\n", - "# # If token auth is enabled, don't forget to add token to the HTTP header.\n", - "# headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + access_token}\n", - "\n", - "# resp = requests.post(aks_service.scoring_uri, test_sample, headers=headers)\n", - "\n", - "\n", - "# print(\"prediction:\", resp.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Clean up\n", - "Delete the service, image and model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%time\n", - "aks_service.delete()\n", - "model.delete()" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "vaidyas" - } - ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.6" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.yml b/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.yml deleted file mode 100644 index 7ca0fa5a..00000000 --- a/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: production-deploy-to-aks -dependencies: -- pip: - - azureml-sdk - - matplotlib - - tqdm - - scipy - - scikit-learn diff --git a/how-to-use-azureml/deployment/production-deploy-to-aks/sklearn_regression_model.pkl b/how-to-use-azureml/deployment/production-deploy-to-aks/sklearn_regression_model.pkl deleted file mode 100644 index d10309b6..00000000 Binary files a/how-to-use-azureml/deployment/production-deploy-to-aks/sklearn_regression_model.pkl and /dev/null differ diff --git a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml b/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml deleted file mode 100644 index 1502e53f..00000000 --- a/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: explain-model-on-amlcompute -dependencies: -- pip: - - azureml-sdk - - azureml-interpret - - flask - - flask-cors - - gevent>=1.3.6 - - ipython - - matplotlib - - ipywidgets - - raiwidgets~=0.33.0 - - itsdangerous==2.0.1 - - markupsafe<2.1.0 - - scipy>=1.5.3 - - protobuf==3.20.0 - - jinja2==3.0.3 diff --git a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml b/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml deleted file mode 100644 index 02265321..00000000 --- a/how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: save-retrieve-explanations-run-history -dependencies: -- pip: - - azureml-sdk - - azureml-interpret - - flask - - flask-cors - - gevent>=1.3.6 - - ipython - - matplotlib - - ipywidgets - - raiwidgets~=0.33.0 - - packaging>=20.9 - - itsdangerous==2.0.1 - - markupsafe<2.1.0 - - scipy>=1.5.3 - - protobuf==3.20.0 - - jinja2==3.0.3 diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb index d1c9f432..a357377c 100644 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb +++ b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb @@ -370,7 +370,7 @@ "# cause errors. Please take extra care when specifying your dependencies in a production environment.\n", "myenv = CondaDependencies.create(\n", " python_version=python_version,\n", - " conda_packages=['pip==20.2.4', numpy_dep],\n", + " conda_packages=['pip==22.3.1', numpy_dep],\n", " pip_packages=['pyyaml', sklearn_dep, pandas_dep, numba_dep] + azureml_pip_packages)\n", "\n", "with open(\"myenv.yml\",\"w\") as f:\n", @@ -404,7 +404,7 @@ "\n", "\n", "aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, \n", - " memory_gb=2, \n", + " memory_gb=4, \n", " tags={\"data\": \"IBM_Attrition\", \n", " \"method\" : \"local_explanation\"}, \n", " description='Get local explanations for IBM Employee Attrition data')\n", diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml deleted file mode 100644 index a6ae9400..00000000 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: train-explain-model-locally-and-deploy -dependencies: -- pip: - - azureml-sdk - - azureml-interpret - - flask - - flask-cors - - gevent>=1.3.6 - - ipython - - matplotlib - - ipywidgets - - raiwidgets~=0.33.0 - - packaging>=20.9 - - itsdangerous==2.0.1 - - markupsafe<2.1.0 - - scipy>=1.5.3 - - protobuf==3.20.0 - - jinja2==3.0.3 diff --git a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml b/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml deleted file mode 100644 index 50a5f42c..00000000 --- a/how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-on-amlcompute-and-deploy.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: train-explain-model-on-amlcompute-and-deploy -dependencies: -- pip: - - azureml-sdk - - azureml-interpret - - flask - - flask-cors - - gevent>=1.3.6 - - ipython - - matplotlib - - azureml-core - - ipywidgets - - raiwidgets~=0.33.0 - - itsdangerous==2.0.1 - - markupsafe<2.1.0 - - scipy>=1.5.3 - - protobuf==3.20.0 - - jinja2==3.0.3 diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb index 209826ca..0d624c5c 100644 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb +++ b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb @@ -33,7 +33,6 @@ "| Data store | Supported as a source | Supported as a sink |\n", "| --- | --- | --- |\n", "| Azure Blob Storage | Yes | Yes |\n", - "| Azure Data Lake Storage Gen 1 | Yes | Yes |\n", "| Azure Data Lake Storage Gen 2 | Yes | Yes |\n", "| Azure SQL Database | Yes | Yes |\n", "| Azure Database for PostgreSQL | Yes | Yes |\n", @@ -151,53 +150,6 @@ " path_on_datastore=\"testdata\")" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Azure Data Lake Storage Gen1\n", - "\n", - "Please consult the following articles for detailed steps on setting up service principal authentication and assigning correct permissions to Data Lake Storage account:\n", - "\n", - "https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-service-to-service-authenticate-using-active-directory\n", - "https://docs.microsoft.com/en-us/azure/data-factory/connector-azure-data-lake-store#use-service-principal-authentication" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "datastore_name='MyAdlsDatastore'\n", - "subscription_id=os.getenv(\"ADL_SUBSCRIPTION_62\", \"\") # subscription id of ADLS account\n", - "resource_group=os.getenv(\"ADL_RESOURCE_GROUP_62\", \"\") # resource group of ADLS account\n", - "store_name=os.getenv(\"ADL_STORENAME_62\", \"\") # ADLS account name\n", - "tenant_id=os.getenv(\"ADL_TENANT_62\", \"\") # tenant id of service principal\n", - "client_id=os.getenv(\"ADL_CLIENTID_62\", \"\") # client id of service principal\n", - "client_st=os.getenv(\"ADL_CLIENT_SECRET_62\", \"\") # the secret of service principal\n", - "\n", - "try:\n", - " adls_datastore = Datastore.get(ws, datastore_name)\n", - " print(\"Found datastore with name: %s\" % datastore_name)\n", - "except UserErrorException:\n", - " adls_datastore = Datastore.register_azure_data_lake(\n", - " workspace=ws,\n", - " datastore_name=datastore_name,\n", - " subscription_id=subscription_id, # subscription id of ADLS account\n", - " resource_group=resource_group, # resource group of ADLS account\n", - " store_name=store_name, # ADLS account name\n", - " tenant_id=tenant_id, # tenant id of service principal\n", - " client_id=client_id, # client id of service principal\n", - " client_secret=client_st) # the secret of service principal\n", - " print(\"Registered datastore with name: %s\" % datastore_name)\n", - "\n", - "adls_data_ref = DataReference(\n", - " datastore=adls_datastore,\n", - " data_reference_name=\"adls_test_data\",\n", - " path_on_datastore=\"testdata\")" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -440,10 +392,16 @@ "metadata": {}, "outputs": [], "source": [ + "# TODO: 3012801 - Use ADLS Gen2 datastore.\n", + "blob_data_ref2 = DataReference(\n", + " datastore=blob_datastore,\n", + " data_reference_name=\"blob_test_data2\",\n", + " path_on_datastore=\"testdata2\")\n", + "\n", "transfer_adls_to_blob = DataTransferStep(\n", " name=\"transfer_adls_to_blob\",\n", - " source_data_reference=adls_data_ref,\n", - " destination_data_reference=blob_data_ref,\n", + " source_data_reference=blob_data_ref,\n", + " destination_data_reference=blob_data_ref2,\n", " compute_target=data_factory_compute)\n", "\n", "print(\"Data transfer step created\")" diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.yml deleted file mode 100644 index 4955c060..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-data-transfer -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.yml deleted file mode 100644 index 8bf484d1..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: aml-pipelines-getting-started -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - protobuf==3.20.0 diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-modulestep.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-modulestep.yml deleted file mode 100644 index 2b63300b..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-modulestep.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-how-to-use-modulestep -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-pipeline-drafts.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-pipeline-drafts.yml deleted file mode 100644 index 198569b0..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-pipeline-drafts.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-how-to-use-pipeline-drafts -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb index 091c16a9..2cdf4113 100644 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb +++ b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb @@ -292,7 +292,7 @@ "metadata": {}, "outputs": [], "source": [ - "tf_env = Environment.get(ws, name='AzureML-tensorflow-2.6-ubuntu20.04-py38-cuda11-gpu')" + "tf_env = Environment.get(ws, name='AzureML-tensorflow-2.12-cuda11')" ] }, { diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.yml deleted file mode 100644 index 95339947..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: aml-pipelines-parameter-tuning-with-hyperdrive -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - matplotlib - - numpy - - pandas_ml - - azureml-dataset-runtime[pandas,fuse] diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-publish-and-run-using-rest-endpoint.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-publish-and-run-using-rest-endpoint.yml deleted file mode 100644 index ec9828ff..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-publish-and-run-using-rest-endpoint.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: aml-pipelines-publish-and-run-using-rest-endpoint -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - requests diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-schedule-for-a-published-pipeline.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-schedule-for-a-published-pipeline.yml deleted file mode 100644 index f35bb648..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-schedule-for-a-published-pipeline.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-setup-schedule-for-a-published-pipeline -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-versioned-pipeline-endpoints.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-versioned-pipeline-endpoints.yml deleted file mode 100644 index aae504eb..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-setup-versioned-pipeline-endpoints.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: aml-pipelines-setup-versioned-pipeline-endpoints -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - requests diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-datapath-and-pipelineparameter.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-datapath-and-pipelineparameter.yml deleted file mode 100644 index 0463f025..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-datapath-and-pipelineparameter.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-showcasing-datapath-and-pipelineparameter -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-dataset-and-pipelineparameter.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-dataset-and-pipelineparameter.yml deleted file mode 100644 index 0c5c948c..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-showcasing-dataset-and-pipelineparameter.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-showcasing-dataset-and-pipelineparameter -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-automated-machine-learning-step.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-automated-machine-learning-step.yml deleted file mode 100644 index fbfd7737..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-automated-machine-learning-step.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: aml-pipelines-with-automated-machine-learning-step -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep-r.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep-r.yml deleted file mode 100644 index 5ee18280..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep-r.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-with-commandstep-r -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep.yml deleted file mode 100644 index b03d3856..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-with-commandstep -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.yml deleted file mode 100644 index 0f034033..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: aml-pipelines-with-data-dependency-steps -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-notebook-runner-step.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-notebook-runner-step.yml deleted file mode 100644 index 3585659d..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-notebook-runner-step.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: aml-pipelines-with-notebook-runner-step -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - azureml-contrib-notebook diff --git a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/commandstep_train/conda_dependencies.yml b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/commandstep_train/conda_dependencies.yml index 66ca1b85..4f012320 100644 --- a/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/commandstep_train/conda_dependencies.yml +++ b/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/commandstep_train/conda_dependencies.yml @@ -1,7 +1,7 @@ channels: - conda-forge dependencies: - - python=3.7 + - python=3.8 - pip: - azureml-defaults - tensorflow-gpu==2.3.0 diff --git a/how-to-use-azureml/machine-learning-pipelines/nyc-taxi-data-regression-model-building/nyc-taxi-data-regression-model-building.yml b/how-to-use-azureml/machine-learning-pipelines/nyc-taxi-data-regression-model-building/nyc-taxi-data-regression-model-building.yml deleted file mode 100644 index bf66b5b1..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/nyc-taxi-data-regression-model-building/nyc-taxi-data-regression-model-building.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: nyc-taxi-data-regression-model-building -dependencies: -- pip: - - azureml-sdk - - certifi - - azureml-widgets - - azureml-opendatasets - - azureml-train-automl - - matplotlib - - pandas - - pyarrow diff --git a/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-image-inference-mnist.yml b/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-image-inference-mnist.yml deleted file mode 100644 index 5ddece97..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-image-inference-mnist.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: file-dataset-image-inference-mnist -dependencies: -- pip: - - azureml-sdk - - azureml-pipeline-steps - - azureml-widgets - - pandas diff --git a/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-partition-per-folder.yml b/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-partition-per-folder.yml deleted file mode 100644 index 27e21b32..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/parallel-run/file-dataset-partition-per-folder.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: file-dataset-partition-per-folder -dependencies: -- pip: - - azureml-sdk - - azureml-pipeline-steps - - azureml-widgets - - pandas diff --git a/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-inference-iris.yml b/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-inference-iris.yml deleted file mode 100644 index 9bdf3735..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-inference-iris.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: tabular-dataset-inference-iris -dependencies: -- pip: - - azureml-sdk - - azureml-pipeline-steps - - azureml-widgets - - pandas diff --git a/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-partition-per-column.yml b/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-partition-per-column.yml deleted file mode 100644 index 539bf030..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/parallel-run/tabular-dataset-partition-per-column.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: tabular-dataset-partition-per-column -dependencies: -- pip: - - azureml-sdk - - azureml-pipeline-steps - - azureml-widgets - - pandas diff --git a/how-to-use-azureml/machine-learning-pipelines/pipeline-style-transfer/pipeline-style-transfer-parallel-run.yml b/how-to-use-azureml/machine-learning-pipelines/pipeline-style-transfer/pipeline-style-transfer-parallel-run.yml deleted file mode 100644 index a7671a43..00000000 --- a/how-to-use-azureml/machine-learning-pipelines/pipeline-style-transfer/pipeline-style-transfer-parallel-run.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: pipeline-style-transfer-parallel-run -dependencies: -- pip: - - azureml-sdk - - azureml-pipeline-steps - - azureml-widgets - - requests diff --git a/how-to-use-azureml/ml-frameworks/fastai/fastai-with-custom-docker/fastai-with-custom-docker.yml b/how-to-use-azureml/ml-frameworks/fastai/fastai-with-custom-docker/fastai-with-custom-docker.yml deleted file mode 100644 index 3e5f80ae..00000000 --- a/how-to-use-azureml/ml-frameworks/fastai/fastai-with-custom-docker/fastai-with-custom-docker.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: fastai-with-custom-docker -dependencies: -- pip: - - azureml-sdk - - fastai==1.0.61 diff --git a/how-to-use-azureml/ml-frameworks/keras/train-hyperparameter-tune-deploy-with-keras/train-hyperparameter-tune-deploy-with-keras.yml b/how-to-use-azureml/ml-frameworks/keras/train-hyperparameter-tune-deploy-with-keras/train-hyperparameter-tune-deploy-with-keras.yml deleted file mode 100644 index f65b1b29..00000000 --- a/how-to-use-azureml/ml-frameworks/keras/train-hyperparameter-tune-deploy-with-keras/train-hyperparameter-tune-deploy-with-keras.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: train-hyperparameter-tune-deploy-with-keras -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - matplotlib diff --git a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-distributeddataparallel/distributed-pytorch-with-distributeddataparallel.yml b/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-distributeddataparallel/distributed-pytorch-with-distributeddataparallel.yml deleted file mode 100644 index 8fa7e81d..00000000 --- a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-distributeddataparallel/distributed-pytorch-with-distributeddataparallel.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: distributed-pytorch-with-distributeddataparallel -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.ipynb b/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.ipynb index d3e1b8c2..bfa38012 100644 --- a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.ipynb +++ b/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.ipynb @@ -1,378 +1,378 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Distributed PyTorch with Horovod\n", - "In this tutorial, you will train a PyTorch model on the [MNIST](http://yann.lecun.com/exdb/mnist/) dataset using distributed training via [Horovod](https://github.com/uber/horovod) across a GPU cluster." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n", - "* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [Configuration](../../../../configuration.ipynb) notebook to install the Azure Machine Learning Python SDK and create an Azure ML `Workspace`\n", - "* Review the [tutorial](../train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb) on single-node PyTorch training using Azure Machine Learning" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Check core SDK version number\n", - "import azureml.core\n", - "\n", - "print(\"SDK version:\", azureml.core.VERSION)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Diagnostics\n", - "Opt-in diagnostics for better experience, quality, and security of future releases." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Copyright (c) Microsoft Corporation. All rights reserved.\n", + "\n", + "Licensed under the MIT License." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Distributed PyTorch with Horovod\n", + "In this tutorial, you will train a PyTorch model on the [MNIST](http://yann.lecun.com/exdb/mnist/) dataset using distributed training via [Horovod](https://github.com/uber/horovod) across a GPU cluster." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Prerequisites\n", + "* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [Configuration](../../../../configuration.ipynb) notebook to install the Azure Machine Learning Python SDK and create an Azure ML `Workspace`\n", + "* Review the [tutorial](../train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb) on single-node PyTorch training using Azure Machine Learning" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Check core SDK version number\n", + "import azureml.core\n", + "\n", + "print(\"SDK version:\", azureml.core.VERSION)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Diagnostics\n", + "Opt-in diagnostics for better experience, quality, and security of future releases." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "Diagnostics" + ] + }, + "outputs": [], + "source": [ + "from azureml.telemetry import set_diagnostics_collection\n", + "\n", + "set_diagnostics_collection(send_diagnostics=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initialize workspace\n", + "\n", + "Initialize a [Workspace](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#workspace) object from the existing workspace you created in the Prerequisites step. `Workspace.from_config()` creates a workspace object from the details stored in `config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.core.workspace import Workspace\n", + "\n", + "ws = Workspace.from_config()\n", + "print('Workspace name: ' + ws.name, \n", + " 'Azure region: ' + ws.location, \n", + " 'Subscription id: ' + ws.subscription_id, \n", + " 'Resource group: ' + ws.resource_group, sep='\\n')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create or attach existing AmlCompute\n", + "You will need to create a [compute target](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#compute-target) for training your model. In this tutorial, we use Azure ML managed compute ([AmlCompute](https://docs.microsoft.com/azure/machine-learning/service/how-to-set-up-training-targets#amlcompute)) for our remote training compute resource. Specifically, the below code creates an `Standard_NC6s_v3` GPU cluster that autoscales from `0` to `4` nodes.\n", + "\n", + "> Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.\n", + "\n", + "**Creation of AmlCompute takes approximately 5 minutes.** If the AmlCompute with that name is already in your workspace, this code will skip the creation process.\n", + "\n", + "As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read [this article](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-quotas) on the default limits and how to request more quota." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.core.compute import ComputeTarget, AmlCompute\n", + "from azureml.core.compute_target import ComputeTargetException\n", + "\n", + "# choose a name for your cluster\n", + "cluster_name = \"gpu-cluster\"\n", + "\n", + "try:\n", + " compute_target = ComputeTarget(workspace=ws, name=cluster_name)\n", + " print('Found existing compute target.')\n", + "except ComputeTargetException:\n", + " print('Creating a new compute target...')\n", + " compute_config = AmlCompute.provisioning_configuration(vm_size='Standard_NC6s_v3',\n", + " max_nodes=4)\n", + "\n", + " # create the cluster\n", + " compute_target = ComputeTarget.create(ws, cluster_name, compute_config)\n", + "\n", + " compute_target.wait_for_completion(show_output=True)\n", + "\n", + "# use get_status() to get a detailed status for the current AmlCompute. \n", + "print(compute_target.get_status().serialize())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The above code creates GPU compute. If you instead want to create CPU compute, provide a different VM size to the `vm_size` parameter, such as `STANDARD_D2_V2`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Train model on the remote compute\n", + "Now that we have the AmlCompute ready to go, let's run our distributed training job." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a project directory\n", + "Create a directory that will contain all the necessary code from your local machine that you will need access to on the remote resource. This includes the training script and any additional files your training script depends on." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "project_folder = './pytorch-distr-hvd'\n", + "os.makedirs(project_folder, exist_ok=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Prepare training script\n", + "Now you will need to create your training script. In this tutorial, the script for distributed training of MNIST is already provided for you at `pytorch_horovod_mnist.py`. In practice, you should be able to take any custom PyTorch training script as is and run it with Azure ML without having to modify your code.\n", + "\n", + "However, if you would like to use Azure ML's [metric logging](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#logging) capabilities, you will have to add a small amount of Azure ML logic inside your training script. In this example, at each logging interval, we will log the loss for that minibatch to our Azure ML run.\n", + "\n", + "To do so, in `pytorch_horovod_mnist.py`, we will first access the Azure ML `Run` object within the script:\n", + "```Python\n", + "from azureml.core.run import Run\n", + "run = Run.get_context()\n", + "```\n", + "Later within the script, we log the loss metric to our run:\n", + "```Python\n", + "run.log('loss', loss.item())\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once your script is ready, copy the training script `pytorch_horovod_mnist.py` into the project directory." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import shutil\n", + "\n", + "shutil.copy('pytorch_horovod_mnist.py', project_folder)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create an experiment\n", + "Create an [Experiment](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#experiment) to track all the runs in your workspace for this distributed PyTorch tutorial. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.core import Experiment\n", + "\n", + "experiment_name = 'pytorch-distr-hvd'\n", + "experiment = Experiment(ws, name=experiment_name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create an environment\n", + "\n", + "In this tutorial, we will use one of Azure ML's curated PyTorch environments for training. [Curated environments](https://docs.microsoft.com/azure/machine-learning/how-to-use-environments#use-a-curated-environment) are available in your workspace by default. Specifically, we will use the PyTorch 1.6 GPU curated environment. The curated environment includes the `torch`, `torchvision` and `horovod` packages required by the training script." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.core import Environment\n", + "\n", + "pytorch_env = Environment.get(ws, name='AzureML-acpt-pytorch-1.13-cuda11.7')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Configure the training job\n", + "\n", + "Create a ScriptRunConfig object to specify the configuration details of your training job, including your training script, environment to use, and the compute target to run on.\n", + "\n", + "In order to execute a distributed run using MPI/Horovod, you must create an `MpiConfiguration` object and pass it to the `distributed_job_config` parameter of the ScriptRunConfig constructor. The below code will configure a 2-node distributed job running one process per node. If you would also like to run multiple processes per node (i.e. if your cluster SKU has multiple GPUs), additionally specify the `process_count_per_node` parameter in `MpiConfiguration` (the default is `1`)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.core import ScriptRunConfig\n", + "from azureml.core.runconfig import MpiConfiguration\n", + "\n", + "src = ScriptRunConfig(source_directory=project_folder,\n", + " script='pytorch_horovod_mnist.py',\n", + " compute_target=compute_target,\n", + " environment=pytorch_env,\n", + " distributed_job_config=MpiConfiguration(node_count=2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Submit job\n", + "Run your experiment by submitting your ScriptRunConfig object. Note that this call is asynchronous." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "run = experiment.submit(src)\n", + "print(run)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Monitor your run\n", + "You can monitor the progress of the run with a Jupyter widget. Like the run submission, the widget is asynchronous and provides live updates every 10-15 seconds until the job completes. You can see that the widget automatically plots and visualizes the loss metric that we logged to the Azure ML run." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from azureml.widgets import RunDetails\n", + "\n", + "RunDetails(run).show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively, you can block until the script has completed training before running more code." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "run.wait_for_completion(show_output=True) # this provides a verbose log" + ] + } + ], + "metadata": { + "authors": [ + { + "name": "ninhu" + } + ], + "category": "training", + "compute": [ + "AML Compute" + ], + "datasets": [ + "MNIST" + ], + "deployment": [ + "None" + ], + "exclude_from_index": false, + "framework": [ + "PyTorch" + ], + "friendly_name": "Distributed PyTorch", + "index_order": 1, + "kernelspec": { + "display_name": "Python 3.8 - AzureML", + "language": "python", + "name": "python38-azureml" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.18" + }, "tags": [ - "Diagnostics" - ] - }, - "outputs": [], - "source": [ - "from azureml.telemetry import set_diagnostics_collection\n", - "\n", - "set_diagnostics_collection(send_diagnostics=True)" - ] + "None" + ], + "task": "Train a model using the distributed training via Horovod" }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Initialize workspace\n", - "\n", - "Initialize a [Workspace](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#workspace) object from the existing workspace you created in the Prerequisites step. `Workspace.from_config()` creates a workspace object from the details stored in `config.json`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.workspace import Workspace\n", - "\n", - "ws = Workspace.from_config()\n", - "print('Workspace name: ' + ws.name, \n", - " 'Azure region: ' + ws.location, \n", - " 'Subscription id: ' + ws.subscription_id, \n", - " 'Resource group: ' + ws.resource_group, sep='\\n')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create or attach existing AmlCompute\n", - "You will need to create a [compute target](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#compute-target) for training your model. In this tutorial, we use Azure ML managed compute ([AmlCompute](https://docs.microsoft.com/azure/machine-learning/service/how-to-set-up-training-targets#amlcompute)) for our remote training compute resource. Specifically, the below code creates an `Standard_NC6s_v3` GPU cluster that autoscales from `0` to `4` nodes.\n", - "\n", - "> Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.\n", - "\n", - "**Creation of AmlCompute takes approximately 5 minutes.** If the AmlCompute with that name is already in your workspace, this code will skip the creation process.\n", - "\n", - "As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read [this article](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-quotas) on the default limits and how to request more quota." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core.compute import ComputeTarget, AmlCompute\n", - "from azureml.core.compute_target import ComputeTargetException\n", - "\n", - "# choose a name for your cluster\n", - "cluster_name = \"gpu-cluster\"\n", - "\n", - "try:\n", - " compute_target = ComputeTarget(workspace=ws, name=cluster_name)\n", - " print('Found existing compute target.')\n", - "except ComputeTargetException:\n", - " print('Creating a new compute target...')\n", - " compute_config = AmlCompute.provisioning_configuration(vm_size='Standard_NC6s_v3',\n", - " max_nodes=4)\n", - "\n", - " # create the cluster\n", - " compute_target = ComputeTarget.create(ws, cluster_name, compute_config)\n", - "\n", - " compute_target.wait_for_completion(show_output=True)\n", - "\n", - "# use get_status() to get a detailed status for the current AmlCompute. \n", - "print(compute_target.get_status().serialize())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The above code creates GPU compute. If you instead want to create CPU compute, provide a different VM size to the `vm_size` parameter, such as `STANDARD_D2_V2`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Train model on the remote compute\n", - "Now that we have the AmlCompute ready to go, let's run our distributed training job." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create a project directory\n", - "Create a directory that will contain all the necessary code from your local machine that you will need access to on the remote resource. This includes the training script and any additional files your training script depends on." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "project_folder = './pytorch-distr-hvd'\n", - "os.makedirs(project_folder, exist_ok=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prepare training script\n", - "Now you will need to create your training script. In this tutorial, the script for distributed training of MNIST is already provided for you at `pytorch_horovod_mnist.py`. In practice, you should be able to take any custom PyTorch training script as is and run it with Azure ML without having to modify your code.\n", - "\n", - "However, if you would like to use Azure ML's [metric logging](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#logging) capabilities, you will have to add a small amount of Azure ML logic inside your training script. In this example, at each logging interval, we will log the loss for that minibatch to our Azure ML run.\n", - "\n", - "To do so, in `pytorch_horovod_mnist.py`, we will first access the Azure ML `Run` object within the script:\n", - "```Python\n", - "from azureml.core.run import Run\n", - "run = Run.get_context()\n", - "```\n", - "Later within the script, we log the loss metric to our run:\n", - "```Python\n", - "run.log('loss', loss.item())\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Once your script is ready, copy the training script `pytorch_horovod_mnist.py` into the project directory." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import shutil\n", - "\n", - "shutil.copy('pytorch_horovod_mnist.py', project_folder)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create an experiment\n", - "Create an [Experiment](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#experiment) to track all the runs in your workspace for this distributed PyTorch tutorial. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Experiment\n", - "\n", - "experiment_name = 'pytorch-distr-hvd'\n", - "experiment = Experiment(ws, name=experiment_name)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Create an environment\n", - "\n", - "In this tutorial, we will use one of Azure ML's curated PyTorch environments for training. [Curated environments](https://docs.microsoft.com/azure/machine-learning/how-to-use-environments#use-a-curated-environment) are available in your workspace by default. Specifically, we will use the PyTorch 1.6 GPU curated environment. The curated environment includes the `torch`, `torchvision` and `horovod` packages required by the training script." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import Environment\n", - "\n", - "pytorch_env = Environment.get(ws, name='AzureML-acpt-pytorch-1.13-cuda11.7')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Configure the training job\n", - "\n", - "Create a ScriptRunConfig object to specify the configuration details of your training job, including your training script, environment to use, and the compute target to run on.\n", - "\n", - "In order to execute a distributed run using MPI/Horovod, you must create an `MpiConfiguration` object and pass it to the `distributed_job_config` parameter of the ScriptRunConfig constructor. The below code will configure a 2-node distributed job running one process per node. If you would also like to run multiple processes per node (i.e. if your cluster SKU has multiple GPUs), additionally specify the `process_count_per_node` parameter in `MpiConfiguration` (the default is `1`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.core import ScriptRunConfig\n", - "from azureml.core.runconfig import MpiConfiguration\n", - "\n", - "src = ScriptRunConfig(source_directory=project_folder,\n", - " script='pytorch_horovod_mnist.py',\n", - " compute_target=compute_target,\n", - " environment=pytorch_env,\n", - " distributed_job_config=MpiConfiguration(node_count=2))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Submit job\n", - "Run your experiment by submitting your ScriptRunConfig object. Note that this call is asynchronous." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "run = experiment.submit(src)\n", - "print(run)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Monitor your run\n", - "You can monitor the progress of the run with a Jupyter widget. Like the run submission, the widget is asynchronous and provides live updates every 10-15 seconds until the job completes. You can see that the widget automatically plots and visualizes the loss metric that we logged to the Azure ML run." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from azureml.widgets import RunDetails\n", - "\n", - "RunDetails(run).show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Alternatively, you can block until the script has completed training before running more code." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "run.wait_for_completion(show_output=True) # this provides a verbose log" - ] - } - ], - "metadata": { - "authors": [ - { - "name": "ninhu" - } - ], - "category": "training", - "compute": [ - "AML Compute" - ], - "datasets": [ - "MNIST" - ], - "deployment": [ - "None" - ], - "exclude_from_index": false, - "framework": [ - "PyTorch" - ], - "friendly_name": "Distributed PyTorch", - "index_order": 1, - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.18" - }, - "tags": [ - "None" - ], - "task": "Train a model using the distributed training via Horovod" - }, - "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.yml b/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.yml deleted file mode 100644 index 58bb77d8..00000000 --- a/how-to-use-azureml/ml-frameworks/pytorch/distributed-pytorch-with-horovod/distributed-pytorch-with-horovod.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: distributed-pytorch-with-horovod -dependencies: -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb b/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb index ee54b088..e3ca1037 100644 --- a/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb +++ b/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.ipynb @@ -273,7 +273,7 @@ "source": [ "from azureml.core import Environment\n", "\n", - "pytorch_env = Environment.get(ws, name='azureml-acpt-pytorch-1.11-cuda11.3')" + "pytorch_env = Environment.get(ws, name='azureml-acpt-pytorch-1.13-cuda11.7')" ] }, { diff --git a/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.yml b/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.yml deleted file mode 100644 index 99612082..00000000 --- a/how-to-use-azureml/ml-frameworks/pytorch/train-hyperparameter-tune-deploy-with-pytorch/train-hyperparameter-tune-deploy-with-pytorch.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: train-hyperparameter-tune-deploy-with-pytorch -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - pillow==5.4.1 - - matplotlib - - numpy==1.19.3 - - pytorch==1.8.1 - - torchvision==0.9.1 diff --git a/how-to-use-azureml/ml-frameworks/scikit-learn/train-hyperparameter-tune-deploy-with-sklearn/train-hyperparameter-tune-deploy-with-sklearn.yml b/how-to-use-azureml/ml-frameworks/scikit-learn/train-hyperparameter-tune-deploy-with-sklearn/train-hyperparameter-tune-deploy-with-sklearn.yml deleted file mode 100644 index 2691a849..00000000 --- a/how-to-use-azureml/ml-frameworks/scikit-learn/train-hyperparameter-tune-deploy-with-sklearn/train-hyperparameter-tune-deploy-with-sklearn.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: train-hyperparameter-tune-deploy-with-sklearn -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - numpy diff --git a/how-to-use-azureml/ml-frameworks/tensorflow/distributed-tensorflow-with-horovod/distributed-tensorflow-with-horovod.yml b/how-to-use-azureml/ml-frameworks/tensorflow/distributed-tensorflow-with-horovod/distributed-tensorflow-with-horovod.yml deleted file mode 100644 index 507e277e..00000000 --- a/how-to-use-azureml/ml-frameworks/tensorflow/distributed-tensorflow-with-horovod/distributed-tensorflow-with-horovod.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: distributed-tensorflow-with-horovod -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/ml-frameworks/tensorflow/train-hyperparameter-tune-deploy-with-tensorflow/train-hyperparameter-tune-deploy-with-tensorflow.yml b/how-to-use-azureml/ml-frameworks/tensorflow/train-hyperparameter-tune-deploy-with-tensorflow/train-hyperparameter-tune-deploy-with-tensorflow.yml deleted file mode 100644 index 43575efe..00000000 --- a/how-to-use-azureml/ml-frameworks/tensorflow/train-hyperparameter-tune-deploy-with-tensorflow/train-hyperparameter-tune-deploy-with-tensorflow.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: train-hyperparameter-tune-deploy-with-tensorflow -dependencies: -- numpy -- matplotlib -- pip: - - azureml-sdk - - azureml-widgets - - pandas - - matplotlib - - fuse diff --git a/how-to-use-azureml/reinforcement-learning/atari-on-distributed-compute/pong_rllib.yml b/how-to-use-azureml/reinforcement-learning/atari-on-distributed-compute/pong_rllib.yml deleted file mode 100644 index a79b3da0..00000000 --- a/how-to-use-azureml/reinforcement-learning/atari-on-distributed-compute/pong_rllib.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: pong_rllib -dependencies: -- pip: - - azureml-sdk - - azureml-contrib-reinforcementlearning - - azureml-widgets - - matplotlib - - azure-mgmt-network - - azure-cli diff --git a/how-to-use-azureml/reinforcement-learning/cartpole-on-compute-instance/cartpole_ci.yml b/how-to-use-azureml/reinforcement-learning/cartpole-on-compute-instance/cartpole_ci.yml deleted file mode 100644 index c5a2ed39..00000000 --- a/how-to-use-azureml/reinforcement-learning/cartpole-on-compute-instance/cartpole_ci.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: cartpole_ci -dependencies: -- pip: - - azureml-sdk - - azureml-contrib-reinforcementlearning - - azureml-widgets diff --git a/how-to-use-azureml/reinforcement-learning/cartpole-on-single-compute/cartpole_sc.yml b/how-to-use-azureml/reinforcement-learning/cartpole-on-single-compute/cartpole_sc.yml deleted file mode 100644 index 48d5edfa..00000000 --- a/how-to-use-azureml/reinforcement-learning/cartpole-on-single-compute/cartpole_sc.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: cartpole_sc -dependencies: -- pip: - - azureml-sdk - - azureml-contrib-reinforcementlearning - - azureml-widgets diff --git a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml b/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml deleted file mode 100644 index aba3d417..00000000 --- a/how-to-use-azureml/responsible-ai/visualize-upload-loan-decision/rai-loan-decision.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: rai-loan-decision -dependencies: -- pip: - - azureml-sdk - - azureml-interpret - - azureml-contrib-fairness - - fairlearn>=0.6.2,<=0.7.0 - - matplotlib - - azureml-dataset-runtime - - ipywidgets - - raiwidgets~=0.33.0 - - liac-arff - - packaging>=20.9 - - itsdangerous==2.0.1 - - markupsafe<2.1.0 - - protobuf==3.20.0 diff --git a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb b/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb index ece42025..e47daaa4 100644 --- a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb +++ b/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.ipynb @@ -101,7 +101,7 @@ "\n", "# Check core SDK version number\n", "\n", - "print(\"This notebook was created using SDK version 1.55.0, you are currently running version\", azureml.core.VERSION)" + "print(\"This notebook was created using SDK version 1.56.0, you are currently running version\", azureml.core.VERSION)" ] }, { diff --git a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.yml b/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.yml deleted file mode 100644 index 42144437..00000000 --- a/how-to-use-azureml/track-and-monitor-experiments/logging-api/logging-api.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: logging-api -dependencies: -- numpy -- matplotlib -- tqdm -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/track-and-monitor-experiments/manage-runs/manage-runs.yml b/how-to-use-azureml/track-and-monitor-experiments/manage-runs/manage-runs.yml deleted file mode 100644 index 34a95ec8..00000000 --- a/how-to-use-azureml/track-and-monitor-experiments/manage-runs/manage-runs.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: manage-runs -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/track-and-monitor-experiments/tensorboard/tensorboard/tensorboard.yml b/how-to-use-azureml/track-and-monitor-experiments/tensorboard/tensorboard/tensorboard.yml deleted file mode 100644 index 003dd69e..00000000 --- a/how-to-use-azureml/track-and-monitor-experiments/tensorboard/tensorboard/tensorboard.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: tensorboard -dependencies: -- pip: - - azureml-sdk - - azureml-tensorboard - - tensorboard - - setuptools>=41.0.0 diff --git a/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-local/train-local.yml b/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-local/train-local.yml deleted file mode 100644 index 5095b89f..00000000 --- a/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-local/train-local.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: train-local -dependencies: -- scikit-learn -- matplotlib -- pip: - - azureml-sdk - - azureml-mlflow diff --git a/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-remote/train-remote.yml b/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-remote/train-remote.yml deleted file mode 100644 index e96f6ab6..00000000 --- a/how-to-use-azureml/track-and-monitor-experiments/using-mlflow/train-remote/train-remote.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: train-remote -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/training/train-on-amlcompute/train-on-amlcompute.yml b/how-to-use-azureml/training/train-on-amlcompute/train-on-amlcompute.yml deleted file mode 100644 index 57cc15b6..00000000 --- a/how-to-use-azureml/training/train-on-amlcompute/train-on-amlcompute.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: train-on-amlcompute -dependencies: -- scikit-learn -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/training/train-on-local/train-on-local.yml b/how-to-use-azureml/training/train-on-local/train-on-local.yml deleted file mode 100644 index 76f64467..00000000 --- a/how-to-use-azureml/training/train-on-local/train-on-local.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: train-on-local -dependencies: -- matplotlib -- scikit-learn -- pip: - - azureml-sdk - - azureml-widgets diff --git a/how-to-use-azureml/training/using-environments/using-environments.yml b/how-to-use-azureml/training/using-environments/using-environments.yml deleted file mode 100644 index 88422a40..00000000 --- a/how-to-use-azureml/training/using-environments/using-environments.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: using-environments -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/work-with-data/datadrift-tutorial/datadrift-tutorial.yml b/how-to-use-azureml/work-with-data/datadrift-tutorial/datadrift-tutorial.yml deleted file mode 100644 index 6633d9e5..00000000 --- a/how-to-use-azureml/work-with-data/datadrift-tutorial/datadrift-tutorial.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: datadrift-tutorial -dependencies: -- pip: - - azureml-sdk - - azureml-datadrift diff --git a/how-to-use-azureml/work-with-data/datasets-tutorial/pipeline-with-datasets/pipeline-for-image-classification.yml b/how-to-use-azureml/work-with-data/datasets-tutorial/pipeline-with-datasets/pipeline-for-image-classification.yml deleted file mode 100644 index f33e9474..00000000 --- a/how-to-use-azureml/work-with-data/datasets-tutorial/pipeline-with-datasets/pipeline-for-image-classification.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: pipeline-for-image-classification -dependencies: -- pip: - - azureml-sdk - - pandas<=0.23.4 - - fuse diff --git a/how-to-use-azureml/work-with-data/datasets-tutorial/scriptrun-with-data-input-output/how-to-use-scriptrun.yml b/how-to-use-azureml/work-with-data/datasets-tutorial/scriptrun-with-data-input-output/how-to-use-scriptrun.yml deleted file mode 100644 index 87dc3b4c..00000000 --- a/how-to-use-azureml/work-with-data/datasets-tutorial/scriptrun-with-data-input-output/how-to-use-scriptrun.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: how-to-use-scriptrun -dependencies: -- pip: - - azureml-sdk diff --git a/how-to-use-azureml/work-with-data/datasets-tutorial/timeseries-datasets/tabular-timeseries-dataset-filtering.yml b/how-to-use-azureml/work-with-data/datasets-tutorial/timeseries-datasets/tabular-timeseries-dataset-filtering.yml deleted file mode 100644 index af9acab3..00000000 --- a/how-to-use-azureml/work-with-data/datasets-tutorial/timeseries-datasets/tabular-timeseries-dataset-filtering.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: tabular-timeseries-dataset-filtering -dependencies: -- pip: - - azureml-sdk - - pandas<=0.23.4 diff --git a/how-to-use-azureml/work-with-data/datasets-tutorial/train-with-datasets/train-with-datasets.yml b/how-to-use-azureml/work-with-data/datasets-tutorial/train-with-datasets/train-with-datasets.yml deleted file mode 100644 index d13f92dc..00000000 --- a/how-to-use-azureml/work-with-data/datasets-tutorial/train-with-datasets/train-with-datasets.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: train-with-datasets -dependencies: -- pip: - - azureml-sdk - - azureml-widgets - - pandas<=0.23.4 - - fuse - - scikit-learn diff --git a/index.md b/index.md index 96f08250..fe7b9978 100644 --- a/index.md +++ b/index.md @@ -18,7 +18,6 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an | [Forecasting BikeShare Demand](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb) | Forecasting | BikeShare | Remote | None | Azure ML AutoML | Forecasting | | [Forecasting orange juice sales with deployment](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/forecasting-orange-juice-sales/auto-ml-forecasting-orange-juice-sales.ipynb) | Forecasting | Orange Juice Sales | Remote | Azure Container Instance | Azure ML AutoML | None | | [Forecasting orange juice sales with deployment](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/automated-machine-learning/forecasting-pipelines/auto-ml-forecasting-pipelines.ipynb) | Forecasting | Orange Juice Sales | Remote | Azure Container Instance | Azure ML AutoML | None | -| [Register a model and deploy locally](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local.ipynb) | Deployment | None | Local | Local | None | None | | :star:[Data drift quickdemo](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/work-with-data/datadrift-tutorial/datadrift-tutorial.ipynb) | Filtering | NOAA | Remote | None | Azure ML | Dataset, Timeseries, Drift | | :star:[Datasets with ML Pipeline](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/work-with-data/datasets-tutorial/pipeline-with-datasets/pipeline-for-image-classification.ipynb) | Train | Fashion MNIST | Remote | None | Azure ML | Dataset, Pipeline, Estimator, ScriptRun | | :star:[Filtering data using Tabular Timeseiries Dataset related API](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/work-with-data/datasets-tutorial/timeseries-datasets/tabular-timeseries-dataset-filtering.ipynb) | Filtering | NOAA | Local | None | Azure ML | Dataset, Tabular Timeseries | @@ -84,9 +83,7 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an |Title| Task | Dataset | Training Compute | Deployment Target | ML Framework | Tags | |:----|:-----|:-------:|:----------------:|:-----------------:|:------------:|:------------:| -| [Train MNIST in PyTorch, convert, and deploy with ONNX Runtime](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/onnx/onnx-train-pytorch-aml-deploy-mnist.ipynb) | Image Classification | MNIST | AML Compute | Azure Container Instance | ONNX | ONNX Converter | -| [Deploy ResNet50 with ONNX Runtime](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/onnx/onnx-modelzoo-aml-deploy-resnet50.ipynb) | Image Classification | ImageNet | Local | Azure Container Instance | ONNX | ONNX Model Zoo | -| :star:[Convert and deploy TinyYolo with ONNX Runtime](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/onnx/onnx-convert-aml-deploy-tinyyolo.ipynb) | Object Detection | PASCAL VOC | local | Azure Container Instance | ONNX | ONNX Converter | + ## Other Notebooks @@ -114,13 +111,6 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an | [spark_session_on_synapse_spark_pool](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/azure-synapse/spark_session_on_synapse_spark_pool.ipynb) | | | | | | | | [Synapse_Job_Scala_Support](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/azure-synapse/Synapse_Job_Scala_Support.ipynb) | | | | | | | | [Synapse_Session_Scala_Support](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/azure-synapse/Synapse_Session_Scala_Support.ipynb) | | | | | | | -| [multi-model-register-and-deploy](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/deploy-multi-model/multi-model-register-and-deploy.ipynb) | | | | | | | -| [register-model-deploy-local-advanced](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/deploy-to-local/register-model-deploy-local-advanced.ipynb) | | | | | | | -| [enable-app-insights-in-production-service](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/enable-app-insights-in-production-service/enable-app-insights-in-production-service.ipynb) | | | | | | | -| [onnx-model-register-and-deploy](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/onnx/onnx-model-register-and-deploy.ipynb) | | | | | | | -| [production-deploy-to-aks-ssl](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks-ssl.ipynb) | | | | | | | -| [production-deploy-to-aks](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.ipynb) | | | | | | | -| [production-deploy-to-aks-gpu](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/deployment/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.ipynb) | | | | | | | | [explain-model-on-amlcompute](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb) | | | | | | | | [save-retrieve-explanations-run-history](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/explain-model/azure-integration/run-history/save-retrieve-explanations-run-history.ipynb) | | | | | | | | [train-explain-model-locally-and-deploy](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/explain-model/azure-integration/scoring-time/train-explain-model-locally-and-deploy.ipynb) | | | | | | | diff --git a/setup-environment/configuration.ipynb b/setup-environment/configuration.ipynb index eb7c60d7..b9079f40 100644 --- a/setup-environment/configuration.ipynb +++ b/setup-environment/configuration.ipynb @@ -102,7 +102,7 @@ "source": [ "import azureml.core\n", "\n", - "print(\"This notebook was created using version 1.55.0 of the Azure ML SDK\")\n", + "print(\"This notebook was created using version 1.56.0 of the Azure ML SDK\")\n", "print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")" ] }, diff --git a/tutorials/compute-instance-quickstarts/quickstart-azureml-in-10mins/quickstart-azureml-in-10mins.ipynb b/tutorials/compute-instance-quickstarts/quickstart-azureml-in-10mins/quickstart-azureml-in-10mins.ipynb index 6b45eadc..a1aa09bc 100644 --- a/tutorials/compute-instance-quickstarts/quickstart-azureml-in-10mins/quickstart-azureml-in-10mins.ipynb +++ b/tutorials/compute-instance-quickstarts/quickstart-azureml-in-10mins/quickstart-azureml-in-10mins.ipynb @@ -1,501 +1,501 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/tutorials/quickstart-ci/AzureMLin10mins.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "# Quickstart: Train and deploy a model in Azure Machine Learning in 10 minutes\n", - "\n", - "In this quickstart, learn how to get started with Azure Machine Learning. You'll train an image classification model using the [MNIST](https://docs.microsoft.com/azure/open-datasets/dataset-mnist) dataset.\n", - "\n", - "You'll learn how to:\n", - "\n", - "* Download a dataset and look at the data\n", - "* Train an image classification model and log metrics using MLflow\n", - "* Deploy the model to do real-time inference" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "## Import Data\n", - "\n", - "Before you train a model, you need to understand the data you're using to train it. In this section, learn how to:\n", - "\n", - "* Download the MNIST dataset\n", - "* Display some sample images\n", - "\n", - "You'll use Azure Open Datasets to get the raw MNIST data files. [Azure Open Datasets](https://docs.microsoft.com/azure/open-datasets/overview-what-are-open-datasets) are curated public datasets that you can use to add scenario-specific features to machine learning solutions for better models. Each dataset has a corresponding class, `MNIST` in this case, to retrieve the data in different ways." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from azureml.opendatasets import MNIST\n", - "\n", - "data_folder = os.path.join(os.getcwd(), \"/tmp/qs_data\")\n", - "os.makedirs(data_folder, exist_ok=True)\n", - "\n", - "mnist_file_dataset = MNIST.get_file_dataset()\n", - "mnist_file_dataset.download(data_folder, overwrite=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "### Take a look at the data\n", - "\n", - "Load the compressed files into `numpy` arrays. Then use `matplotlib` to plot 30 random images from the dataset with their labels above them. \n", - "\n", - "Note this step requires a `load_data` function that's included in an `utils.py` file. This file is placed in the same folder as this notebook. The `load_data` function simply parses the compressed files into numpy arrays." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from utils import load_data\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import glob\n", - "\n", - "\n", - "# note we also shrink the intensity values (X) from 0-255 to 0-1. This helps the model converge faster.\n", - "X_train = (\n", - " load_data(\n", - " glob.glob(\n", - " os.path.join(data_folder, \"**/train-images-idx3-ubyte.gz\"), recursive=True\n", - " )[0],\n", - " False,\n", - " )\n", - " / 255.0\n", - ")\n", - "X_test = (\n", - " load_data(\n", - " glob.glob(\n", - " os.path.join(data_folder, \"**/t10k-images-idx3-ubyte.gz\"), recursive=True\n", - " )[0],\n", - " False,\n", - " )\n", - " / 255.0\n", - ")\n", - "y_train = load_data(\n", - " glob.glob(\n", - " os.path.join(data_folder, \"**/train-labels-idx1-ubyte.gz\"), recursive=True\n", - " )[0],\n", - " True,\n", - ").reshape(-1)\n", - "y_test = load_data(\n", - " glob.glob(\n", - " os.path.join(data_folder, \"**/t10k-labels-idx1-ubyte.gz\"), recursive=True\n", - " )[0],\n", - " True,\n", - ").reshape(-1)\n", - "\n", - "\n", - "# now let's show some randomly chosen images from the traininng set.\n", - "count = 0\n", - "sample_size = 30\n", - "plt.figure(figsize=(16, 6))\n", - "for i in np.random.permutation(X_train.shape[0])[:sample_size]:\n", - " count = count + 1\n", - " plt.subplot(1, sample_size, count)\n", - " plt.axhline(\"\")\n", - " plt.axvline(\"\")\n", - " plt.text(x=10, y=-10, s=y_train[i], fontsize=18)\n", - " plt.imshow(X_train[i].reshape(28, 28), cmap=plt.cm.Greys)\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "## Train model and log metrics with MLflow\n", - "\n", - "You'll train the model using the code below. Note that you are using MLflow autologging to track metrics and log model artefacts.\n", - "\n", - "You'll be using the [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) classifier from the [SciKit Learn framework](https://scikit-learn.org/) to classify the data.\n", - "\n", - "**Note: The model training takes approximately 2 minutes to complete.**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "gather": { - "logged": 1612966046970 + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/tutorials/quickstart-ci/AzureMLin10mins.png)" + ] }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "# Quickstart: Train and deploy a model in Azure Machine Learning in 10 minutes\n", + "\n", + "In this quickstart, learn how to get started with Azure Machine Learning. You'll train an image classification model using the [MNIST](https://docs.microsoft.com/azure/open-datasets/dataset-mnist) dataset.\n", + "\n", + "You'll learn how to:\n", + "\n", + "* Download a dataset and look at the data\n", + "* Train an image classification model and log metrics using MLflow\n", + "* Deploy the model to do real-time inference" + ] }, - "nteract": { - "transient": { - "deleting": false - } + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "## Import Data\n", + "\n", + "Before you train a model, you need to understand the data you're using to train it. In this section, learn how to:\n", + "\n", + "* Download the MNIST dataset\n", + "* Display some sample images\n", + "\n", + "You'll use Azure Open Datasets to get the raw MNIST data files. [Azure Open Datasets](https://docs.microsoft.com/azure/open-datasets/overview-what-are-open-datasets) are curated public datasets that you can use to add scenario-specific features to machine learning solutions for better models. Each dataset has a corresponding class, `MNIST` in this case, to retrieve the data in different ways." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from azureml.opendatasets import MNIST\n", + "\n", + "data_folder = os.path.join(os.getcwd(), \"/tmp/qs_data\")\n", + "os.makedirs(data_folder, exist_ok=True)\n", + "\n", + "mnist_file_dataset = MNIST.get_file_dataset()\n", + "mnist_file_dataset.download(data_folder, overwrite=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "### Take a look at the data\n", + "\n", + "Load the compressed files into `numpy` arrays. Then use `matplotlib` to plot 30 random images from the dataset with their labels above them. \n", + "\n", + "Note this step requires a `load_data` function that's included in an `utils.py` file. This file is placed in the same folder as this notebook. The `load_data` function simply parses the compressed files into numpy arrays." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from utils import load_data\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import glob\n", + "\n", + "\n", + "# note we also shrink the intensity values (X) from 0-255 to 0-1. This helps the model converge faster.\n", + "X_train = (\n", + " load_data(\n", + " glob.glob(\n", + " os.path.join(data_folder, \"**/train-images-idx3-ubyte.gz\"), recursive=True\n", + " )[0],\n", + " False,\n", + " )\n", + " / 255.0\n", + ")\n", + "X_test = (\n", + " load_data(\n", + " glob.glob(\n", + " os.path.join(data_folder, \"**/t10k-images-idx3-ubyte.gz\"), recursive=True\n", + " )[0],\n", + " False,\n", + " )\n", + " / 255.0\n", + ")\n", + "y_train = load_data(\n", + " glob.glob(\n", + " os.path.join(data_folder, \"**/train-labels-idx1-ubyte.gz\"), recursive=True\n", + " )[0],\n", + " True,\n", + ").reshape(-1)\n", + "y_test = load_data(\n", + " glob.glob(\n", + " os.path.join(data_folder, \"**/t10k-labels-idx1-ubyte.gz\"), recursive=True\n", + " )[0],\n", + " True,\n", + ").reshape(-1)\n", + "\n", + "\n", + "# now let's show some randomly chosen images from the traininng set.\n", + "count = 0\n", + "sample_size = 30\n", + "plt.figure(figsize=(16, 6))\n", + "for i in np.random.permutation(X_train.shape[0])[:sample_size]:\n", + " count = count + 1\n", + " plt.subplot(1, sample_size, count)\n", + " plt.axhline(\"\")\n", + " plt.axvline(\"\")\n", + " plt.text(x=10, y=-10, s=y_train[i], fontsize=18)\n", + " plt.imshow(X_train[i].reshape(28, 28), cmap=plt.cm.Greys)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "## Train model and log metrics with MLflow\n", + "\n", + "You'll train the model using the code below. Note that you are using MLflow autologging to track metrics and log model artefacts.\n", + "\n", + "You'll be using the [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) classifier from the [SciKit Learn framework](https://scikit-learn.org/) to classify the data.\n", + "\n", + "**Note: The model training takes approximately 2 minutes to complete.**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1612966046970 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "# create the model\n", + "import mlflow\n", + "import numpy as np\n", + "from sklearn.linear_model import LogisticRegression\n", + "from azureml.core import Workspace\n", + "\n", + "# connect to your workspace\n", + "ws = Workspace.from_config()\n", + "\n", + "# create experiment and start logging to a new run in the experiment\n", + "experiment_name = \"azure-ml-in10-mins-tutorial\"\n", + "\n", + "# set up MLflow to track the metrics\n", + "mlflow.set_tracking_uri(ws.get_mlflow_tracking_uri())\n", + "mlflow.set_experiment(experiment_name)\n", + "mlflow.autolog()\n", + "\n", + "# set up the Logistic regression model\n", + "reg = 0.5\n", + "clf = LogisticRegression(\n", + " C=1.0 / reg, solver=\"liblinear\", multi_class=\"auto\", random_state=42\n", + ")\n", + "\n", + "# train the model\n", + "with mlflow.start_run() as run:\n", + " clf.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## View Experiment\n", + "In the left-hand menu in Azure Machine Learning Studio, select __Jobs__ and then select your experiment (azure-ml-in10-mins-tutorial). An experiment is a grouping of many runs from a specified script or piece of code. Information for the run is stored under that experiment. If the name doesn't exist when you submit an experiment, if you select your run you will see various tabs containing metrics, logs, explanations, etc.\n", + "\n", + "## Version control your models with the model registry\n", + "\n", + "You can use model registration to store and version your models in your workspace. Registered models are identified by name and version. Each time you register a model with the same name as an existing one, the registry increments the version. The code below registers and versions the model you trained above. Once you have executed the code cell below you will be able to see the model in the registry by selecting __Models__ in the left-hand menu in Azure Machine Learning Studio." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1612881042710 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "# register the model\n", + "model_uri = \"runs:/{}/model\".format(run.info.run_id)\n", + "model = mlflow.register_model(model_uri, \"sklearn_mnist_model\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Deploy the model for real-time inference\n", + "In this section you learn how to deploy a model so that an application can consume (inference) the model over REST.\n", + "\n", + "### Create deployment configuration\n", + "The code cell gets a _curated environment_, which specifies all the dependencies required to host the model (for example, the packages like scikit-learn). Also, you create a _deployment configuration_, which specifies the amount of compute required to host the model. In this case, the compute will have 1CPU and 1GB memory." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1612881061728 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "# create environment for the deploy\n", + "from azureml.core.environment import Environment\n", + "from azureml.core.conda_dependencies import CondaDependencies\n", + "from azureml.core.webservice import AciWebservice\n", + "\n", + "# get a curated environment\n", + "env = Environment.get(\n", + " workspace=ws, \n", + " name=\"AzureML-sklearn-1.0\"\n", + ")\n", + "env.inferencing_stack_version='latest'\n", + "\n", + "# create deployment config i.e. compute resources\n", + "aciconfig = AciWebservice.deploy_configuration(\n", + " cpu_cores=1,\n", + " memory_gb=1,\n", + " tags={\"data\": \"MNIST\", \"method\": \"sklearn\"},\n", + " description=\"Predict MNIST with sklearn\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "### Deploy model\n", + "\n", + "This next code cell deploys the model to Azure Container Instance (ACI).\n", + "\n", + "**Note: The deployment takes approximately 3 minutes to complete.**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "%%time\n", + "import uuid\n", + "from azureml.core.model import InferenceConfig\n", + "from azureml.core.environment import Environment\n", + "from azureml.core.model import Model\n", + "\n", + "# get the registered model\n", + "model = Model(ws, \"sklearn_mnist_model\")\n", + "\n", + "# create an inference config i.e. the scoring script and environment\n", + "inference_config = InferenceConfig(entry_script=\"score.py\", environment=env)\n", + "\n", + "# deploy the service\n", + "service_name = \"sklearn-mnist-svc-\" + str(uuid.uuid4())[:4]\n", + "service = Model.deploy(\n", + " workspace=ws,\n", + " name=service_name,\n", + " models=[model],\n", + " inference_config=inference_config,\n", + " deployment_config=aciconfig,\n", + ")\n", + "\n", + "service.wait_for_deployment(show_output=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The [*scoring script*](score.py) file referenced in the code above can be found in the same folder as this notebook, and has two functions:\n", + "\n", + "1. an `init` function that executes once when the service starts - in this function you normally get the model from the registry and set global variables\n", + "1. a `run(data)` function that executes each time a call is made to the service. In this function, you normally format the input data, run a prediction, and output the predicted result.\n", + "\n", + "### View Endpoint\n", + "Once the model has been successfully deployed, you can view the endpoint by navigating to __Endpoints__ in the left-hand menu in Azure Machine Learning Studio. You will be able to see the state of the endpoint (healthy/unhealthy), logs, and consume (how applications can consume the model)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "nteract": { + "transient": { + "deleting": false + } + } + }, + "source": [ + "## Test the model service\n", + "\n", + "You can test the model by sending a raw HTTP request to test the web service. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1612881538381 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "# send raw HTTP request to test the web service.\n", + "import requests\n", + "\n", + "# send a random row from the test set to score\n", + "random_index = np.random.randint(0, len(X_test) - 1)\n", + "input_data = '{\"data\": [' + str(list(X_test[random_index])) + \"]}\"\n", + "\n", + "headers = {\"Content-Type\": \"application/json\"}\n", + "\n", + "resp = requests.post(service.scoring_uri, input_data, headers=headers)\n", + "\n", + "print(\"POST to url\", service.scoring_uri)\n", + "print(\"label:\", y_test[random_index])\n", + "print(\"prediction:\", resp.text)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Clean up resources\n", + "\n", + "If you're not going to continue to use this model, delete the Model service using:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "gather": { + "logged": 1612881556520 + }, + "jupyter": { + "outputs_hidden": false, + "source_hidden": false + }, + "nteract": { + "transient": { + "deleting": false + } + } + }, + "outputs": [], + "source": [ + "# if you want to keep workspace and only delete endpoint (it will incur cost while running)\n", + "service.delete()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you want to control cost further, stop the compute instance by selecting the \"Stop compute\" button next to the **Compute** dropdown. Then start the compute instance again the next time you need it." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "## Next Steps\n", + "\n", + "In this quickstart, you learned how to run machine learning code in Azure Machine Learning.\n", + "\n", + "Now that you have working code in a development environment, learn how to submit a **_job_** - ideally on a schedule or trigger (for example, arrival of new data).\n", + "\n", + " [**Learn how to get started with Azure ML Job Submission**](../quickstart-azureml-python-sdk/quickstart-azureml-python-sdk.ipynb) " + ] } - }, - "outputs": [], - "source": [ - "# create the model\n", - "import mlflow\n", - "import numpy as np\n", - "from sklearn.linear_model import LogisticRegression\n", - "from azureml.core import Workspace\n", - "\n", - "# connect to your workspace\n", - "ws = Workspace.from_config()\n", - "\n", - "# create experiment and start logging to a new run in the experiment\n", - "experiment_name = \"azure-ml-in10-mins-tutorial\"\n", - "\n", - "# set up MLflow to track the metrics\n", - "mlflow.set_tracking_uri(ws.get_mlflow_tracking_uri())\n", - "mlflow.set_experiment(experiment_name)\n", - "mlflow.autolog()\n", - "\n", - "# set up the Logistic regression model\n", - "reg = 0.5\n", - "clf = LogisticRegression(\n", - " C=1.0 / reg, solver=\"liblinear\", multi_class=\"auto\", random_state=42\n", - ")\n", - "\n", - "# train the model\n", - "with mlflow.start_run() as run:\n", - " clf.fit(X_train, y_train)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## View Experiment\n", - "In the left-hand menu in Azure Machine Learning Studio, select __Jobs__ and then select your experiment (azure-ml-in10-mins-tutorial). An experiment is a grouping of many runs from a specified script or piece of code. Information for the run is stored under that experiment. If the name doesn't exist when you submit an experiment, if you select your run you will see various tabs containing metrics, logs, explanations, etc.\n", - "\n", - "## Version control your models with the model registry\n", - "\n", - "You can use model registration to store and version your models in your workspace. Registered models are identified by name and version. Each time you register a model with the same name as an existing one, the registry increments the version. The code below registers and versions the model you trained above. Once you have executed the code cell below you will be able to see the model in the registry by selecting __Models__ in the left-hand menu in Azure Machine Learning Studio." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "gather": { - "logged": 1612881042710 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, - "nteract": { - "transient": { - "deleting": false - } - } - }, - "outputs": [], - "source": [ - "# register the model\n", - "model_uri = \"runs:/{}/model\".format(run.info.run_id)\n", - "model = mlflow.register_model(model_uri, \"sklearn_mnist_model\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Deploy the model for real-time inference\n", - "In this section you learn how to deploy a model so that an application can consume (inference) the model over REST.\n", - "\n", - "### Create deployment configuration\n", - "The code cell gets a _curated environment_, which specifies all the dependencies required to host the model (for example, the packages like scikit-learn). Also, you create a _deployment configuration_, which specifies the amount of compute required to host the model. In this case, the compute will have 1CPU and 1GB memory." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "gather": { - "logged": 1612881061728 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, - "nteract": { - "transient": { - "deleting": false - } - } - }, - "outputs": [], - "source": [ - "# create environment for the deploy\n", - "from azureml.core.environment import Environment\n", - "from azureml.core.conda_dependencies import CondaDependencies\n", - "from azureml.core.webservice import AciWebservice\n", - "\n", - "# get a curated environment\n", - "env = Environment.get(\n", - " workspace=ws, \n", - " name=\"AzureML-sklearn-1.0\"\n", - ")\n", - "env.inferencing_stack_version='latest'\n", - "\n", - "# create deployment config i.e. compute resources\n", - "aciconfig = AciWebservice.deploy_configuration(\n", - " cpu_cores=1,\n", - " memory_gb=1,\n", - " tags={\"data\": \"MNIST\", \"method\": \"sklearn\"},\n", - " description=\"Predict MNIST with sklearn\",\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "### Deploy model\n", - "\n", - "This next code cell deploys the model to Azure Container Instance (ACI).\n", - "\n", - "**Note: The deployment takes approximately 3 minutes to complete.**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, - "nteract": { - "transient": { - "deleting": false - } - } - }, - "outputs": [], - "source": [ - "%%time\n", - "import uuid\n", - "from azureml.core.model import InferenceConfig\n", - "from azureml.core.environment import Environment\n", - "from azureml.core.model import Model\n", - "\n", - "# get the registered model\n", - "model = Model(ws, \"sklearn_mnist_model\")\n", - "\n", - "# create an inference config i.e. the scoring script and environment\n", - "inference_config = InferenceConfig(entry_script=\"score.py\", environment=env)\n", - "\n", - "# deploy the service\n", - "service_name = \"sklearn-mnist-svc-\" + str(uuid.uuid4())[:4]\n", - "service = Model.deploy(\n", - " workspace=ws,\n", - " name=service_name,\n", - " models=[model],\n", - " inference_config=inference_config,\n", - " deployment_config=aciconfig,\n", - ")\n", - "\n", - "service.wait_for_deployment(show_output=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The [*scoring script*](score.py) file referenced in the code above can be found in the same folder as this notebook, and has two functions:\n", - "\n", - "1. an `init` function that executes once when the service starts - in this function you normally get the model from the registry and set global variables\n", - "1. a `run(data)` function that executes each time a call is made to the service. In this function, you normally format the input data, run a prediction, and output the predicted result.\n", - "\n", - "### View Endpoint\n", - "Once the model has been successfully deployed, you can view the endpoint by navigating to __Endpoints__ in the left-hand menu in Azure Machine Learning Studio. You will be able to see the state of the endpoint (healthy/unhealthy), logs, and consume (how applications can consume the model)." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "nteract": { - "transient": { - "deleting": false - } - } - }, - "source": [ - "## Test the model service\n", - "\n", - "You can test the model by sending a raw HTTP request to test the web service. " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "gather": { - "logged": 1612881538381 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, - "nteract": { - "transient": { - "deleting": false - } - } - }, - "outputs": [], - "source": [ - "# send raw HTTP request to test the web service.\n", - "import requests\n", - "\n", - "# send a random row from the test set to score\n", - "random_index = np.random.randint(0, len(X_test) - 1)\n", - "input_data = '{\"data\": [' + str(list(X_test[random_index])) + \"]}\"\n", - "\n", - "headers = {\"Content-Type\": \"application/json\"}\n", - "\n", - "resp = requests.post(service.scoring_uri, input_data, headers=headers)\n", - "\n", - "print(\"POST to url\", service.scoring_uri)\n", - "print(\"label:\", y_test[random_index])\n", - "print(\"prediction:\", resp.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Clean up resources\n", - "\n", - "If you're not going to continue to use this model, delete the Model service using:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "gather": { - "logged": 1612881556520 - }, - "jupyter": { - "outputs_hidden": false, - "source_hidden": false - }, - "nteract": { - "transient": { - "deleting": false - } - } - }, - "outputs": [], - "source": [ - "# if you want to keep workspace and only delete endpoint (it will incur cost while running)\n", - "service.delete()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you want to control cost further, stop the compute instance by selecting the \"Stop compute\" button next to the **Compute** dropdown. Then start the compute instance again the next time you need it." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "## Next Steps\n", - "\n", - "In this quickstart, you learned how to run machine learning code in Azure Machine Learning.\n", - "\n", - "Now that you have working code in a development environment, learn how to submit a **_job_** - ideally on a schedule or trigger (for example, arrival of new data).\n", - "\n", - " [**Learn how to get started with Azure ML Job Submission**](../quickstart-azureml-python-sdk/quickstart-azureml-python-sdk.ipynb) " - ] - } - ], - "metadata": { - "authors": [ - { - "name": "cewidste" - } ], - "kernelspec": { - "display_name": "Python 3.8 - AzureML", - "language": "python", - "name": "python38-azureml" + "metadata": { + "authors": [ + { + "name": "cewidste" + } + ], + "kernelspec": { + "display_name": "Python 3.8 - AzureML", + "language": "python", + "name": "python38-azureml" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.18" + }, + "notice": "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.", + "nteract": { + "version": "nteract-front-end@1.0.0" + } }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.18" - }, - "notice": "Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.", - "nteract": { - "version": "nteract-front-end@1.0.0" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file