Azure Machine Learning Notebooks Integration with the Wallaroo SDK
Tags: azure, machinelearning, datascience, mlops
Published: 2023-03-11 00:18:55

Data Scientists that natively use Azure Machine Learning for model training and development can continue their progress to production ML through deploying models to Wallaroo through the [Wallaroo SDK](https://docs.wallaroo.ai/wallaroo-developer-guides/wallaroo-sdk-guides/). Through this integration into Azure ML Data scientists can easily upload their models and specify modeling pipelines via the Wallaroo SDK with just a few lines of python, using the notebook environment that they are most comfortable with. This helps to reduce change management overhead for production ML leading to improved scale and repeatable production model operations.

The following guide is created to assist users with installing the Wallaroo SDK, setting up authentication through Azure ML, and making a standard connection to a Wallaroo instance through Azure ML Workspace.

This [AzureML Wallaroo SDK Install tutorial](https://github.com/WallarooLabs/Wallaroo_Tutorials/tree/main/development/sdk-install-guides/azure-ml-sdk-install) is available for download and can be run on the [Wallaroo Community Edition](https://portal.wallaroo.community/). 

To learn how to set up the Azure ML environment follow the steps in this guide

[Quickstart: Create workspace resources you need to get started with Azure Machine Learning](https://learn.microsoft.com/en-us/azure/machine-learning/quickstart-create-resources)


## Steps

<u>Setting Up The Virtual Python Environment.</u>

In the Azure ML window select the **Launch Studio** button



![Azure ML console and Launch Studio button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1fv24prd7a0nb1xcc7i.jpg)

Next step is to create a workspace. 


![Azure ML Create Workspace Button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/725sy5032zistfx6b75g.jpg)

Inside the workspace select **Notebook** from the left margin. 


![Create Notebook Menu Option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rhf5877xh99koa253rp.jpg)


Then create a new folder where the Jupyter Notebooks from Wallaroo will be stored. 


![Azure ML Create New Folder Button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oip1nzsw6aw5y3bjch8a.jpg)


Once we have the new folder created, open the terminal window as shown below. 


![Open Terminal Window Button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap45nezrhsplhsqem40f.png)

With the Terminal window open the next step is to create the Python virtual environment with conda. Replace wallaroosdk with the name of the virtual environment as required by your organization. Note that Python 3.8.6 and above is specified as a requirement for Python libraries used with the Wallaroo SDK. The following will install the latest version of Python 3.8, which as of this time is 3.8.15.

Staying in the terminal window run the following commands to install the SDK

![conda create command syntax.  -n wallaroosdk python=3.8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ydf3fxhsyct5nukc2zk.png)

Next step is to activate the environment.


![conda command syntax. conda activate wallaroosdk ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1o8tc40uasgfpi6i0ih.png)

Next Step is to Install the ipykernel library. This allows the JupyterHub notebooks to access the Python virtual environment as a kernel.

![conda command syntax. conda install ipykernel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6kx3eex1k0mjv2h50hm.png)

Next install the new virtual environment as a python kernel.


![command syntax. ipython kernal install --user --name=wallaroosdk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qosyix9gcl4t2k8s9oh4.png)


Next step is to install the Wallaroo SDK. This process may take several minutes while the other required Python libraries are added to the virtual environment.


![pip install wallaroo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcj82n63852x0461cbrw.png)

Once the conda virtual environment has been installed, it can either be selected as a new Jupyter Notebook kernel, or the Notebook’s kernel can be set to an existing Jupyter notebook. If a notebook is existing, close it then reopen to select the new Wallaroo SDK environment.


![Azure ML Select kernel console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynfy8gw81ifruxlgvx2a.jpg)

To use a new Notebook:


1. From the left navigation panel, select **+->Notebook**.
2. From the Kernel selection dropbox on the upper right side, select the new virtual environment - in this case, `wallaroosdk`.

To update an existing Notebook to use the new virtual environment as a kernel:



1. From the main menu, select **Kernel->Change Kernel**.
2. Select the new kernel.

With the Wallaroo Python SDK installed, remote commands and inferences can be performed through the following steps.

Open a Connection to Wallaroo through the Wallaroo client.

This is accomplished using the wallaroo.Client(api_endpoint, auth_endpoint, auth_type command) command that connects to the Wallaroo instance services. For more information on the DNS names of Wallaroo services, see the [DNS Integration Guide](https://docs.wallaroo.ai/wallaroo-operations-guide/wallaroo-configuration/wallaroo-dns-guide/).

The Client method takes the following parameters:


    

- **api_endpoint (String)**: The URL to the Wallaroo instance API service.
- **auth_endpoint (String)**: The URL to the Wallaroo instance Keycloak service.
- **auth_type command (String)**: The authorization type. In this case, SSO.

Once run, the wallaroo.Client command provides a URL to grant the SDK permission to your specific Wallaroo environment. When displayed, enter the URL into a browser and confirm permissions. Depending on the configuration of the Wallaroo instance, the user will either be presented with a login request to the Wallaroo instance or be authenticated through a broker such as Google, Github, etc. 

To use the broker, select it from the list under the username/password login forms. For more information on Wallaroo authentication configurations, see the [Wallaroo Authentication Configuration](https://docs.wallaroo.ai/wallaroo-operations-guide/wallaroo-configuration/wallaroo-sso-authentication/) Guides.


![Wallaroo Login Window for Username and password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqpuu2wyuwusg98v0hda.png)

Once authenticated, the user will verify adding the device the user is establishing the connection from. Once both steps are complete, then the connection is granted.


![Wallaroo Grant Access to sdk client](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37nmcnevkobk4i9l16ll.png)

The connection is stored in the variable wl for use in all other Wallaroo calls.

And with that the Wallaroo SDK is installed in the Azure ML environment, and now you can continue progress from ML model development through to production and easily upload ML models and specify modeling pipelines via the Wallaroo SDK, with just a few lines of python, using the notebook environment that you are most comfortable with.

You can step through the ML production process using the [Wallaroo Tutorials](https://docs.wallaroo.ai/wallaroo-tutorials/) and by setting up the free [Community Edition](https://portal.wallaroo.community/). More ML Production learning resources from Wallaroo.ai can be found on our [YouTube channel](https://www.youtube.com/@wallaroolabsinc.5530) and [blogs](https://www.wallaroo.ai/blog).