Logo von Llm Model Quantization

Llm Model Quantization

Community
j4flmao
llm-model-quantization

Use this skill when the user says 'quantize a model', 'GPTQ', 'AWQ', 'GGUF', 'Q4_K_M', 'INT4 / INT8 / FP8 weights', 'NF4', 'bitsandbytes', 'model too big for my GPU'. Explains how weight (and activation) quantization works, compares GPTQ, AWQ, GGUF k-quants, bitsandbytes NF4, and FP8, and gives working commands to produce and serve quantized models with an evaluation gate. Do NOT use for: KV cache sizing (ai/llm-engineering/kv-cache), QLoRA fine-tuning workflows (ai/llm-finetuning), or running local models end to end (rnd/ai-agents/local-slm-inference).

Übersicht

Herausgeberj4flmao
Repositoryagent-skills
Skill-Namellm-model-quantization
Sterne
41
Forks
6
Mitgelieferte Dateien
Nur Anweisungen
LizenzMIT
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • In sich abgeschlossen

    Alles, was das Modell braucht, steht in den Anweisungen — keine zusätzlichen Dateien zum Synchronisieren.

  • Open Source

    Von j4flmao auf GitHub veröffentlicht. Prüfen Sie den Quellinhalt vor der Installation.

Installation

Installieren Sie den KI-Skill Llm Model Quantization in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner — liest SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/j4flmao/agent-skills/tree/main/skills/ai/llm-engineering/model-quantization
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill anlegen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format lesen kann, kann diesen Skill nutzen — kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/ai/llm-engineering/model-quantization .claude/skills/llm-model-quantization
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie Llm Model Quantization in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt Llm Model Quantization automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist Llm Model Quantization nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Keys.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

Model Quantization

Purpose

Quantization stores weights (and optionally activations) in fewer bits so a model fits in less memory and decodes faster, since decoding is usually memory-bandwidth bound. The cost is a quality loss that depends on bit width, method, calibration data, and model. Pick the format your inference engine runs fastest, quantize with a calibration-aware method, and gate the result on your own evals.

Agent Protocol

Trigger

"quantize", "GPTQ", "AWQ", "GGUF", "k-quants", "Q4_K_M", "INT4", "INT8", "FP8", "NF4", "bitsandbytes", "fit model in VRAM".

Input Context

  • Model and size; target hardware (NVIDIA generation, Apple Silicon, CPU).
  • Inference engine (vLLM, TensorRT-LLM, llama.cpp/Ollama, transformers).
  • Quality tolerance and the eval set that measures it.

Output Artifact

Recommended format and bit width, quantization commands, memory estimate, eval comparison plan.

Response Format

Target: {hardware} via {engine}
Format: {fp8|awq-w4a16|gptq-w4a16|gguf Q4_K_M|nf4}
Memory: weights ≈ params × bits/8 (+ scales) = {GB}
Steps: {commands}
Eval gate: {metric} drop ≤ {x}% vs bf16 baseline

Completion Criteria

  • Format supported natively by the target engine/hardware.
  • Calibration data resembles production inputs.
  • Baseline vs quantized evaluated on task metrics, not only perplexity.
  • Throughput/latency measured, not assumed.

How It Works

Affine (asymmetric) quantization of a group of weights:

scale  s = (max(W) - min(W)) / (2^b - 1)
zero   z = round(-min(W) / s)
q      = clamp(round(W / s) + z, 0, 2^b - 1)
W_hat  = s · (q - z)

Symmetric quantization fixes z = 0 and uses a signed range. Group-wise quantization (e.g. group size 128) keeps a separate scale (and zero point) per group, limiting the damage from outliers at a cost of extra bits per weight (a 16-bit scale per 128 weights adds 0.125 bits/weight).

Weight-only schemes (W4A16, W8A16) dequantize inside the matmul kernel; they help most in the memory-bound decode phase. Weight+activation schemes (W8A8 INT8/FP8) also speed up compute-bound prefill on hardware with matching tensor-core support.

Methods

MethodIdeaCalibrationTypical use
RTN (round-to-nearest)Quantize each group independentlyNoneBaseline; fine at 8-bit
GPTQQuantize columns sequentially, compensate error in remaining weights using approximate second-order (Hessian) informationYes (small dataset)4-bit GPU serving
AWQFind salient weight channels via activation magnitudes; scale them up (inputs scaled down) before quantizing so their relative error shrinksYes4-bit GPU serving
SmoothQuantMigrate activation outliers into weights to enable W8A8YesINT8 activations
FP8 (E4M3)8-bit float weights/activations with per-tensor or per-channel scalesOptional (static scales)Hopper/Ada/Blackwell GPUs
NF4 (bitsandbytes)4-bit NormalFloat data type with double quantization of scalesNoneQLoRA training, quick experiments
GGUF k-quantsBlock quantization with super-blocks of quantized scales; optional importance matrixOptional (imatrix)llama.cpp / Ollama on CPU, Apple, mixed CPU+GPU

Choosing a Format

