Background
I have a lab server with 2 NVIDIA Telsla P40 cards to run LLMs locally. More on this under the Local LLMs tag. Ollama makes it super easy to install and install and switch between models IMO making it a great backend for OpenWebUI. As I continued to think about Hermes and OpenClaw, I really wanted to have a consistent response time for the agent framework (Heremes, OpenClaw) when it needs to call the api for the model. The biggest obstacles are the loading of the model, and how well the model runs on the P40. There is a way to pre-load a model using Ollama which I details in a previous post. But I wanted to go a different to get more control over model choice and execution while minimizing the overhead, even the small amount introduced by Ollama.
Choosing the Inference Engine
First a couple quick definitions
- Inference – The process of an AI using its existing knowledge to calculate an answer to your specific prompt ex. ask it a question
- Inference Engine – Software that runs a model to perform the heavy calculations needed to turn the AI’s data into readable text
There are a few commonly used inference engines in the open source space
- Ollama
- Llama.cpp
- VLLM
- Aphrodite
VLLM is popular for deployments where parallel request are being processed and also includes the latest software features for efficiency. However, VLLM won’t run on the NVIDIA P40 because the architecture is too old. Aphrodite was created for this situation. Aphrodite is basically a VLLM backported to work on older architecture. However, after many configuration iterations it still would not run the model I chose. It turns out that this was not entirely the fault of on the P40 architecture or Aphrodite (which did initiate). The problem was that the Aphrodite engine does not support Qwen3, which the model I chose to run for it’s ability to reason and speed. Having validated this is not resolvable I pivoted to Llama.cpp.
Llama.cpp is the back end of Ollama. Ollama is essentially a managed version of Llama.cpp and I can get some more direct configuration choices running Llama.cpp directly. Instead of choosing a model from the Ollama site, I did some research on what model would run well on my P40 and qwen3.8-multimodal was the winner, and I am not disappointed.
Choosing the model
Hugging Face has become the standard central repository for downloadable models. Many are open source but whether an AI model is open source is a different nuanced discussion. Hugging Face was super confusing when I went to download the model I wanted, so here is the foundational knowledge to get going.
Naming Convention
The below is the standard naming convention, some or all descriptors may be used.
[The Packager] / [The Modder] _ [The Base Model] - [The Size] - [The Mods] - [The Format]
- The Packager
- Downloaded and compressed the model into a package like .gguf
- The Modder
- Developers or companies that have modified the AI’s brain
- orcarouter_: This user took the official Qwen 3.8 model and ran it through a fine-tuning process to strip away all corporate safety filters (Uncensored)
- ukisai_Swift-: This developer took the Qwen model and likely force-fed it thousands of textbooks and GitHub repositories specifically related to Apple’s Swift programming language
- JetBrains-…-blend: This is a “Model Merge.” Someone took the brain of an older model and mathematically smashed it together with the new model using data from JetBrains
- Developers or companies that have modified the AI’s brain
- The Base Model
- The raw foundation model that has read the entire internet, but has not been trained to be an assistant.
- The Size
- This is the size in parameters. Parameters are the adjustable settings within a model that it learns to make predictions. The same model can be available with different parameter counts. Lower parameters can effect the quality of the output of the model. ~30B is considered the min size if you want the model to use reasoning as a core function of the output.
- The Mods
- There are multiple types of mods, this isn’t a prefect categorization as some mods will fit in multiple categories, but as a guideline is it enough to understand what is trying to be conveyed by the filename.
- Instruction Tuning improves the model’s ability to understand and respond
- Instruct
- Coder
- MoE (Mixture of Experts) is made of eight smaller brains that hand tasks off to each other
- Capability Augmentation adds new abilities or enhances existing ones
- Web browser plugin
- Enhanced reasoning
- Efficiency mods reduce the model size and optimize performance
- Quanta
- Q4_K_M (The Golden Standard): This compresses the model to 4-bit precision. It is widely considered the perfect balance losing near zero intelligence
- 4 (4-Bit / INT4): The baseline target size for the weights is 4 bits
- K (K-Quants): Developed by the llama.cpp team, “K-Quants” is a smart, variable-bitrate compression method
- M (Medium): This denotes the size variant of the K-quant
- Q4_K_M (The Golden Standard): This compresses the model to 4-bit precision. It is widely considered the perfect balance losing near zero intelligence
- Pruning techniques
- Quanta
- Style/Tone change the model’s output style
- Formal
- Informal
- Creative
- Technical
- Instruction Tuning improves the model’s ability to understand and respond
- There are multiple types of mods, this isn’t a prefect categorization as some mods will fit in multiple categories, but as a guideline is it enough to understand what is trying to be conveyed by the filename.
- The Format
- The process of training a model results in a vast matrix of numerical values which are the model’s learned parameters. The community converts this matrix into optimized file formats tailored to the specific software used for inference and deployment. The format you want depends on the inference engine you are using.
- Safetensors (.safetensors)
- GGUF (.gguf)
- The process of training a model results in a vast matrix of numerical values which are the model’s learned parameters. The community converts this matrix into optimized file formats tailored to the specific software used for inference and deployment. The format you want depends on the inference engine you are using.
Find and Download
The best practice is to search using the below format.
[Model Name] [Size / Parameters] [Format] [The Packager]
When choosing a model this first thing to know is what you want it to do. A search or conversation with AI can help narrow down the recommended models and reliable packagers. I went with the top one and gguf since I am using gguf. Base model developers put their models here too, but unless you are running massive GPU it’s not realistic to run it directly. It’s still useful to see what the latest releases, then go get a packaged one.
Running the Model
To effectively run a model the entire model needs to be loaded into GPU ram. It can be split between the GPU ram on multiple cards but that’s less efficient because the cards need to communicate with each other. Additionally there needs to be left over ram for a context buffer.
I’m pretty security first when it comes to AI so I created a new user on my server to run llama.cpp, and run it in a rootless container using podman. The GPU is transparent to the container (requires nvidia-container-toolkit) so there is no performance hit. Then, I enabled linger for the user, and created a systemd unit that runs as the new user which I creatively named llama.
Create User
# Create the dedicated user and set its home directory
sudo useradd -r -m -d /opt/llama.cpp -s /bin/bash llama
# Add the user to video/render groups for GPU device access
sudo usermod -aG video,render llama
# Pre-create model and rootless Podman storage folders
sudo mkdir -p /opt/llama.cpp/models /opt/llama.cpp/.local /opt/llama.cpp/.config /opt/llama.cpp/.cache
sudo chown -R llama:llama /opt/llama.cpp
Enable Linger
# Allow the llama user to run persistent background services
sudo loginctl enable-linger llama
# Initialize rootless user namespaces for Podman
sudo -i -u llama podman system migrate
Create systemd unit
[Unit]
Description=Llama.cpp Dedicated Engine
After=network.target nvidia-persistenced.service
Wants=nvidia-persistenced.service
[Service]
User=llama
Group=llama
WorkingDirectory=/opt/llama.cpp
TimeoutStartSec=600
Environment="MODEL_FILE=Qwen3.8-27B-Q4_K_M.gguf"
Environment="MM_PROJECTOR=mmproj-Qwen3.8-27B-f16.gguf"
Environment="MODEL_ALIAS=qwen-3.8-27b"
ExecStartPre=-/usr/bin/podman rm -f llama-server
ExecStart=/usr/bin/podman run --name llama-server \
--rm \
--device nvidia.com/gpu=0 \
--security-opt label=disable \
-p 0.0.0.0:11435:8080 \
-v /opt/llama.cpp/models:/models:Z \
ghcr.io/ggml-org/llama.cpp:server-cuda \
-m /models/${MODEL_FILE} \
--mmproj /models/${MM_PROJECTOR} \
--reasoning-budget 2048 \
-c 32768 \
-ctk q8_0 \
-ctv q8_0 \
--parallel 1 \
-ngl 99 \
--alias ${MODEL_ALIAS}
ExecStop=/usr/bin/podman stop llama-server
Restart=always
[Install]
WantedBy=multi-user.target
The systemd unit contains the llama-server command so the correct command needs to be constructed.
--device nvidia.com/gpu=0:- Uses the Container Device Interface (CDI) to pass exclusively GPU 0 into the container. I dedicate 1 GPU card to this service.
--security-opt label=disable&:Z:- On SELinux-enforcing systems (RHEL/Fedora/Rocky), rootless containers are blocked from accessing host character devices (
/dev/nvidia*). Disabling SELinux labeling for the container allows CUDA device access, while:Zrelabels the/opt/llama.cpp/modelsmount for private container read access.
- On SELinux-enforcing systems (RHEL/Fedora/Rocky), rootless containers are blocked from accessing host character devices (
-p 0.0.0.0:11435:8080:- Binds the container’s internal port
8080to all IPv4 host interfaces (0.0.0.0) on port11435. Binding to0.0.0.0ensures external clients on your LAN (such as an OpenWebUI VM or IDE agents) can reach the API without hitting127.0.0.1container loopback isolation.
- Binds the container’s internal port
-m ...Q4_K_M.gguf- Model file
--mmproj ...f16.gguf- Multimodal Vision Projectorz: Loads the CLIP vision encoder alongside the LLM, enabling image ingestion and screenshot analysis
-ngl 99(Full GPU Offload)- Instructs
llama.cppto offload up to 99 transformer layers to the GPU
- Instructs
-c 32768- 32K Context Window Size
- Sets the maximum active working memory (prompt + conversation history + generated tokens) to 32,768 tokens (~24,000 words).
- After loading the 27B weights (~17.0 GB), the vision projector (~1.0 GB), and CUDA compute buffers (~1.1 GB), is 19.1GB out of my 24 GB VRAM
- A
32768(32K) context window comfortably holds large code files, documentation, and multi-turn agent histories while leaving safe VRAM headroom.
-ctk q8_0and-ctv q8_0- 8-Bit KV Cache Quantization
-fa- Flash Attention is omitted because my Tesla P40 does not support Flash Attention.
- Modern GPUs (Ampere/RTX 3000+) use
-fato compute attention in tiles without materializing the full attention matrix in VRAM. - Hence,
llama-servermust allocate standard KV Cache memory linearly on my Tesla P40
Reload and start service
sudo systemctl daemon-reload
sudo systemctl enable --now llama-server
Test the API
This curl command, if successful, will return a bash script. Replace localhost with the server IP if run from a remote workstation.
curl http://localhost:11435/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "Write a bash script to backup a directory."}
]
}'



Leave a Reply