tutorial
offline-llm
usb-deployment
edge-ai
quantization
Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan
| Item | Minimum Spec |
|---|---|
| Host OS | Windows 10+, macOS 12+, Linux (kernel 5.4+) |
| CPU | x86_64 with AVX2 (or ARMv8 with NEON) |
| RAM | 8 GB (16 GB recommended) |
| USB | USB‑3.0 flash drive, at least 16 GB free space |
| Tools | %%INLINECODE_0%%, %%INLINECODE_1%%, %%INLINECODE_2%%/%%INLINECODE_3%%, Python 3.9+ |
llama.cpp which supports GGML‑format models and 4‑bit/8‑bit quantization.bash# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# Build with AVX2 support
make LLAMA_AVX2=1
# Convert the original HuggingFace checkpoint to GGML format (4‑bit)
python3 convert_hf_to_ggml.py \
--model_dir /path/to/llama-2-7b-chat \
--outfile models/llama-2-7b-chat-q4.ggmlv3.bin \
--type q4_0
The resulting *.ggmlv3.bin file is ready for offline execution.
LLM-USB. LLM-USB/
├─ models/
│ └─ llama-2-7b-chat-q4.ggmlv3.bin
├─ scripts/
│ └─ run_llm.sh
└─ README.md
llama.cpp binary (./main) into scripts/.stdin and prints the model’s response.bash#!/usr/bin/env bash
# scripts/run_llm.sh
MODEL_PATH="$(dirname "$0")/../models/llama-2-7b-chat-q4.ggmlv3.bin"
if [[ ! -f "$MODEL_PATH" ]]; then
echo "Model not found at $MODEL_PATH"
exit 1
fi
./main \
-m "$MODEL_PATH" \
-p "$*" \
-n 128 \
-ctx 2048 \
-temp 0.7
chmod +x scripts/run_llm.sh).Usage example (on the host machine):
bash$ /media/usb/LLM-USB/scripts/run_llm.sh "Explain quantum tunneling in two sentences."
| Parameter | Effect |
|---|---|
| %%INLINECODE_12%% (tokens) |
Controls output length. Lower values reduce latency.
| -temp (temperature) | Adjusts randomness; 0.0 = deterministic.
| -ctx (context size) | Larger context consumes more RAM. Keep ≤ 2048 for 8 GB RAM.
| -ngl (GPU layers) | If the host has a supported GPU, add -ngl 16 to offload 16 layers.
Experiment with -ngl on laptops with an NVIDIA GPU and the llama.cpp CUDA build.
docker run --rm -v /mnt/usb:/data alpine:latest /data/scripts/run_llm.sh …).llama.cpp, you can achieve offline, privacy‑preserving AI on virtually any laptop or edge device.Feel free to fork the repository, experiment with other models, and share your own USB‑LLM projects!