Skip to main content
Print

INTRO TO INTERACTIVE LLMS WITH OLLAMA PART 1: GETTING STARTED

By Nathan J. Elrod

Ollama is an open-source LLM model manager. It provides a unified front-end for deploying a number of popular open-source LLMs (including various flavors of llama2 and Mistral), simplifying the experience. Unlike proprietary LLMs, there is no chat limit and use is subject only to general ARCC resource and queue limits. Llama can be run locally, or is installed on the ARCC and available to run via Terminal command, or through a localhost API accessible by Open OnDemand/Jupyter notebook. This article will focus on ollama use on the ARCC.

1. REQUEST HPC RESOURCES

First start up a job on the ARCC, via SLURM command or through Open OnDemand. Note the GPU or CPU node.

**NOTE: llama will only run on a full GPU (“large” queue).**

2. SSH INTO NODE

Using the node from Step 1, open up a Terminal window and securely connect:

ssh <node_name>

3. START AN OLLAMA SERVER

Once inside the node, start a localhost llama instance by running

ollama serve

You should see the following appear in the Terminal:

**NOTE: Any ollama command executed in a new Terminal window should initiate activity in this server instance

4a. (OPTIONAL) PULL AN OLLAMA MODEL

The various LLM models and tags supported by ollama are listed here. If a model hasn’t been run before, it must first be pulled into the ARCC repository. Launch a new Terminal window and enter <model_name> is the name of the model being run; <tags> listed after a colon typically signify the parameter size used (i.e., 7b, 70b, etc.).

ollama pull <model_name>:<tags>

4b. (OPTIONAL) CLONE AN OLLAMA MODEL

You may want to clone a base model for some tasks like fine-tuning, etc. To do this simply Launch a new Terminal window and enter :

ollama cp <model_name>:<tags> <new_model_name>

5a. RUN A MODEL: TERMINAL

Once the llama server is running on a node and the necessary models are available, there are a few ways to interact with it. First is directly through the Terminal command line. This essentially created a command-line chat bot:

ollama run <model_name>:<tags>

5b. RUN A MODEL: JUPYTER NOTEBOOK

If an Open OnDemand job is running, and the connected ollama server is running on that node, a Jupyter notebook can connect to it via localhost with the correct Python packages such as langchain.

6. PROMPT ENGINEERING

Remember it is best practice to structure LLM queries in the format relevant to that model. For example, llama2 and mistral use the following:

''' [INST] Instruction [/INST] Example model answer(s) [/INST] Follow-up instructions [/INST] '''

HELPFUL LINKS

Table of Contents