Techno Blender
Digitally Yours.

Boost Your ML Team’s Productivity with Container-Based Development in the Cloud | by Sofian Hamiti | Dec, 2022

0 28


Earlier this year, I published 2 guides (here, and here) to hosting code-server on SageMaker. It shows how you can run VS Code on scalable cloud compute, and code from anywhere without worrying about local setup. All you need is an internet connection.

Image by author: created with Stable Diffusion

In this post, we will go a step further and show how to do container-based development in the cloud, to speed up your ML project delivery.

We will pull an example python 3.10 container image from Dockerhub, and develop in it with VS Code on SageMaker. You will need access to a SageMaker Notebook Instance to go through the example. A small one should be enough.

With container-based development, you write, execute, and test your ML code inside containers. It means that you can work with the same libraries and dependencies as your team members, making collaboration easier with consistent and highly reproducible development environments.

Another advantage is that you develop and test your code in an environment that can behave exactly like your production environment, helping move faster from 0 to 1 in your project.

Photo by Desola Lanre-Ologun on Unsplash

And hosting code-server on SageMaker provides minimal changes to a local development experience in VS Code, allowing you to code from anywhere, on scalable cloud compute.

“But I thought VS Code was Open Source”

Typically with VS Code, you would use the Dev Containers extension to do container-based development. However, you cannot use it with code-server, nor any other open source VS Code projects.

Photo by Cookie the Pom on Unsplash

While the core of VS Code is open source, the marketplace and many extensions published by Microsoft are not. And Microsoft prohibits the use of any non-Microsoft VS Code from accessing their marketplace. See Differences compared to VS Code for more details.

So how do we do container-based development with VS Code on SageMaker then?

So we cannot bring the container to the IDE due to Microsoft extension license issues. But what if we bring the IDE to the container? In fact, code-server is web-based and can truly run anywhere. The setup is very easy and you can do it in 3 steps:

Step 1: Add code-server to your existing Dockerfile

You can add code-server to your container with a single line of code. Here is an example for adding it to an a python 3.10 image from Dockerhub

Image by author: I use an existing Dockerfile in my Notebook Instance, with python:3.10

Add one line and this is it!

Step 2: Build and launch the container image on the Notebook Instance

Launch a terminal via the Jupyter/Jupyterlab of your Notebook Instance:

Image by author: If you use Jupyter, the button should be on the top-right corner

You can now navigate to your Dockerfile folder, and build the container image locally with the following command:

# BUILD THE CONTAINER IMAGE LOCALLY
docker build -t ide-in-container:latest .

Once the image is built, you can run the container with the command to launch code-server:

# RUN CONTAINER WITH VS CODE IN IT
docker run --rm -it -p 8080:8080 ide-in-container:latest code-server --auth none --disable-telemetry --bind-addr 0.0.0.0:8080

We expose code-server to the instance through the default port 8080.

Image by author: You should see the following after running the docker command

Step 3: Access VS Code through the Notebook Instance Jupyter Proxy

Now, all you need is to copy your Notebook Instance URL, change it a bit, and past it into a new tab:

Images by author: On the left is my instance original URL. I replaced /tree with /proxy/8080/ and pasted it in a new browser tab.

The tab should now open VS Code:

Image by author: You can install the Python extension for VS Code and get to work in your ML project!

Notes

To further streamline your work, you can mount the local Notebook Instance volume, and point VS Code to your existing configuration (extensions, key bindings, settings). In the example Dockerfile, I point VS Code to the /home/SageMaker/vscode-config config folder, I already had on the instance. This is done using the XDG_DATA_HOME environment variable.

And here is how you can mount the Notebook Instance volume to the container:

# RUN THIS COMMAND IF YOU WANT TO MOUNT THE NOTEBOOK INSTANCE HOME/SAGEMAKER FOLDER
docker run --rm -it -p 8080:8080 -v /home/ec2-user/SageMaker/:/home/SageMaker ide-in-container:latest code-server --auth none --disable-telemetry --bind-addr 0.0.0.0:8080

To improve your collaboration, you can add this “environment Dockerfile” on your project team GitHub repo. in this way it will be versioned and everyone can work with the exact same dependencies, at any time.

Developing inside containers with cloud-based IDEs can help streamline your ML project and team collaboration by making it easy to run and test code in a consistent environment, and by allowing you to access that development environment from anywhere.

In this post, I have shared with you a simple approach for running VS Code in a container, hosted on Amazon SageMaker.

To go further, you can visit 5 Simple Steps to MLOps with GitHub Actions, MLflow, and SageMaker Pipelines and learn how your team can easily run an end-to-end MLOps project using GitHub Actions and SageMaker.


