Downloads · 30 days
22
11% of all-time downloads
sitsope/phi-3-mini-4k-instruct-q4
phi-3-mini-4k-instruct-q4 is a machine learning model from sitsope. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Deploy a small, low‑cost LLM with 4‑bit quantization + RAG, exposed via a clean FastAPI service that can run on CPU‑only servers (e.g., Azure Container Instances).
Downloads · 30 days
22
11% of all-time downloads
All-time downloads
204
Public
Repo size
2.4 GB
Likes
1
Public
Click a slice to open those files.
.gguf4.8 GB · 100%
From the Hugging Face model README
Deploy a small, low‑cost LLM with 4‑bit quantization + RAG, exposed via a clean FastAPI service that can run on CPU‑only servers (e.g., Azure Container Instances).
FastAPI API serving a 4‑bit GGUF LLM with a lightweight FAISS RAG pipeline. Designed for low‑cost CPU servers (Azure Container Instances) and local Mac testing.
llama-cpp-python)app/
main.py # FastAPI app
rag.py # FAISS utilities
ingest.py # build index from public sources
settings.py # config via env
scripts/
download_model.py
Dockerfile
requirements.txt
python3.12 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
# Download 4-bit Phi-3 GGUF
python scripts/download_model.py \
--repo microsoft/Phi-3-mini-4k-instruct-gguf \
--filename Phi-3-mini-4k-instruct-q4.gguf \
--out models
# Build FAISS index from public pages
python -m app.ingest --pages "Large_language_model,Azure,Quantization_(signal_processing)" --lang en
# Run API
export MODEL_PATH="models/Phi-3-mini-4k-instruct-q4.gguf"
export N_GPU_LAYERS="-1" # Metal offload on Mac
uvicorn app.main:app --host 0.0.0.0 --port 8000
Test:
curl http://localhost:8000/health
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"question":"What is quantization in signal processing?"}'
Build:
docker build -t quant-llm .
Run:
docker run --rm -p 8000:8000 \
-e MODEL_PATH=/models/Phi-3-mini-4k-instruct-q4.gguf \
-v "$PWD/models:/models" \
quant-llm
az group create -n rg-quant-llm -l westeurope
az acr create -n acrquantllm -g rg-quant-llm --sku Basic
az acr login -n acrquantllm
az acr build -t quant-llm:1 -r acrquantllm .
az container create \
-g rg-quant-llm \
-n quant-llm-api \
--image acrquantllm.azurecr.io/quant-llm:1 \
--registry-login-server acrquantllm.azurecr.io \
--registry-username <ACR_USERNAME> \
--registry-password <ACR_PASSWORD> \
--cpu 2 --memory 6 \
--ports 8000 \
--environment-variables MODEL_PATH=/models/Phi-3-mini-4k-instruct-q4.gguf N_THREADS=2 N_GPU_LAYERS=0 \
--command-line "bash -lc 'python scripts/download_model.py --repo microsoft/Phi-3-mini-4k-instruct-gguf --filename Phi-3-mini-4k-instruct-q4.gguf --out /models && uvicorn app.main:app --host 0.0.0.0 --port 8000'"
az container show -g rg-quant-llm -n quant-llm-api --query ipAddress.ip -o tsv
Environment variables in app/settings.py:
MODEL_PATH (default: models/phi-3-mini-4k-instruct-q4.gguf)N_CTX (default: 4096)N_THREADS (default: 8)N_GPU_LAYERS (default: 0, use -1 on Mac for Metal)RAG_TOP_K (default: 4)app/ingest.py to your own docs.See CONTRIBUTING.md.
MIT. See LICENSE.