
TensorFlow is a popular open-source machine learning platform that helps users implement deep learning and machine learning models to solve common business problems. TensorFlow offers an ecosystem for developers and enterprises to build scalable machine learning applications. For example, it's used to train neural networks referred to as stateful dataflow graphs where each graph node represents neural network operations or multi-dimensional arrays.
This article demonstrates the steps to deploy a temporary or a persistent TensorFlow workspace using the official Docker image and the NVIDIA Docker Toolkit.
Before you begin, you should:
A record. This article uses tensorflow.example.com for demonstration.The Vultr Cloud GPU servers feature NVIDIA GPUs for machine learning, artificial intelligence, and so on. They come with licensed NVIDIA drivers and the CUDA Toolkit, which are essential for the proper functioning of the GPUs. This section demonstrates the steps to verify the GPU availability on the server and inside a container.
Execute the nvidia-smi command on the server.
The above command outputs the information about the connected GPU. It includes information such as the driver version, CUDA version, GPU model, available memory, GPU usage, and so on.
Execute the nvidia-smi command inside a container.
The above command uses the official nvidia/cuda image to verify the GPU access inside a container. The NVIDIA Docker Toolkit enables you to use the GPU inside the containers using the --gpus option. The --rm option removes the container from the disk once the container ends.
The Vultr Cloud GPU servers offer access to high-end GPUs that you can leverage for training your machine learning models, saving a lot of time without paying the upfront cost of the hardware. This section explains the steps to deploy a temporary TensorFlow workspace on a Vultr Cloud GPU server.
Disable the firewall.
The above command disables the firewall to allow inbound connections on all ports.
Deploy a new Docker container.
The above command uses the official tensorflow/tensorflow image with the latest-gpu-jupyter tag that contains the GPU-accelerated TensorFlow environment and the Jupyter notebook server. Copy the token from the output of this command to access the Jupyter notebook interface.
The following is the explanation for each parameter used in the above command.
-p 8888:8888: Expose the connection on port 8888.--gpus all: GPU access inside the container.-it: Interactive session. Allow keyboard interrupt.--rm: Remove the container when stopped.-v /root/notebooks:/tf/notebooks: Store all the notebooks in the /root/notebooks directory.Verify the GPU availability using the TensorFlow module.
http://PUBLIC_IP:8888 in your web browser and use the copied token to log in to the interface.Run the following code in a new cell.
Output.
The output confirms that the GPU is available in the TensorFlow module. You can stop the workspace by opening the terminal window and pressing Ctrl + C. Stopping the container will not delete the notebooks. You can find them in the /root/notebooks directory.
Deploying the TensorFlow Workspace on a Vultr Cloud GPU server provides more than just access to high-end GPU. The Jupyter notebook interface allows you to work with others on a machine-learning project, offering more flexibility and scalability than a local setup. It also allows you to access and manage your machine learning resources from anywhere with an internet connection. This section demonstrates the steps to deploy a persistent TensorFlow workspace on a Vultr Cloud GPU server using Docker Compose.
Create and enter a new directory named tensorflow-workspace.
The above commands create and enter a new directory named tensorflow-workspace in the /root directory. You use this directory to store all the configuration files related to the TensorFlow Workspace, such as Nginx configuration, SSL certificate, and so on.
Create a new file named docker-compose.yaml.
Add the following contents to the file.
The above configuration defines three services. The jupyter service runs the container that contains the GPU-accelerated TensorFlow workspace, and it uses the volumes attribute to store all the notebooks in the /root/notebooks directory. The nginx service runs a container using the official Nginx image that acts as a reverse proxy server between clients and the jupyter service. The certbot service runs a container using the official Certbot image that issues a Let's Encrypt SSL certificate for the specified domain name. Replace YOUR_EMAIL with your email address.
Save the file and close the file editor using Ctrl+X then Enter.
Create a new directory named nginx.
Create a new file named nginx.conf.
Add the following contents to the file.
The above configuration instructs the Nginx server to serve the ACME challenge generated by Certbot. You must perform this step for the Certbot container to verify the ownership of the domain name and issue an SSL certificate for it. You swap this configuration in the later steps to set up the reverse proxy server.
Save the file and close the file editor using Ctrl+X then Enter.
Create a new file named dhparam.pem using the openssl command.
The above command generates a DHparam or Diffie-Hellman parameter, a key exchange algorithm to secure communications between two parties. You use this as another layer of security to protect the server from getting hacked or attacked by malicious individuals who might try to intercept or decrypt the communications between the server and the client.
Before starting the services, you must point your domain name to the server's IP address using an
Arecord.
Deploy the Docker Compose services.
The above command starts the services defined in the docker-compose.yaml file in detached mode. This means that the services will start in the background, and you can use your terminal for other commands.
Verify the SSL issuance.
The above command outputs the list of contents inside the directory created by Certbot for your domain name. The output should contain the fullchain.pem and the privkey.pem files. It may take up to five minutes to generate the SSL certificate. If this command takes longer than that, you can troubleshoot by viewing the logs using the docker-compose logs certbot command.
Stop the nginx container.
The above command stops the nginx container so you can swap the Nginx configuration in the next steps.
Swap the Nginx configuration.
Add the following contents to the file.
The above configuration uses the SSL certificate generated by Certbot and additional SSL parameters to increase the security of the workspace. It configures a reverse proxy server that channels the incoming traffic to the jupyter container on port 8888. It also defines a location block to serve ACME challenge files for SSL renewals using Cron.
Save the file and close the file editor using Ctrl+X then Enter.
Start the nginx container.
The above command starts the nginx container that uses the new configuration. You can confirm the deployment of the workspace by opening https://tensorflow.example.com in your web browser.
Fetch the token from the Docker logs.
The above command outputs the logs generated by the jupyter container. It contains the token to access the Jupyter notebook interface.
You can also set up a password for accessing the Jupyter notebook interface by following the steps given below.
https://tensorflow.example.com.Append an entry to the Cron table.
The above command opens the Cron table editor. cron is a built-in job scheduler in the Linux operating system to run the specified commands at a scheduled time. Refer to How to Use the Cron Task Scheduler to learn more.
Add the following lines to the table.
The above statements define two tasks that start the certbot container to regenerate the SSL certificate and restart the nginx container to reload the configuration using the latest SSL certificate.
Exit the editor using Esc then ExclamationWQ and Enter.
Enable the firewall.
The above commands enable the firewall and allow the incoming connection on port 80 for HTTP traffic, 443 for HTTPS traffic, and 22 for SSH connections.
This article demonstrated the steps to deploy a temporary or a persistent TensorFlow workspace using the official Docker image and the NVIDIA Docker Toolkit. You can deploy a temporary workspace to leverage the high-end hardware offered by Vultr to perform resource-hungry tasks like training a model or performing visualizations. You can also deploy a persistent workspace for an efficient remote development environment, as the Jupyter notebook interface allows you to work with others on a machine-learning project.
0 Comments
Be the first to comment and share your perspective with the community.