This lesson is being piloted (Beta version)

How to use Ollama with SuperPOD

Overview

Teaching: 20 min
Exercises: 0 min
Questions
  • How to use Ollama

Objectives
  • OLLAMA on HPC: M3/SuperPOD

OLLAMA

Key Features of Ollama:

Ollama on HPC: M3/SuperPOD

How to use Ollama on HPC: M3/SuperPOD terminal?

Step 1: request a compute node with 1 GPU:

M3:

$ srun -A Allocation -N1 -G1 --mem=64gb --time=4:00:00 -p gpu-dev --pty $SHELL

SuperPOD:

$ srun -A Allocation -N1 -G1 --mem=64gb --time=4:00:00 --pty $SHELL

Step 2: Load Ollama model:

$ module load testing/ollama/0.12.11

Step 3: Export path to Ollama model

$ export OLLAMA_BASE_DIR=/projects/tuev/LLMs/LLMs/Ollama_models/

Step 4: Serve Ollama

There are several command:

$ ollama --version & # to check the version of ollama
# ollama list & # to list all downloaded LLMs to the location where you specified OLLAMA_BASE_DIR
$ ollama serve & # to initialize ollama
$ ollama pull LLMs_name # to download LLMs
$ ollama run LLMS_name # to run LLMs

Before you can run anything with Ollama, you have to serve it first:

$ ollama serve &

Step 5: Now Ollama has been loaded and served. Let’s check the local models:

$ ollama list &

You should see the screen like this:

image

If there are any other models that you want us to download, please email me: tuev@smu.edu

Step 6: Download Ollama model

You can download any LLM model that you downloaded previously to chat:

$ ollama pull llama3:70

Step 7: Run Ollama model

You can run any LLM model that you downloaded previously to chat:

$ ollama run llama3:70

image

Step 8: Stop Ollama model

$ killall ollama

How to run Ollama on M3 using Open OnDemand portal: hpc.m3.smu.edu?

Step 1. Login to Open OnDemand portal as usual

Step 2: JupyterLab’s Custom Environment setting

module load testing/ollama/0.12.11
export OLLAMA_BASE_DIR=/projects/tuev/LLMs/LLMs/Ollama_models
ollama serve &

Step 3: Select gpu-dev partition

Step 4: Click launch and open a Jupyter Notebook.

import ollama
import subprocess
import os
# --- LLM & RAG ---
from langchain_community.chat_models import ChatOllama

# get home and job id
home_dir =  os.getenv('HOME')
job_id = os.getenv('SLURM_JOB_ID')

# get ollama directory or default to home
ollama_dir = os.getenv('OLLAMA_BASE_DIR', home_dir)

try:
    with open(f"{ollama_dir}/ollama/host_{job_id}.txt") as f:
        HOST = f.read().strip()
    with open(f"{ollama_dir}/ollama/port_{job_id}.txt") as f:
        PORT = f.read().strip()
    ollama_url = f"http://{HOST}:{PORT}"
except Exception as e:
    print("[⚠️] Could not read host/port, you manually set the `ollama_url` below.")


chat_model = ChatOllama(
            base_url=ollama_url,
            model="gpt-oss:20b",
            temperature=0,
        )

response = chat_model.invoke("Where is SMU")
print(response.content)

Key Points

  • Ollama, SuperPOD