PyTorch on CARC GPUs¶
SSH in to the cluster¶
To connect to a CARC cluster (Hopper in this example), you will need to use the secure shell command below with your username in place of $USERNAME. This will prompt you for your password. When typing your password, you will not get any visual feedback. If you have issues with connecting to the machine, please reach out to the CARC helpdesk.
Create the Condarc File¶
To create the Condarc file that you will need, use your favorite text editor to create an empty file '.condarc'. For this tutorial I will use nano, which is an easy beginning text editor.
The above code creates a blank file using the nano text editor.In the condarc file you just created, paste the following then change the $USERNAME prompt to your username.
auto_activate_base: false
channels:
- conda-forge
- defaults
envs_dirs:
- /users/$USERNAME/.conda/envs
pkgs_dirs:
- /users/$USERNAME/.conda/pkgs
To save the lines of code you just pasted into the file, hold down the control key and press 'O'. This "writes out" or saves the text. You can then exit the text editor by holding down the control key and pressing 'X'.
To confirm that the file has been edited and contains the correct code, run the command.
The following text should appear under your command line.
auto_activate_base: false
channels:
- conda-forge
- defaults
envs_dirs:
- /users/{YOUR USERNAME HERE}/.conda/envs
pkgs_dirs:
- /users/{YOUR USERNAME HERE}/.conda/pkgs
Navigate to the PyTorch1.9-K40-Compatible directory¶
Run the following code to change directories into the PyTorch1.9-K40-Compatible directory.
Assuming you have a default command line prompt, this will change your command prompt to reflect the updated directory. If you are not in the PyTorch1.9-K40-Compatible directory, you will run into issues in later steps. To confirm that you are in the correct directory, print your working directory with the following command.Create the Conda Environment¶
Now that you are in the correct directory, you'll create your python environment. To create a python environment, you first need to load the miniconda3 module with the following command: (No output should print from this command)
You can then create the python environment by running the following command: When asked to proceed, enter "y"Activate the Conda Environment¶
Once the environment is created, you will need to activate it before you start the pytorch installation. Activate the environment by running the following:
This command will add a prefix to your command prompt that indicates which environment you are in. Your command line prompt should take the form of:Pip installation¶
To install pytorch, run the following command:
After the installation is complete, we can confirm that the torch install was sucessful in JupyterHub. Follow the link below to the CARC website.Next, log in to JupyterHub with your CARC username and password. If you are logged in without being prompted to select a server, click on the control panel button in the upper right corner. Then select "Stop My Server", then select "Start Server"
You will be prompted to choose a server. For this tutorial, I will choose a server option with GPUs.
Create a new notebook by selecting new > Python [conda env:.conda-pytorch-1.9-cuda-11-K40]To test that the installation was successful, run the following code.
With 2 GPUs, you should get an output of 2.Migrated from UNM-CARC QuickBytes (last source update 2023-09-20). Spotted a problem? Open an issue or pull request.