Engine?
├── vLLM / TensorRT-LLM / SGLang on recent NVIDIA (FP8-capable)
│   └── FP8 W8A8 first (near-lossless on most models); W4A16 (AWQ/GPTQ) if memory-bound
├── vLLM on older GPUs (Ampere) → W4A16 AWQ or GPTQ (Marlin kernels)
├── llama.cpp / Ollama / LM Studio → GGUF: Q4_K_M default, Q5_K_M/Q6_K for quality, Q8_0 near-lossless
├── transformers experiments / QLoRA → bitsandbytes NF4
└── Blackwell → FP4 variants (NVFP4/MXFP4) where the engine supports them; eval carefully

Producing Quantized Models

W4A16 GPTQ with llm-compressor (vLLM project); AutoGPTQ and AutoAWQ are no longer maintained, so prefer llm-compressor or GPTQModel:

python
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier

recipe = GPTQModifier(targets="Linear", scheme="W4A16", ignore=["lm_head"])
oneshot(
    model="meta-llama/Llama-3.1-8B-Instruct",
    dataset="open_platypus",              # replace with in-domain calibration data
    recipe=recipe,
    max_seq_length=2048,
    num_calibration_samples=512,
    output_dir="Llama-3.1-8B-Instruct-W4A16",
)
# Serve: vllm serve ./Llama-3.1-8B-Instruct-W4A16   (format detected from the saved config)

GGUF with llama.cpp:

bash
python convert_hf_to_gguf.py ./Llama-3.1-8B-Instruct --outtype f16 --outfile llama-f16.gguf
./llama-imatrix -m llama-f16.gguf -f calibration.txt -o imatrix.dat      # optional, helps low bits
./llama-quantize --imatrix imatrix.dat llama-f16.gguf llama-Q4_K_M.gguf Q4_K_M

NF4 on load (bitsandbytes):

python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig

bnb = 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("meta-llama/Llama-3.1-8B-Instruct",
                                             quantization_config=bnb, device_map="auto")

Memory Estimates (weights only)

Paramsbf168-bit~4.5 bits (4-bit + scales)
8B16 GB8 GB~4.5 GB
70B140 GB70 GB~40 GB

Add KV cache and runtime overhead on top (see the kv-cache skill).

Evaluation Gate

  1. Run the bf16 baseline and the quantized model on the same task evals (accuracy, pass@k, rubric scores) plus a perplexity sanity check.
  2. Check long-context and tool-calling behaviour separately; they degrade before short QA does.
  3. Measure tokens/s and TTFT on the real engine and batch sizes; low-bit kernels can be slower at large batch.
  4. Ship only if the drop is within the agreed threshold.

Anti-Patterns

  • Judging quality by perplexity alone.
  • Calibrating on generic web text for a domain model (code, legal, non-English).
  • Quantizing lm_head/embeddings aggressively without testing.
  • Choosing a format the engine dequantizes in slow fallback kernels.
  • Comparing speed at batch size 1 when production runs batched.

Checklist

  • Format matches engine and GPU generation.
  • In-domain calibration set (hundreds of samples).
  • Baseline vs quantized eval table recorded.
  • Throughput/latency benchmark on target hardware.
  • Model card notes method, bits, group size, calibration data.

References

  • Frantar et al., "GPTQ" (ICLR 2023); Lin et al., "AWQ" (MLSys 2024); Xiao et al., "SmoothQuant" (ICML 2023); Dettmers et al., "QLoRA" (NeurIPS 2023).
  • llama.cpp docs: convert_hf_to_gguf.py, llama-quantize, llama-imatrix; vLLM quantization docs; llm-compressor examples.

Häufig gestellte Fragen

Was macht der KI-Skill Llm Model Quantization?

Use this skill when the user says 'quantize a model', 'GPTQ', 'AWQ', 'GGUF', 'Q4_K_M', 'INT4 / INT8 / FP8 weights', 'NF4', 'bitsandbytes', 'model too big for my GPU'. Explains how weight (and activation) quantization works, compares GPTQ, AWQ, GGUF k-quants, bitsandbytes NF4, and FP8, and gives working commands to produce and serve quantized models with an evaluation gate. Do NOT use for: KV cache sizing (ai/llm-engineering/kv-cache), QLoRA fine-tuning workflows (ai/llm-finetuning), or running local models end to end (rnd/ai-agents/local-slm-inference).

Warum Llm Model Quantization in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. Llm Model Quantization besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich Llm Model Quantization in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/j4flmao/agent-skills/tree/main/skills/ai/llm-engineering/model-quantization ein. TypingMind liest die Datei SKILL.md und installiert den Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können Llm Model Quantization nutzen?

Jedes Modell, das Sie in TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit Llm Model Quantization verwenden?

So viele Sie möchten. Solange ein Modell Skills unterstützt, können Sie Llm Model Quantization damit verwenden – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama und weitere – alles in TypingMind mit Ihren eigenen API-Schlüsseln.

Ist der KI-Skill Llm Model Quantization kostenlos?

Ja. Der Skill wird von j4flmao auf GitHub unter der Lizenz MIT veröffentlicht. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: eine Datei namens SKILL.md mit einem Namen und einer Beschreibung sowie allen Skripten, Vorlagen oder Referenzdateien, die das Modell möglicherweise benötigt. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und benötigen daher weder Server noch API-Schlüssel oder Laufzeitumgebung. Sie funktionieren mit jedem Modell.

Alle

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