Published
Running LLMs on Your Own Infrastructure: Quantization, Edge Inference and Data Privacy
Run open-weights LLMs on your own servers: quantization (INT8, INT4, GPTQ, AWQ, GGUF), edge inference and hybrid setups that keep sensitive data in-house.
- Written by
- Ali ÖzdurmuşFounder, Veni AI
- Updated
- Reading time
- 6 min read

Many companies want AI on data that should not leave the building: customer records, health data, contracts, production recipes. Running an open-weights model on your own servers, or even on a device in the field, solves that, but only if the model fits the hardware. Quantization is what makes it fit.
This guide covers why teams self-host, how quantization works, which formats and tools to use, and how to combine local and cloud inference.
Why Run Models Yourself
- Data stays in-house. Easier to meet KVKK, GDPR and sector rules, and to answer customer security questionnaires.
- Predictable cost for high-volume, repetitive tasks once hardware is in place.
- Low latency for factory floors, retail stores or field teams.
- Offline resilience where connectivity is weak.
The trade-off: you operate the hardware, the serving stack and the updates. For many companies the right answer is hybrid: sensitive or high-volume tasks on local models, complex reasoning on hosted frontier models.
Quantization Basics
Quantization stores model weights (and sometimes activations) in lower-precision formats.
| Format | Bits per parameter | Size of a 7B model (weights) |
|---|---|---|
| FP32 | 32 | ~28 GB |
| FP16 / BF16 | 16 | ~14 GB |
| INT8 | 8 | ~7 GB |
| INT4 | 4 | ~3.5 GB |
Smaller weights mean less memory and, in most memory-bound inference setups, faster generation. The cost is some loss of quality, which you must measure on your own tasks.
Number formats
FP32: 1 sign + 8 exponent + 23 mantissa bits
FP16: 1 sign + 5 exponent + 10 mantissa bits
BF16: 1 sign + 8 exponent + 7 mantissa bits
INT8: integer, -128 to 127
INT4: integer, -8 to 7Post-Training Quantization (PTQ)
Quantize a trained model without retraining. The core idea fits in a few lines:
import torch
def quantize_tensor(tensor, bits=8):
min_val, max_val = tensor.min(), tensor.max()
scale = (max_val - min_val) / (2**bits - 1)
zero_point = torch.round(-min_val / scale)
q = torch.clamp(torch.round(tensor / scale + zero_point), 0, 2**bits - 1)
return q.to(torch.uint8), scale, zero_point
def dequantize_tensor(q, scale, zero_point):
return (q.float() - zero_point) * scaleQuantization-Aware Training (QAT)
Simulates quantization during training so the model learns to tolerate it. Better quality at very low bit widths, but it requires a training run.
GPTQ
Quantizes layer by layer and compensates the error of each quantized weight by adjusting the remaining ones, using calibration data.
For each layer:
1. Estimate which weights matter most (second-order information)
2. Quantize weights column by column
3. Adjust the remaining weights to compensate the error
Group quantization: one scale factor per group of 128 weightsAWQ (Activation-aware Weight Quantization)
Protects the small share of weights that matter most for typical activations, then quantizes the rest. Often a very good quality/speed balance at 4 bits on GPUs.
BitsAndBytes (Hugging Face)
The quickest way to load a model in 8-bit or 4-bit for experiments and QLoRA fine-tuning:
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
BASE_MODEL = "your-org/open-weights-model"
bnb_4bit = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL, quantization_config=bnb_4bit, device_map="auto"
)llama.cpp and GGUF
GGUF is the format used by llama.cpp and the tools built on it. It runs on CPUs, Apple Silicon and consumer GPUs, which makes it the usual choice for laptops, edge boxes and small servers.
# Convert a Hugging Face model to GGUF
python convert_hf_to_gguf.py ./my-model --outfile my-model-f16.gguf --outtype f16
# Quantize
./llama-quantize my-model-f16.gguf my-model-q4_k_m.gguf Q4_K_M| Format | Approx. bits | Quality |
|---|---|---|
| Q3_K_M | ~3.4 | Noticeable loss |
| Q4_K_M | ~4.5 | Common default |
| Q5_K_M | ~5.5 | Good |
| Q6_K | ~6.5 | Very good |
| Q8_0 | 8 | Close to FP16 |
from llama_cpp import Llama
llm = Llama(model_path="my-model-q4_k_m.gguf", n_ctx=8192, n_gpu_layers=-1)
output = llm("Summarize this maintenance report: ...", max_tokens=256, temperature=0.2)Serving on GPUs with vLLM
For shared, multi-user serving on your own GPUs, vLLM is a widely used engine. It supports GPTQ, AWQ and other quantized formats, continuous batching and tensor parallelism:
from vllm import LLM, SamplingParams
llm = LLM(model="your-org/open-weights-model-awq", quantization="awq", tensor_parallel_size=2)
outputs = llm.generate(["Classify this support ticket: ..."], SamplingParams(temperature=0.2, max_tokens=128))vLLM also exposes an OpenAI-compatible HTTP server, so applications can switch between a local model and a hosted one by changing a base URL.
Edge and On-Device Inference
Dedicated NPUs in laptops, phones and industrial devices make small models practical on the device itself.
Where it fits
- Field teams and stores with unreliable connectivity
- Real-time tasks where a network round-trip is too slow
- Data that must never leave the device
Technical building blocks
- Compression: quantization plus distillation into smaller models
- NPU runtimes provided by the hardware vendor
- Local caching of frequent answers
- Secure update pipelines so models can be patched like any other software
Hybrid Routing: Local First, Cloud When Needed
Request
│
├─ contains personal or confidential data? ──▶ local model
├─ simple, high-volume task? ──▶ local model
└─ complex reasoning, no sensitive data? ──▶ hosted frontier modelImplement the router as a small, testable rule set first. Log which path each request took; it is valuable evidence for audits and cost planning.
Choosing a Method
Shared GPU server, many users → AWQ or GPTQ (4-bit) + vLLM
CPU, laptop or edge box → GGUF Q4_K_M or Q5_K_M with llama.cpp
Fine-tuning needed → QLoRA (4-bit BitsAndBytes)
Maximum quality → INT8 or BF16Whatever you pick, measure it: run your own evaluation set on the full-precision and the quantized model and compare quality, latency and memory before rollout.
Practical Checklist
- Define the target hardware and its memory limits first.
- Shortlist open-weights models whose license allows your use.
- Measure quality vs. size on your own evaluation set.
- Design the cloud fallback path for complex requests.
- Plan monitoring and secure model updates from day one.
Summary
Quantization turns open-weights models into something you can run on hardware you control, from a GPU server in your data center to a device on the shop floor. Combined with a simple local/cloud router, it gives you AI on sensitive data without sending that data outside.
Veni AI designs and deploys self-hosted and hybrid AI setups for companies that need their data to stay in Türkiye or on their own premises. See our services or talk to us about your infrastructure.


