You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One you're logged in to the compute node, you should set up your cache directories and Apptainer settings.
22
+
### Building the container
22
23
23
-
👉 *If you're following this tutorial, **you should do this every time you're running ollama on Hyak!** This is because the default settings for Apptainer will use your home directory for caching, which will quickly fill up your home directory and cause your jobs to fail. If you are aware of this and have already set `APPTAINER_CACHEDIR`, you can remove the line that sets `APPTAINER_CACHEDIR`.*
24
+
Next, you'll need to build the container. In this example, we'll build the container in a directory in your scratch space. You can change the path to wherever you'd like to build the container.
24
25
25
26
```bash
26
-
# Do this in every session where you're running ollama on Hyak!
By default, the container will install the latest version of `ollama`. If you want to install a specific version, you can specify the version with the `OLLAMA_VERSION` build argument. The most recent version tested with this container is `0.5.8`.
37
+
38
+
### Starting the `ollama` server
39
+
40
+
The model files that `ollama` uses are stored by default in your home directory. As these files can be quite large, it's a good idea to store them somewhere else. In this example, we'll store them in your scratch space.
You should run the command above every time you start a new server. If you want to run it automatically every time you log in, you can add it to your `.bashrc` file.
Next, you'll have to start the `ollama` server. You can set the port for the server with the `OLLAMA_PORT` environment variable or leave it unset to use a random port.
50
+
51
+
```bash
52
+
# Start the ollama server as an Apptainer instance named "ollama-$USER":
53
+
# --nv: Use the NVIDIA GPU
54
+
# --writable-tmpfs: Use a writable tmpfs for the cache directory
55
+
# --bind /gscratch: Bind /gscratch to the container
Next, build the container. (You only need to do this once.)
59
+
### Running `ollama` commands
60
+
61
+
To run `ollama` commands, execute the `apptainer run` command with your instance as the first argument and the `ollama` command as the second argument.
62
+
63
+
For example, to get help with the `ollama` command, run:
Next, you'll have to start the ollama server. Before you do this, you'll need to find an open port to use. You can do this with the `random-port` command embedded in this container:
69
+
You can start an interactive prompt with the following command:
48
70
49
71
```bash
50
-
export OLLAMA_PORT="$(apptainer run ollama.sif random-port)"
72
+
apptainer run instance://ollama-$USER ollama run qwen:0.5b
51
73
```
52
74
75
+
Or provide the prompt on the command line and return JSON output non-interactively:
76
+
53
77
```bash
54
-
# Start the ollama server (make sure you include the `&` at the end to run it in the background):
55
-
apptainer run ollama.sif serve &
78
+
# NOTE: Not all models support JSON output
79
+
# NOTE: Wrap the prompt in single quotes to avoid issues with special characters
80
+
apptainer run instance://ollama-$USER ollama run qwen:0.5b --format=json --prompt 'Who are you?'
81
+
```
56
82
57
-
# Wait a few seconds for the server to start up:
58
-
sleep 5
83
+
For other models, you can replace `qwen:0.5b` with the name of the model you want to use. You can find a list of available models [here](https://ollama.ai/library).
84
+
85
+
To show the models on the server, run:
86
+
87
+
```bash
88
+
apptainer run instance://ollama-$USER ollama list
59
89
```
60
90
61
-
Once the server is running, you can start an interactive prompt with the following command:
91
+
To show the currently running models, run:
62
92
63
93
```bash
64
-
# Start an interactive prompt with the qwen:0.5b model:
65
-
apptainer run ollama.sif run qwen:0.5b
94
+
apptainer run instance://ollama-$USER ollama ps
66
95
```
67
96
68
-
For other models, you can replace `qwen:0.5b` with the name of the model you want to use. You can find a list of available models [here](https://ollama.ai/library).
97
+
To stop the server, run:
69
98
70
-
To list available models, try:
99
+
```bash
100
+
apptainer instance stop ollama-$USER
101
+
```
102
+
103
+
See the [documentation](https://github.com/ollama/ollama) for more information on how to use `ollama`.
104
+
105
+
#### Listing available models and tags
106
+
107
+
This repository includes a custom command to list available models and tags at (https://ollama.com/library). This command is not part of the `ollama` package and is only available in this container. It is useful for finding the names of models and tags to use with the `ollama` command, but it is not guaranteed to work in the future.
108
+
109
+
To list available models, try the following command with a running instance:
71
110
72
111
```bash
73
-
apptainer run ollama.sif available
112
+
apptainer run instance://ollama-$USER available-models
74
113
```
75
114
76
115
To list available tags for a model, try:
77
116
78
117
```bash
79
118
# Replace `qwen` with the name of the model you want to check:
80
-
apptainer run ollama.sif availabletags qwen
119
+
apptainer run instance://ollama-$USER available-tags qwen
81
120
```
82
-
83
-
See the [documentation](https://github.com/ollama/ollama) for more information on how to use `ollama`.
0 commit comments