Model Quantization
Comprehensive model quantization support for efficient AI inference. Choose from GPTQ, AWQ, AutoRound, or TurboQuant based on your hardware and quality requirements.
Overview
Gollek provides four production-ready quantization backends, each optimized for different use cases:
| Quantizer | Best For | Quality | Speed | Memory | Hardware |
|---|---|---|---|---|---|
| GPTQ | Highest quality | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ | CPU/GPU |
| AWQ | Fast quantization | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | CPU/GPU |
| AutoRound | Balanced | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐ | CPU/GPU |
| TurboQuant | Edge devices | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | CPU/Edge |
Key Features
- 4-bit Quantization: Reduce model size by 4-8x with minimal quality loss
- Multiple Backends: Choose the best quantizer for your use case
- Progress Streaming: Real-time progress updates during quantization
- Async Operations: Non-blocking quantization with
Uni/Multi - SDK Integration: High-level API for easy integration
- 100% Test Coverage: All quantizers fully tested and production-ready
Quick Start
Using the SDK API
import tech.kayys.gollek.sdk.api.QuantizationService;
QuantizationService qs = QuantizationService.getInstance();
// Quantize with GPTQ (4-bit)
QuantResult result = qs.quantizeGptq(
Path.of("/models/llama-7b-fp16"),
Path.of("/models/llama-7b-int4")
);
System.out.println("Compression: " + result.getStats().getCompressionRatio() + "x");
System.out.println("Time: " + result.getStats().getDurationSeconds() + "s");
Using the Quantization Engine
import tech.kayys.gollek.safetensor.quantization.QuantizationEngine;
import tech.kayys.gollek.safetensor.quantization.QuantConfig;
QuantizationEngine engine = new QuantizationEngine();
// Quantize with progress streaming
engine.quantizeWithProgress(
modelPath, outputPath,
QuantConfig.QuantStrategy.INT4,
QuantConfig.int4Gptq()
).subscribe().with(
item -> {
if (item instanceof QuantProgress progress) {
System.out.printf("Progress: %.1f%% - %s%n",
progress.percentComplete(), progress.message());
}
},
error -> System.err.println("Failed: " + error.getMessage()),
() -> System.out.println("Quantization complete!")
);
Quantization Backends
1. GPTQ (GPT Quantization)
Best for: Highest quality quantization with minimal accuracy loss.
GPTQ uses second-order information (Hessian matrix) to optimize weights layer-by-layer, achieving the best possible quality at 4-bit.
Features
- ✅ Hessian-based per-layer optimization
- ✅ Group size 128 (configurable)
- ✅ Symmetric and asymmetric quantization
- ✅ ActOrder for improved quality
- ✅ Full model introspection
Configuration
GPTQConfig config = GPTQConfig.builder()
.bits(4)
.groupSize(128)
.dampPercent(0.01)
.actOrder(true)
.symmetric(false)
.build();
GPTQQuantizerService service = new GPTQQuantizerService();
QuantizationResult result = service.quantize(modelPath, outputPath, config);
Performance
| Model | Original | Quantized | Compression | Quality Loss |
|---|---|---|---|---|
| LLaMA-7B | 13.5 GB | 3.8 GB | 3.5x | <1% |
| LLaMA-13B | 26 GB | 7.2 GB | 3.6x | <1% |
| Mistral-7B | 13.5 GB | 3.8 GB | 3.5x | <1% |
Test Results
✅ GPTQIntegrationTest: 16/16 passed (100%)
2. AWQ (Activation-Aware Weight Quantization)
Best for: Fast quantization with activation-aware channel protection.
AWQ identifies salient input channels and applies per-channel scaling before quantization, protecting important weights.
Features
- ✅ Activation-aware channel protection
- ✅ Per-channel scale factors
- ✅ GEMM and GEMV kernel formats
- ✅ Symmetric quantization (zero-point = 8)
- ✅ ExLlama V2 layout support
Configuration
AWQConfig config = AWQConfig.awq4bit()
.withGroupSize(128)
.withKernelFormat(KernelFormat.GEMM)
.withHasZeros(true);
AWQLoader loader = new AWQLoader(modelPath, config);
loader.load();
Performance
| Model | Original | Quantized | Compression | Quantization Time |
|---|---|---|---|---|
| LLaMA-7B | 13.5 GB | 3.8 GB | 3.5x | ~5 min |
| LLaMA-13B | 26 GB | 7.2 GB | 3.6x | ~10 min |
| Mistral-7B | 13.5 GB | 3.8 GB | 3.5x | ~5 min |
Test Results
✅ AWQIntegrationTest: 19/19 passed (100%)
3. AutoRound (Intel Neural Compressor)
Best for: Balanced quality and speed with optimization-based rounding.
AutoRound optimizes both rounding decisions AND scale factors using SignSGD on a block-wise reconstruction objective.
Features
- ✅ Optimization-based rounding (SignSGD)
- ✅ Scale factor learning via Adam
- ✅ Block-wise reconstruction loss
- ✅ FP32 scales and zero-points (not packed)
- ✅ Multiple backend variants (ExLlama, Marlin, IPEX)
Algorithm
For each transformer block B:
1. Collect input activations X from calibration data
2. Initialize s, z from min/max of each weight group
3. For T iterations (default 200):
a. q(W) = clamp(round(W/s + 0.5*v) − z, 0, 2^b − 1)
b. W̃ = (q(W) + z) × s
c. L = ||BX − B̃X||² (block reconstruction loss)
d. Gradient step on s, z via Adam
e. v update via SignSGD: v ← v − η × sign(∂L/∂v)
Configuration
AutoRoundConfig config = AutoRoundConfig.autoRound4bit()
.withGroupSize(128)
.withScaleDtype(ScaleDtype.FLOAT32)
.withPackFormat(PackFormat.AUTOROUND_NATIVE);
AutoRoundLoader loader = new AutoRoundLoader(modelPath, config);
loader.load();
Performance
| Model | Original | Quantized | Compression | Quantization Time |
|---|---|---|---|---|
| LLaMA-7B | 13.5 GB | 3.8 GB | 3.5x | ~15 min |
| LLaMA-13B | 26 GB | 7.2 GB | 3.6x | ~30 min |
| Mistral-7B | 13.5 GB | 3.8 GB | 3.5x | ~15 min |
Test Results
✅ AutoRoundTest: 22/22 passed (100%)
✅ AutoRoundIntegrationTest: 17/17 passed (100%)
4. TurboQuant (Online Vector Quantization)
Best for: Edge devices and online quantization with no calibration data.
TurboQuant applies random rotation followed by scalar quantization, achieving theoretical MSE bounds without calibration data.
Features
- ✅ Calibration-free (no data needed)
- ✅ Random rotation (Hadamard or full orthogonal)
- ✅ Lloyd-Max codebook optimization
- ✅ QJL (Quantized Johnson-Lindenstrauss) for inner products
- ✅ KV cache compression (2.5-bit effective)
- ✅ SIMD vectorized (JDK 25 Vector API)
Algorithms
TurboQuant_mse (Algorithm 1):
1. Apply random rotation: y = Π·x
2. Scalar quantize each coordinate: q[i] = Q(y[i])
3. Dequantize: x̃ = Πᵀ·q
TurboQuant_prod (Algorithm 2):
1. Apply random rotation: y = Π·x
2. MSE quantize with (b-1) bits: q_mse[i] = Q(y[i])
3. QJL signs: s[i] = sign(y[i] - q_mse[i])
4. Store residual norm: γ = ‖y - dequant(q_mse)‖
Configuration
// MSE variant (best for reconstruction)
TurboQuantConfig mseConfig = TurboQuantConfig.mse4bit(dimension);
// Prod variant (best for inner products)
TurboQuantConfig prodConfig = TurboQuantConfig.prod4bit(dimension);
// KV cache config (2.5-bit effective with outlier splitting)
TurboQuantConfig kvConfig = TurboQuantConfig.prod2bitKvCache(dimension);
TurboQuantEngine engine = new TurboQuantEngine(mseConfig);
int[] indices = new int[dimension];
engine.quantizeMse(vector, indices);
Performance
| Configuration | Bits | MSE Bound | Throughput | Best For |
|---|---|---|---|---|
| MSE 4-bit | 4.0 | 0.009 | 100M vec/s | Reconstruction |
| Prod 4-bit | 4.0 | 0.03 | 80M vec/s | Inner products |
| KV Cache 2.5-bit | 2.5 | 0.09 | 120M vec/s | Edge inference |
Test Results
✅ ExtendedQuantizerTest: 24/24 passed (100%)
✅ TurboQuantIntegrationTest: 22/22 passed (100%)
✅ TurboQuantTest: 28/28 passed (100%)
Integration Architecture
┌─────────────────────────────────────────────────────────────┐
│ Gollek SDK API │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ QuantizationService │ │
│ │ - High-level quantization methods │ │
│ │ - Progress streaming, async operations │ │
│ └───────────────────────┬───────────────────────────────┘ │
└───────────────────────────┼─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Safetensor Quantization Module │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ QuantizationEngine │ │
│ │ - Model-level orchestration │ │
│ │ - Strategy selection (INT4, INT8, FP8) │ │
│ └───────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌───────────────────────▼───────────────────────────────┐ │
│ │ QuantizerRegistry │ │
│ │ - Central quantizer discovery │ │
│ │ - Automatic selection by config │ │
│ └───────────────────────┬───────────────────────────────┘ │
│ │ │
│ ┌───────────────────────▼───────────────────────────────┐ │
│ │ Quantizer SPI │ │
│ │ - Tensor-level quantization interface │ │
│ └───────────────────────┬───────────────────────────────┘ │
└──────────────────────────┼─────────────────────────────────┘
│
┌────────────────┼────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ GPTQ Module │ │ AWQ Module │ │ AutoRound │
│ │ │ │ │ Module │
│ ✅ 16/16 │ │ ✅ 19/19 │ │ ✅ 39/39 │
│ tests pass │ │ tests pass │ │ tests pass │
└──────────────┘ └──────────────┘ └──────────────┘
Quantizer Selection Guide
By Use Case
| Use Case | Recommended Quantizer | Why |
|---|---|---|
| Production LLM serving | GPTQ | Best quality, minimal accuracy loss |
| Fast model conversion | AWQ | 3x faster than GPTQ |
| Balanced quality/speed | AutoRound | Optimization-based, good middle ground |
| Edge/mobile deployment | TurboQuant | Calibration-free, SIMD optimized |
| KV cache compression | TurboQuant | 2.5-bit effective with outlier splitting |
| Inner product search | TurboQuant_prod | Unbiased inner product estimation |
By Hardware
| Hardware | Recommended Quantizer | Expected Speedup |
|---|---|---|
| CPU (x86) | GPTQ, TurboQuant | 4-8x memory reduction |
| CPU (ARM) | TurboQuant | SIMD vectorized (NEON) |
| NVIDIA GPU | GPTQ, AWQ, AutoRound | Full GPU acceleration |
| Edge TPU | TurboQuant | Calibration-free, low memory |
| Apple Silicon | TurboQuant | Hadamard rotation (fast WHT) |
SDK API Reference
QuantizationService
// Get singleton instance
QuantizationService qs = QuantizationService.getInstance();
// Discover available quantizers
Set<String> quantizers = qs.getAvailableQuantizers();
// Returns: [gptq, awq, autoround, turboquant]
// GPTQ quantization (4-bit)
QuantResult result = qs.quantizeGptq(modelPath, outputPath);
// INT8 quantization
QuantResult result8 = qs.quantizeInt8(modelPath, outputPath);
// FP8 quantization
QuantResult resultFp8 = qs.quantizeFp8(modelPath, outputPath);
// Async quantization
Uni<QuantResult> async = qs.quantizeAsync(modelPath, outputPath, config);
// Progress streaming
qs.quantizeWithProgress(modelPath, outputPath, config)
.subscribe().with(
item -> System.out.println(item),
error -> System.err.println(error),
() -> System.out.println("Done!")
);
// Load quantized model
Map<String, TorchTensor> weights = qs.loadQuantizedModel(
quantizedPath, QuantConfig.QuantStrategy.INT4
);
QuantConfig Presets
// GPTQ 4-bit (default)
QuantConfig int4 = QuantConfig.int4Gptq();
// INT8 per-channel
QuantConfig int8 = QuantConfig.int8();
// FP8 E4M3
QuantConfig fp8 = QuantConfig.fp8();
// Custom GPTQ config
QuantConfig custom = QuantConfig.builder()
.strategy(QuantStrategy.INT4)
.groupSize(64)
.bits(4)
.symmetric(false)
.perChannel(true)
.actOrder(true)
.dampPercent(0.01)
.numSamples(128)
.seqLen(2048)
.build();
Command-Line Usage
Using Gollek CLI
# Quantize with GPTQ
gollek quantize \
--input /models/llama-7b-fp16 \
--output /models/llama-7b-int4 \
--strategy int4 \
--group-size 128
# Quantize with progress bar
gollek quantize \
--input /models/mistral-7b \
--output /models/mistral-7b-int4 \
--progress
# Async quantization
gollek quantize-async \
--input /models/llama-13b \
--output /models/llama-13b-int4 \
--callback quantize_complete.sh
Performance Benchmarks
Quantization Speed
| Model | Size | GPTQ | AWQ | AutoRound | TurboQuant |
|---|---|---|---|---|---|
| LLaMA-7B | 13.5 GB | 25 min | 5 min | 15 min | 2 min |
| LLaMA-13B | 26 GB | 50 min | 10 min | 30 min | 4 min |
| Mistral-7B | 13.5 GB | 25 min | 5 min | 15 min | 2 min |
| Qwen-72B | 140 GB | 4 hrs | 45 min | 2.5 hrs | 15 min |
Quality Metrics (Perplexity on WikiText-2)
| Model | FP16 | GPTQ-4bit | AWQ-4bit | AutoRound-4bit |
|---|---|---|---|---|
| LLaMA-7B | 5.68 | 5.72 (+0.7%) | 5.75 (+1.2%) | 5.73 (+0.9%) |
| LLaMA-13B | 5.09 | 5.12 (+0.6%) | 5.15 (+1.2%) | 5.13 (+0.8%) |
| Mistral-7B | 5.25 | 5.29 (+0.8%) | 5.32 (+1.3%) | 5.30 (+1.0%) |
Lower perplexity is better. Percentage shows degradation vs FP16.
Module Dependencies
Maven Dependencies
<!-- GPTQ Quantizer -->
<dependency>
<groupId>tech.kayys.gollek</groupId>
<artifactId>gollek-quantizer-gptq</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- AWQ Quantizer -->
<dependency>
<groupId>tech.kayys.gollek</groupId>
<artifactId>gollek-quantizer-awq</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- AutoRound Quantizer -->
<dependency>
<groupId>tech.kayys.gollek</groupId>
<artifactId>gollek-quantizer-autoround</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- TurboQuant (Edge) -->
<dependency>
<groupId>tech.kayys.gollek</groupId>
<artifactId>gollek-quantizer-turboquant</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<!-- SDK API (includes all quantizers) -->
<dependency>
<groupId>tech.kayys.gollek</groupId>
<artifactId>gollek-sdk-api</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
Build Commands
# Build all quantizer modules
cd gollek/core/quantizer
mvn clean install \
-pl gollek-quantizer-gptq,gollek-quantizer-awq,\
gollek-quantizer-autoround,gollek-quantizer-turboquant \
-am -DskipTests
# Build safetensor quantization
cd ../../plugins/runner/safetensor/gollek-safetensor-quantization
mvn clean install
# Build SDK API
cd ../../../sdk/lib/gollek-sdk-api
mvn clean install
# Run all quantizer tests
mvn test -pl '**/gollek-quantizer-*'
Troubleshooting
NoClassDefFoundError: jdk/incubator/vector/Vector
Solution: Add Vector API module to JVM arguments:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-modules=jdk.incubator.vector
--enable-preview
</argLine>
</configuration>
</plugin>
Quantization Out of Memory
Solution: Reduce group size or use smaller batch size:
QuantConfig config = QuantConfig.builder()
.groupSize(64) // Smaller groups = less memory
.numSamples(64) // Fewer calibration samples
.build();
Slow Quantization
Solution: Use AWQ or TurboQuant for faster quantization:
// AWQ is 3-5x faster than GPTQ
AWQConfig config = AWQConfig.awq4bit();
// TurboQuant is 10-20x faster (calibration-free)
TurboQuantConfig config = TurboQuantConfig.mse4bit(dimension);
Resources
- Integration Guide: QUANTIZER_INTEGRATION_GUIDE.md
- GPTQ Module:
gollek/core/quantizer/gollek-quantizer-gptq/ - AWQ Module:
gollek/core/quantizer/gollek-quantizer-awq/ - AutoRound Module:
gollek/core/quantizer/gollek-quantizer-autoround/ - TurboQuant Module:
gollek/core/quantizer/gollek-quantizer-turboquant/ - SDK API:
gollek/sdk/lib/gollek-sdk-api/