GPU 3Node: Run PyTorch AI/ML Workloads

GPU 3Node: Run PyTorch AI/ML Workloads

Table of Contents


We show the steps to run PyTorch on Python with Cuda to run AI/ML workloads, such as the different codes available on the HuggingFace NLP course.


Set a Python Virtual Environment

Before installing Python package with pip, you should create a virtual environment.

  • Install the prerequisites
    apt update
    apt install python3-pip python3-dev
    pip3 install --upgrade pip
    pip3 install virtualenv
  • Create a virtual environment
    mkdir ~/python_project
    cd ~/python_project
    virtualenv python_project_env
    source python_project_env/bin/activate

Install PyTorch and Test Cuda

Once you’ve created and activated a virtual environment for Pyhton, you can install different Python packages.

  • Install PyTorch and upgrade Numpy
    pip3 install torch
    pip3 install numpy --upgrade

Before going further, you can check if Cuda is properly installed on your machine.

  • Check that Cuda is available on Python with PyTorch by using the following lines:
    import torch
    torch.cuda.device_count() # the output should be 1
    torch.cuda.current_device() # the output should be 0

Set and Access Jupyter Notebook

You can run Jupyter Notebook on the remote VM and access it on your local browser.

  • Install Jupyter Notebook
    pip3 install notebook
  • Run Jupyter Notebook in no-browser mode and take note of the URL and the token
    jupyter notebook --no-browser --port=8080 --ip=
  • On your local machine, copy and paste on a browser the given URL but make sure to change with the WireGuard IP (here it is and to set the correct token.<insert_token>

Run AI/ML Workloads

After following the steps above, you should now be able to run Python codes that will make use of your GPU node to compute AI and ML workloads.

Questions and Feedback

If you have any questions, you can ask the ThreeFold community for help on the ThreeFold Forum or on the ThreeFold Grid Tester Community on Telegram.