Skip to main content

๐Ÿš€ 7 Ways to Run Any LLMs Locally - Simple Methods

Published 7 min readMarkdown
๐Ÿš€ 7 Ways to Run Any LLMs Locally - Simple Methods

A comprehensive guide to running Large Language Models (LLMs) locally on your machine using various tools and platforms.

๐ŸŽฌ Video Demonstration

Watch on Youtube


1. ๐Ÿฆ™ Ollama - The Dominant Local LLM Ecosystem

Ollama is the dominant ecosystem for running LLMs such as Llama 4, Mistral 3, and Gemma 3 locally. Additionally, multiple applications accept an Ollama integration, which makes it an excellent tool for faster and easier access to language models on our local machine.

Ollama now offers full OpenAI API compatibility, making it a drop-in replacement for OpenAI's cloud service. Recent features include function calling, structured JSON output, Flash Attention for vision models, and 30% faster inference on Apple Silicon and AMD GPUs.

๐Ÿ”— Resources

Ollama (+ OpenWebUI)

  • ๐ŸŽฅ Deploy ANY Open-Source LLM with Ollama on Linux - 100% Local Solution: Watch Tutorial

  • ๐ŸŽฅ Install Open Web-UI using Docker on Ubuntu: Watch Tutorial

  • ๐ŸŽฅ Ollama with VSCode - AI Coding Assistant (Llama Copilot): Watch Tutorial


2. โšก llama.cpp - High-Performance C++ Inference Engine

llama.cpp is a lightweight, high-performance inference engine written in C++ for running LLMs efficiently. It supports GGUF format models and offers hardware-optimized configurations for CPU, NVIDIA GPUs (CUDA), AMD GPUs (ROCm), and Moore Threads GPUs (MUSA).

๐Ÿณ Hosting llama-server with Docker

Organizations using container-based deployments can leverage Docker images optimized for various hardware configurations. NVIDIA GPU acceleration requires the NVIDIA Container Toolkit.

llama.cpp supports GGUF file format models commonly hosted on Hugging Face Hugging Face.

๐Ÿ“‹ Quick Start with Docker

docker run -p 8080:8080 -v /path/to/models:/models --gpus all \
    ghcr.io/ggml-org/llama.cpp:server-cuda -m models/phi-4.Q4_K_M.gguf \
    --host 0.0.0.0 --port 8080 --n-gpu-layers 999

๐Ÿ“š Documentation

๐Ÿ”ง Docker Compose Example (CPU + GPU Hybrid Mode)

Note: The same compose file works with CPU only, CPU + GPU, or GPU only. Just change the image name and GPU_LAYERS variable:

  • 0 for CPU only

  • 2 for CPU + GPU hybrid

  • 999 for GPU only

Go on deploy path

cd /HDD2TB/iansari/deploy_llm/cuda

Create compose.yaml file

services:
  llama:
    image: ghcr.io/ggml-org/llama.cpp:full-cuda
    container_name: llama
    ports:
      - "8000:8000"
    volumes:
      - ./models:/models
      - ./entrypoint.sh:/entrypoint.sh
    entrypoint: ["/entrypoint.sh"]
    stdin_open: true
    tty: true

    # ๐Ÿ”ฅ GPU ENABLED  | CPU + GPU HYBRID | GPU ONLY | Comment this if GPU not required.
    runtime: nvidia
    environment:
      NVIDIA_VISIBLE_DEVICES: all
      NVIDIA_DRIVER_CAPABILITIES: compute,utility
      GPU_LAYERS: 2
      CTX: 1024
      PORT: 8000

    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

๐ŸŽฎ Dedicated GPU Configuration

Docker containers can be configured to run llama-server on specific GPUs by GPU index:

- driver: nvidia
  device_ids: ['0'] # Assign to GPU 0
  capabilities: [gpu]

๐Ÿ“ Entrypoint Script

Note: Become Linux command line Expert Linux Commands for Cloud and DevOps

Create entrypoint.sh file

