PyTorch Installation¶
PyTorch is a framework for the Python programming language, designed for machine learning. It includes a set of tools for working with models, commonly used in natural language processing, computer vision, and other similar fields. You can install it on your server manually using this guide.
PyTorch Installation on Linux¶
This instruction is suitable for the following operating systems: Ubuntu 22.04, and verified for Python versions: Python 3.10.
Note
If you plan to use GPU acceleration, please install NVIDIA drivers and CUDA according to this instruction.
-
Install Python:
In Ubuntu 22.04, this version is installed by default, so we do not recommend installing a newer version.
-
Create a virtual environment for Python:
-
Activate the virtual environment:
After successful activation, the prompt will include the name of the virtual environment in parentheses:
Note
You can create as many virtual environments as you like and install different libraries (including simultaneously, but sometimes this may cause conflicts).
-
Install PyTorch libraries in the virtual environment:
-
Verify PyTorch installation:
To do this, run a Python console command
python
and then run the following program:If the installation is successful, you will receive the following output:
(venv) user@49069:~$ python Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> x = torch.rand(5, 3) >>> print(x) tensor([[0.80, 0.04, 0.6], [0.32, 0.59, 0.7], [0.8, 0.70, 0.25], [0.40, 0.9, 0.9], [0.8, 0.15, 0.5]])
-
Verify if PyTorch libraries use CUDA:
To do this, run the following program in a Python console:
If PyTorch can work in GPU mode, the output will be:
To exit the virtual environment, use the command: