diff --git a/how-to-use-azureml/azure-databricks/README.md b/how-to-use-azureml/azure-databricks/README.md index 4749c0c65..552ce2ca3 100644 --- a/how-to-use-azureml/azure-databricks/README.md +++ b/how-to-use-azureml/azure-databricks/README.md @@ -1,33 +1,73 @@ -Azure Databricks is a managed Spark offering on Azure and customers already use it for advanced analytics. It provides a collaborative Notebook based environment with CPU or GPU based compute cluster. +Azure Databricks is a managed Spark offering on Azure and customers already use it for advanced analytics. It provides a collaborative Notebook based environment with CPU or GPU based compute cluster. -In this section, you will find sample notebooks on how to use Azure Machine Learning SDK with Azure Databricks. You can train a model using Spark MLlib and then deploy the model to ACI/AKS from within Azure Databricks. You can also use Automated ML capability (**public preview**) of Azure ML SDK with Azure Databricks. +In this section, you will find sample notebooks on how to use Azure Machine Learning SDK with Azure Databricks. You can train a model using Spark MLlib and then deploy the model to ACI/AKS from within Azure Databricks. You can also use Automated ML capability (**public preview**) of Azure ML SDK with Azure Databricks. -- Customers who use Azure Databricks for advanced analytics can now use the same cluster to run experiments with or without automated machine learning. -- You can keep the data within the same cluster. -- You can leverage the local worker nodes with autoscale and auto termination capabilities. -- You can use multiple cores of your Azure Databricks cluster to perform simultenous training. -- You can further tune the model generated by automated machine learning if you chose to. -- Every run (including the best run) is available as a pipeline, which you can tune further if needed. +- Customers who use Azure Databricks for advanced analytics can now use the same cluster to run experiments with or without automated machine learning. +- You can keep the data within the same cluster. +- You can leverage the local worker nodes with autoscale and auto termination capabilities. +- You can use multiple cores of your Azure Databricks cluster to perform simultenous training. +- You can further tune the model generated by automated machine learning if you chose to. +- Every run (including the best run) is available as a pipeline, which you can tune further if needed. - The model trained using Azure Databricks can be registered in Azure ML SDK workspace and then deployed to Azure managed compute (ACI or AKS) using the Azure Machine learning SDK. Please follow our [Azure doc](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-configure-environment#azure-databricks) to install the sdk in your Azure Databricks cluster before trying any of the sample notebooks. -**Single file** - +**Single file** - The following archive contains all the sample notebooks. You can the run notebooks after importing [DBC](Databricks_AMLSDK_1-4_6.dbc) in your Databricks workspace instead of downloading individually. -Notebooks 1-4 have to be run sequentially & are related to Income prediction experiment based on this [dataset](https://archive.ics.uci.edu/ml/datasets/adult) and demonstrate how to data prep, train and operationalize a Spark ML model with Azure ML Python SDK from within Azure Databricks. +Notebooks 1-4 have to be run sequentially & are related to Income prediction experiment based on this [dataset](https://archive.ics.uci.edu/ml/datasets/adult) and demonstrate how to data prep, train and operationalize a Spark ML model with Azure ML Python SDK from within Azure Databricks. Notebook 6 is an Automated ML sample notebook for Classification. Learn more about [how to use Azure Databricks as a development environment](https://docs.microsoft.com/azure/machine-learning/service/how-to-configure-environment#azure-databricks) for Azure Machine Learning service. -**Databricks as a Compute Target from AML Pipelines** -You can use Azure Databricks as a compute target from [Azure Machine Learning Pipelines](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-ml-pipelines). Take a look at this notebook for details: [aml-pipelines-use-databricks-as-compute-target.ipynb](https://github.com/Azure/MachineLearningNotebooks/tree/master/how-to-use-azureml/azure-databricks/databricks-as-remote-compute-target/aml-pipelines-use-databricks-as-compute-target.ipynb). +**Databricks as a Compute Target from Azure ML Pipelines** +You can use Azure Databricks as a compute target from [Azure Machine Learning Pipelines](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-ml-pipelines). Take a look at this notebook for details: [aml-pipelines-use-databricks-as-compute-target.ipynb](https://github.com/Azure/MachineLearningNotebooks/tree/master/how-to-use-azureml/azure-databricks/databricks-as-remote-compute-target/aml-pipelines-use-databricks-as-compute-target.ipynb). + +# Linked Azure Databricks and Azure Machine Learning Workspaces (Preview) +Customers can now link Azure Databricks and AzureML Workspaces to better enable MLOps scenarios by [managing their tracking data in a single place when using the MLflow client](https://mlflow.org/docs/latest/tracking.html#mlflow-tracking) - the Azure ML workspace. + +## Linking the Workspaces (Admin operation) + +1. The Azure Databricks Azure portal blade now includes a new button to link an Azure ML workspace. +![New ADB Portal Link button](./img/adb-link-button.png) +2. Both a new or existing Azure ML Workspace can be linked in the resulting prompt. Follow any instructions to set up the Azure ML Workspace. +![Link Prompt](./img/link-prompt.png) +3. After a successful link operation, you should see the Azure Databricks overview reflect the linked status +![Linked Successfully](./img/adb-successful-link.png) + +## Configure MLflow to send data to Azure ML (All roles) + +1. Add azureml-mlflow as a library to any notebook or cluster that should send data to Azure ML. You can do this via: + 1. [DBUtils](https://docs.azuredatabricks.net/user-guide/dev-tools/dbutils.html#dbutils-library) + ``` + dbutils.library.installPyPI("azureml-mlflow") + dbutils.library.restartPython() # Removes Python state + ``` + 2. [Cluster Libraries](https://docs.azuredatabricks.net/user-guide/libraries.html#install-a-library-on-a-cluster) + ![Cluster Library](./img/cluster-library.png) +2. [Set the MLflow tracking URI](https://mlflow.org/docs/latest/tracking.html#where-runs-are-recorded) to the following scheme: + ``` + adbazureml://${azuremlRegion}.experiments.azureml.net/history/v1.0/subscriptions/${azuremlSubscriptionId}/resourceGroups/${azuremlResourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/${azuremlWorkspaceName} + ``` + 1. You can automatically configure this on your clusters for all subsequent notebook sessions using this helper script instead of manually setting the tracking URI in the notebook: + * [AzureML Tracking Cluster Init Script](./linking/README.md) +3. If configured correctly, you'll now be able to see your MLflow tracking data in both Azure ML (via the REST API and all clients) and Azure Databricks (in the MLflow UI and using the MLflow client) + + +## Known Preview Limitations +While we roll this experience out to customers for feedback, there are some known limitations we'd love comments on in addition to any other issues seen in your workflow. +### 1-to-1 Workspace linking +Currently, an Azure ML Workspace can only be linked to one Azure Databricks Workspace at a time. +### Data synchronization +At the moment, data is only generated in the Azure Machine Learning workspace for tracking. Editing tags via the Azure Databricks MLflow UI won't be reflected in the Azure ML UI. +### Java and R support +The experience currently is only available from the Python MLflow client. For more on SDK concepts, please refer to [notebooks](https://github.com/Azure/MachineLearningNotebooks). **Please let us know your feedback.** - -![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/azure-databricks/README.png) \ No newline at end of file + +![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/azure-databricks/README.png) diff --git a/how-to-use-azureml/azure-databricks/img/adb-link-button.png b/how-to-use-azureml/azure-databricks/img/adb-link-button.png new file mode 100755 index 000000000..03cc1d4e6 Binary files /dev/null and b/how-to-use-azureml/azure-databricks/img/adb-link-button.png differ diff --git a/how-to-use-azureml/azure-databricks/img/adb-successful-link.png b/how-to-use-azureml/azure-databricks/img/adb-successful-link.png new file mode 100755 index 000000000..f2d62cbf4 Binary files /dev/null and b/how-to-use-azureml/azure-databricks/img/adb-successful-link.png differ diff --git a/how-to-use-azureml/azure-databricks/img/cluster-library.png b/how-to-use-azureml/azure-databricks/img/cluster-library.png new file mode 100755 index 000000000..b86c5f512 Binary files /dev/null and b/how-to-use-azureml/azure-databricks/img/cluster-library.png differ diff --git a/how-to-use-azureml/azure-databricks/img/link-prompt.png b/how-to-use-azureml/azure-databricks/img/link-prompt.png new file mode 100755 index 000000000..3384edc1a Binary files /dev/null and b/how-to-use-azureml/azure-databricks/img/link-prompt.png differ diff --git a/how-to-use-azureml/azure-databricks/linking/README.md b/how-to-use-azureml/azure-databricks/linking/README.md new file mode 100644 index 000000000..5bcb788ff --- /dev/null +++ b/how-to-use-azureml/azure-databricks/linking/README.md @@ -0,0 +1,56 @@ +# Adding an init script to an Azure Databricks cluster + +The [azureml-cluster-init.sh](./azureml-cluster-init.sh) script configures the environment to +1. Use the configured AzureML Workspace with Workspace.from_config() +2. Set the default MLflow Tracking Server to be the AzureML managed one + +Modify azureml-cluster-init.sh by providing the values for region, subscriptionId, resourceGroupName, and workspaceName of your target Azure ML workspace in the highlighted section at the top of the script. + +To create the Azure Databricks cluster-scoped init script + +1. Create the base directory you want to store the init script in if it does not exist. + ``` + dbutils.fs.mkdirs("dbfs:/databricks//") + ``` + +2. Create the script by copying the contents of azureml-cluster-init.sh + ``` + dbutils.fs.put("/databricks//azureml-cluster-init.sh",""" + + """, True) + +3. Check that the script exists. + ``` + display(dbutils.fs.ls("dbfs:/databricks//azureml-cluster-init.sh")) + ``` + +1. Configure the cluster to run the script. + * Using the cluster configuration page + 1. On the cluster configuration page, click the Advanced Options toggle. + 1. At the bottom of the page, click the Init Scripts tab. + 1. In the Destination drop-down, select a destination type. Example: 'DBFS' + 1. Specify a path to the init script. + ``` + dbfs:/databricks//azureml-cluster-init.sh + ``` + 1. Click Add + + * Using the API. + ``` + curl -n -X POST -H 'Content-Type: application/json' -d '{ + "cluster_id": "", + "num_workers": , + "spark_version": "", + "node_type_id": "", + "cluster_log_conf": { + "dbfs" : { + "destination": "dbfs:/cluster-logs" + } + }, + "init_scripts": [ { + "dbfs": { + "destination": "dbfs:/databricks//azureml-cluster-init.sh" + } + } ] + }' https:///api/2.0/clusters/edit + ``` diff --git a/how-to-use-azureml/azure-databricks/linking/azureml-cluster-init.sh b/how-to-use-azureml/azure-databricks/linking/azureml-cluster-init.sh new file mode 100644 index 000000000..36ecfa52a --- /dev/null +++ b/how-to-use-azureml/azure-databricks/linking/azureml-cluster-init.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# This script configures the environment to +# 1. Use the configured AzureML Workspace with azureml.core.Workspace.from_config() +# 2. Set the default MLflow Tracking Server to be the AzureML managed one + +############## START CONFIGURATION ################# +# Provide the required *AzureML* workspace information +region="" # example: westus2 +subscriptionId="" # example: bcb65f42-f234-4bff-91cf-9ef816cd9936 +resourceGroupName="" # example: dev-rg +workspaceName="" # example: myazuremlws + +# Optional config directory +configLocation="/databricks/config.json" +############### END CONFIGURATION ################# + + +# Drop the workspace configuration on the cluster +sudo touch $configLocation +sudo echo {\\"subscription_id\\": \\"${subscriptionId}\\", \\"resource_group\\": \\"${resourceGroupName}\\", \\"workspace_name\\": \\"${workspaceName}\\"} > $configLocation + +# Set the MLflow Tracking URI +trackingUri="adbazureml://${region}.experiments.azureml.net/history/v1.0/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/${workspaceName}" +sudo echo export MLFLOW_TRACKING_URI=${trackingUri} >> /databricks/spark/conf/spark-env.sh