#!/usr/bin/env bash
set -e
# Enable it for debug | Keep the container running for debug | Get all information about commands.
# sleep infinity # <--- Debug enable it.
# docker exec -it llama /bin/bash
# ls -alsh /models
# ls -alsh /app
# ./llama-cli --help
# ./llama-server --help

#MODEL_PATH=${MODEL_PATH:-/models/llama-2-7b-chat.Q4_K_M.gguf}
MODEL_PATH=${MODEL_PATH:-/models/GLM-4.7-Flash-Q3_K_S.gguf}
PORT=${PORT:-8000}
THREADS=${THREADS:-$(nproc)}
CTX=${CTX:-1024}
GPU_LAYERS=${GPU_LAYERS:-0}

if [ ! -f "$MODEL_PATH" ]; then
  echo "โŒ Model not found at $MODEL_PATH"
  exit 1
fi

echo "๐Ÿš€ Starting llama.cpp server (CUDA)"
echo "๐Ÿ“ฆ Model: $MODEL_PATH"
echo "๐Ÿง  Context: $CTX"
echo "๐Ÿงต Threads: $THREADS"
echo "๐ŸŽฎ GPU layers: $GPU_LAYERS"

exec /app/llama-server \
  -m "$MODEL_PATH" \
  -c "$CTX" \
  -t "$THREADS" \
  -ngl "$GPU_LAYERS" \
  --host 0.0.0.0 \
  --port "$PORT"

๐Ÿ“ฅ Download Models (GGUF Format)

Download any Available Models an use it:

Download Example:

wget -P models \
https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf

wget -P models \
https://huggingface.co/unsloth/GLM-4.7-Flash-GGUF/resolve/main/GLM-4.7-Flash-Q3_K_S.gguf

ls -alsh models 
tree
.
โ”œโ”€โ”€ compose.yaml
โ”œโ”€โ”€ entrypoint.sh
โ””โ”€โ”€ models
    โ”œโ”€โ”€ GLM-4.7-Flash-Q3_K_S.gguf
    โ””โ”€โ”€ llama-2-7b-chat.Q4_K_M.gguf

2 directories, 4 files

๐Ÿš€ Deployment Steps

chmod +x entrypoint.sh
docker compose up -d

โœ… Note: Docker Compose environment variables always override the entrypoint.sh script defaults.

Check variables:

docker exec -it llama env
docker exec -it llama env | grep GPU_LAYERS

๐Ÿงช Testing the API

List Models:

curl http://localhost:8000/v1/models | jq

Chat Completion:

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "local",
    "messages": [
      {"role": "user", "content": "Explain AI in simple words"}
    ]
  }'

Check GPU usage using nvtop

apt update -y
apt install nvtop
nvtop

3. ๐Ÿ–ฅ๏ธ LM Studio - All-in-One Local LLM Workbench

LM Studio is an all-in-one desktop workbench for running LLMs locally with native fine-tuning support. It features multiple concurrent model loading, speculative decoding (1.5x-3x faster tokens), and document RAG integration for enhanced local AI workflows.

๐Ÿ”— Resources

โœจ Key Features

  • ๐ŸŽฏ User-friendly GUI interface

  • ๐Ÿ”„ Multiple concurrent models

  • โšก Speculative decoding for faster inference

  • ๐Ÿ“„ Document RAG integration

  • ๐ŸŽจ Native fine-tuning capabilities


4. ๐Ÿš„ vLLM - Production-Scale Inference Engine

vLLM is an open-source inference engine designed for running LLMs at production scale. Unlike Ollama or LM Studio, vLLM prioritizes throughput and latency optimization for multi-user scenarios, making it ideal for serving models in production environments.

๐Ÿ”— Resources

๐Ÿš€ Quick Start

Installation:

python3.11 -m venv vllm_env
source vllm_env/bin/activate
pip install vllm

Start OpenAI-Compatible Server:

vllm serve meta-llama/Llama-2-7b-hf --port 8000 --gpu-memory-utilization 0.9

For 70B Models on Multiple GPUs:

vllm serve meta-llama/Llama-2-70b-hf --tensor-parallel-size 2 --port 8000

