
PyTorch is a flexible and high-performance machine learning framework that includes a rich set of libraries for building and training deep learning models. It integrates smoothly with Python and supports fast, dynamic computation, making it a top choice for both research and production. Running PyTorch on Ubuntu 22.04, a stable and developer-friendly Linux distribution, offers an ideal environment for AI and machine learning workloads thanks to its strong support for modern software and hardware acceleration.
This guide walks you through the steps to install PyTorch on Ubuntu 22.04 Server, a stable and widely-used Linux distribution ideal for machine learning development and deployment. For containerized environments, you can also explore how to build a PyTorch container image to streamline deployment across platforms.
To install PyTorch on a server, verify the system capabilities to correctly enable the framework. In addition, you can install PyTorch as a native system package or install it using an environment management tool such as Conda as described in the steps below.
Verify that your Server has a supported GPU driver. For example, view the Vultr NVidia GPU usage
If the above command fails, you cannot the PyTorch GPU package on the server, When successful, install the PyTorch GPU package
Upgrade the Python Pip package manager
Using Pip, install the latest PyTorch version on your server
The above command installs the latest PyTorch version built on the CUDA version 11.8. The additional packages, torchvision and torchaudio extend PyTorch support with image and audio processing capabilities.
To install PyTorch on a GPU server, either install Anaconda or Miniconda then follow the steps below.
Activate your target Conda environment. For example env1
Install the latest PyTorch version from the pytorch and the nvidia channels
The above command installs the latest PyTorch version with the CUDA version 11.8. Verify the latest version and install it in your environment.
To install PyTorch on a CPU-only server without any GPU attachment, install the latest version together with the torch, torchvision, and torchaudio processing packages as described below.
Upgrade the Python Pip package manager
Using Pip, install the latest PyTorch version
To install PyTorch using Conda on a CPU-only system, install also install the cpuonly package from the pytorch Conda channel. Because this is a CPU-only environment, do not use packages from the nvidia channel.
Activate your target Conda environment. For example env1
Install the latest PyTorch version from the pytorch channel
The above command installs PyTorch with the cpuonly, torchvision, and torchaudio packages in your Conda environment.
To verify that PyTorch is available and correctly installed on your server, perform the following test operations.
Access the Python Shell
Import the torch package
Declare a random tensor
Print the tensor value
Output:
As displayed in the above output, PyTorch is actively running and performing computation tasks on your server
Access the Python Shell
Import the PyTorch torch package
Verify that PyTorch has access to the server GPU
Output:
When the above result is True, PyTorch is correctly running with GPU access, If False, PyTorch cannot run with GPU-acceleration.
You have installed PyTorch on a Ubuntu server using both GPU and CPU-Only methods. Using PyTorch, you can extensively use other computation packages on your server to run and develop applications. For more information on how to install PyTorch, visit the official installation documentation.
0 Comments
Be the first to comment and share your perspective with the community.