From 5827503c82c7f3490a48401d6bcf1482a95c23e2 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Fri, 29 Mar 2024 19:42:33 -0400 Subject: [PATCH 1/2] feat: Add a ujust action to install ollama quadlet --- just/bluefin-tools.just | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/just/bluefin-tools.just b/just/bluefin-tools.just index 4dcc85bc759..ee6ed3a782f 100644 --- a/just/bluefin-tools.just +++ b/just/bluefin-tools.just @@ -28,3 +28,75 @@ tensorflow: # Run the yafti setup tool yafti: yafti /etc/yafti.yml --force + +# Setup a local Ollama instance in a container. +# Detect hardware, offer a choice if needed. +ollama: + #!/usr/bin/env bash + echo 'Follow the prompts and check the tutorial: ' + echo + GPU_CHOICES=() + # Detect nvidia drivers + if which nvidia-smi > /dev/null 2>&1; then + GPU_CHOICES+=("Nvidia (CUDA)") + fi + # Detect radeon hardware + if lspci | grep ' VGA ' | grep -sq Radeon; then + GPU_CHOICES+=("AMD (ROCm)") + fi + GPU_SELECTION=$(printf '%s\n' "${GPU_CHOICES[@]}" | gum choose --select-if-one --header "Select the type of graphics card you have") + echo "Selected ${GPU_SELECTION}!" + case "$GPU_SELECTION" in + "Nvidia (CUDA)") + IMAGE=latest + CUSTOM_ARGS="AddDevice=nvidia.com/gpu=all" + ;; + + "AMD (ROCm)") + IMAGE=rocm + read -r -d '' CUSTOM_ARGS <<-'EOF' + AddDevice=/dev/dri + AddDevice=/dev/kfd + EOF + ;; + esac + + read -r -d '' QUADLET <<-EOF + [Unit] + Description=The Ollama container + After=local-fs.target + + [Service] + Restart=always + TimeoutStartSec=60 + # Ensure there's a userland podman.sock + ExecStartPre=/bin/systemctl --user enable podman.socket + + [Container] + ContainerName=ollama + PublishPort=11434:11434 + RemapUsers=keep-id + RunInit=yes + NoNewPrivileges=no + Volume=%h/.ollama:/.ollama + PodmanArgs=--userns=keep-id + PodmanArgs=--group-add=keep-groups + PodmanArgs=--ulimit=host + PodmanArgs=--security-opt=label=disable + PodmanArgs=--cgroupns=host + + Image=docker.io/ollama/ollama:${IMAGE} + ${CUSTOM_ARGS} + + [Install] + RequiredBy=default.target + EOF + if [ ! -f ~/.config/containers/systemd/ollama.container ]; then + mkdir -p ~/.config/containers/systemd + echo "${QUADLET}" > ~/.config/containers/systemd/ollama.container + else + echo "Ollama container already exists, skipping..." + fi + systemctl --user daemon-reload + systemctl --user start ollama.service + echo "Please install the ollama cli via \`brew install ollama\`" From d2d82c4e7e6f769c248193d50e13fb97b1dab7a2 Mon Sep 17 00:00:00 2001 From: Robert Sturla Date: Sun, 7 Apr 2024 23:03:31 +0100 Subject: [PATCH 2/2] More justfile comment to single line to try and please linter --- just/bluefin-tools.just | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/just/bluefin-tools.just b/just/bluefin-tools.just index a2fc33854b0..70f4ccbfab1 100644 --- a/just/bluefin-tools.just +++ b/just/bluefin-tools.just @@ -25,8 +25,7 @@ tensorflow: podman pull docker.io/tensorflow/tensorflow:latest podman run -it -p 8888:8888 docker.io/tensorflow/tensorflow:latest-jupyter # Start Jupyter server -# Setup a local Ollama instance in a container. -# Detect hardware, offer a choice if needed. +# Setup a local Ollama instance in a container. Detect hardware, offer a choice if needed. ollama: #!/usr/bin/env bash echo 'Follow the prompts and check the tutorial: '