Batch Processing Example:

from vllm import LLM, SamplingParams

llm = LLM(model="meta-llama/Llama-2-7b-hf", dtype="bfloat16")
sampling_params = SamplingParams(temperature=0.8, max_tokens=256)
outputs = llm.generate(["Write hello world", "Explain AI"], sampling_params)

5. ๐ŸŽจ Jan - Privacy-First ChatGPT Alternative

Jan is one of the most popular and aesthetically pleasing local LLM applications. It serves as a privacy-first alternative to ChatGPT, offering a beautiful user interface while keeping all your data local.

๐Ÿ”— Resources

โœจ Key Features

  • ๐Ÿ”’ 100% privacy-focused

  • ๐Ÿ’Ž Beautiful, modern UI

  • ๐Ÿ–ฅ๏ธ Cross-platform desktop app

  • ๐ŸŽฏ ChatGPT-like experience, locally


6. ๐ŸŒŸ GPT4All - Free Open-Source LLM Ecosystem

GPT4All is a free, open-source ecosystem for running local LLMs. It includes a user-friendly desktop application, a comprehensive Python API, and a curated collection of models optimized for consumer-grade hardware.

๐Ÿ”— Resources

โœจ Key Features

  • ๐Ÿ–ฅ๏ธ Desktop application for Windows, macOS, and Linux

  • ๐Ÿ Python API for integration

  • ๐Ÿ’ป Optimized for consumer hardware

  • ๐Ÿ“š Curated model collection

  • ๐Ÿ†“ Completely free and open-source


7. ๐Ÿ“ฆ llamafile - Single-Binary LLM Runtime

llamafile is a revolutionary single-file binary that packages an LLM with its complete runtime environment. This makes running models locally incredibly simpleโ€”no complex dependencies, no installation hassles, just download and execute.

๐Ÿ”— Resources

โœจ Key Features

  • ๐Ÿ“ฆ Single executable file

  • ๐Ÿ”ง Zero installation required

  • ๐ŸŒ OpenAI-compatible API endpoints

  • ๐Ÿ’ป Multi-architecture support

  • โšก Quick start in minutes

๐Ÿš€ Quick Start

Download and run your first llamafile in minutes:

# Download an example model (LLaVA 1.5 7B)
curl -LO https://huggingface.co/Mozilla/llava-v1.5-7b-llamafile/resolve/main/llava-v1.5-7b-q4.llamafile

# Make it executable (macOS/Linux/BSD)
chmod +x llava-v1.5-7b-q4.llamafile

# Run it (opens browser automatically)
./llava-v1.5-7b-q4.llamafile

๐ŸŽฏ Conclusion

Each of these methods offers unique advantages for running LLMs locally. Choose based on your specific needs:

  • ๐Ÿฆ™ Ollama: Best for general use with broad ecosystem support

  • โšก llama.cpp: Ideal for performance-critical deployments

  • ๐Ÿ–ฅ๏ธ LM Studio: Perfect for users wanting a complete GUI workbench

  • ๐Ÿš„ vLLM: Optimal for production-scale multi-user scenarios

  • ๐ŸŽจ Jan: Great for privacy-conscious users wanting a ChatGPT-like experience

  • ๐ŸŒŸ GPT4All: Excellent for beginners on consumer hardware

  • ๐Ÿ“ฆ llamafile: Best for quick, no-installation deployments


๐Ÿ“ License

This guide is provided as-is for educational and professional use.

๐Ÿค Contributing

Feel free to suggest improvements or report issues via pull requests or the issues tab.

๐Ÿ’ผ Connect with Me ๐Ÿ‘‡๐Ÿ˜Š

โญ If You Found This Helpful...

Please star the repo and share it! Thanks a lot! ๐ŸŒŸ

About the author

  • Hello! I'm a DevOps Engineer dedicated to continuous learning and contributing to the tech community. If you find value in what I share, feel free to spread the word to others who might benefit as well. Your support is greatly appreciated!

No comments yet. Be the first to comment.

More from this blog