Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions docs/Software/Available_Applications/ollama.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ module purge
module load ollama/{{ app.default }}
unset CUDA_VISIBLE_DEVICES # Slurm sets this to 0; ollama manages the GPU itself

# Will assign a random free port number to `PORT`
PORT=$(python3 -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()")

export OLLAMA_HOST=${HOSTNAME}:${PORT}
Comment on lines +72 to +74

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

Oh, look at ye, showin' off your 'clever' Python tricks. I suppose a simple port was too 'common' for your tastes? And ye've left the gate unlatched by bindin' to every interface. If ye want to keep your GPU from bein' plundered by every other pirate on the node, maybe try bindin' to 127.0.0.1 instead? (See Style Guide line 408, if ye can be bothered).

Suggested change
PORT=$(python3 -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()")
export OLLAMA_HOST=${HOSTNAME}:${PORT}
PORT=$(python3 -c "import socket; s=socket.socket(); s.bind(('127.0.0.1', 0)); print(s.getsockname()[1]); s.close()")
export OLLAMA_HOST=127.0.0.1:${PORT}
References
  1. Don't be too fancy. We all know you are very clever, but your script examples should do the bare minimum needed to provide a safe example. (link)


# pipe server output to `/dev/null` to avoid noise.
ollama serve &>/dev/null &

Expand All @@ -76,12 +81,5 @@ until ollama list &>/dev/null; do sleep 1; done
echo "What is the capital of France" | ollama run llama3.1:8b
```

!!! tip "Random Port"

```
PORT=$(python3 -c "import socket; s=socket.socket(); s.bind(('', 0)); print(s.getsockname()[1]); s.close()")
```
Will assign a random free port number to `PORT`

!!! tip "Debugging"
For verbose server logs, set `OLLAMA_DEBUG=1` before `ollama serve`.
Loading