Earlier this year, I published 2 guides (here, and here) to hosting code-server on SageMaker. It shows how you can run VS Code on scalable cloud compute, and code from anywhere without worrying about local setup. All you need is an internet connection.

Image by author: created with Stable Diffusion

In this post, we will go a step further and show how to do container-based development in the cloud, to speed up your ML project delivery.

We will pull an example python 3.10 container image from Dockerhub, and develop in it with VS Code on SageMaker. You will need access to a SageMaker Notebook Instance to go through the example. A small one should be enough.

With container-based development, you write, execute, and test your ML code inside containers. It means that you can work with the same libraries and dependencies as your team members, making collaboration easier with consistent and highly reproducible development environments.

Another advantage is that you develop and test your code in an environment that can behave exactly like your production environment, helping move faster from 0 to 1 in your project.

Photo by Desola Lanre-Ologun on Unsplash

And hosting code-server on SageMaker provides minimal changes to a local development experience in VS Code, allowing you to code from anywhere, on scalable cloud compute.

“But I thought VS Code was Open Source”

Typically with VS Code, you would use the Dev Containers extension to do container-based development. However, you cannot use it with code-server, nor any other open source VS Code projects.

Photo by Cookie the Pom on Unsplash

While the core of VS Code is open source, the marketplace and many extensions published by Microsoft are not. And Microsoft prohibits the use of any non-Microsoft VS Code from accessing their marketplace. See Differences compared to VS Code for more details.

So how do we do container-based development with VS Code on SageMaker then?

So we cannot bring the container to the IDE due to Microsoft extension license issues. But what if we bring the IDE to the container? In fact, code-server is web-based and can truly run anywhere. The setup is very easy and you can do it in 3 steps:

Step 1: Add code-server to your existing Dockerfile

You can add code-server to your container with a single line of code. Here is an example for adding it to an a python 3.10 image from Dockerhub

Image by author: I use an existing Dockerfile in my Notebook Instance, with python:3.10

Add one line and this is it!

Step 2: Build and launch the container image on the Notebook Instance

Launch a terminal via the Jupyter/Jupyterlab of your Notebook Instance:

Image by author: If you use Jupyter, the button should be on the top-right corner

You can now navigate to your Dockerfile folder, and build the container image locally with the following command:

# BUILD THE CONTAINER IMAGE LOCALLY
docker build -t ide-in-container:latest .

Once the image is built, you can run the container with the command to launch code-server:

# RUN CONTAINER WITH VS CODE IN IT
docker run --rm -it -p 8080:8080 ide-in-container:latest code-server --auth none --disable-telemetry --bind-addr 0.0.0.0:8080

We expose code-server to the instance through the default port 8080.

Image by author: You should see the following after running the docker command

Step 3: Access VS Code through the Notebook Instance Jupyter Proxy

Now, all you need is to copy your Notebook Instance URL, change it a bit, and past it into a new tab:

Images by author: On the left is my instance original URL. I replaced /tree with /proxy/8080/ and pasted it in a new browser tab.

The tab should now open VS Code:

Image by author: You can install the Python extension for VS Code and get to work in your ML project!

Notes

To further streamline your work, you can mount the local Notebook Instance volume, and point VS Code to your existing configuration (extensions, key bindings, settings). In the example Dockerfile, I point VS Code to the /home/SageMaker/vscode-config config folder, I already had on the instance. This is done using the XDG_DATA_HOME environment variable.

And here is how you can mount the Notebook Instance volume to the container:

# RUN THIS COMMAND IF YOU WANT TO MOUNT THE NOTEBOOK INSTANCE HOME/SAGEMAKER FOLDER
docker run --rm -it -p 8080:8080 -v /home/ec2-user/SageMaker/:/home/SageMaker ide-in-container:latest code-server --auth none --disable-telemetry --bind-addr 0.0.0.0:8080

To improve your collaboration, you can add this “environment Dockerfile” on your project team GitHub repo. in this way it will be versioned and everyone can work with the exact same dependencies, at any time.

Developing inside containers with cloud-based IDEs can help streamline your ML project and team collaboration by making it easy to run and test code in a consistent environment, and by allowing you to access that development environment from anywhere.

In this post, I have shared with you a simple approach for running VS Code in a container, hosted on Amazon SageMaker.

To go further, you can visit 5 Simple Steps to MLOps with GitHub Actions, MLflow, and SageMaker Pipelines and learn how your team can easily run an end-to-end MLOps project using GitHub Actions and SageMaker.

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment