# Repository Briefing: IST-DASLab/GSQ
> Source: https://repoforai.com/repo/IST-DASLab/GSQ (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/IST-DASLab/GSQ
- **Official Docs / Website**: https://huggingface.co/collections/ISTA-DASLab/gsq
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: B (51/100 · Maintenance 12/35 · Adoption 13/25 · Releases 6/20 · License 20/20)
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: GPU, CLI
- **Momentum**: 160 ★ total (+1 24h / +5 7d) · 21 forks
- **Topics**: `gguf`, `llm`, `post-training-quantization`, `quantization`
- **When to Use**: Best for: Teams evaluating 2–3-bit or ternary LLM weights on CUDA GPUs that can budget for calibration and refinement and need to retain an INT scalar or GGUF K-Quant deployment format. Skip if: A ready-made checkpoint or GPTQ alone already meets your quality target, you need CPU-only quantization, or Ada-based vLLM fused MoE serving is a hard requirement.

## Overview
```text
### Architecture & Core Mechanics
GSQ is a layer-wise PyTorch post-training quantizer, not an inference engine. `main.py` uses calibration activations to initialize each layer with GPTQ; round-to-nearest is available as an alternative. It then minimizes layer-output reconstruction error by learning a discrete grid assignment for each weight and a scale for each group. Gumbel-Softmax makes the assignments differentiable during refinement: temperature falls and logit scale rises before the final hard selection. The Lion optimizer runs with a cosine learning-rate schedule, and custom autograd replays the sampling RNG state in the backward pass.

Completed layers are serialized as `.safetensors` shards and moved to `meta` so they no longer occupy device memory. `save_model.py` assembles the shards into a Hugging Face-compatible checkpoint with `compressed-tensors` metadata for vLLM. Model-family wrappers handle dense and expert-parallel MoE variants. Strict YAML validation in `src.config.load_config` rejects unknown keys, while shell entrypoints expose the quantize, save, serve and evaluate stages separately.

### Key Capabilities & Differentiators
The supplied recipes cover ternary, 2-bit and 3-bit weights. The default 2-bit grid uses four integer levels with a learned group scale; the ternary quantizer learns separate sign and mask logits. Model wrappers cover dense LLaMA, Qwen3 and Qwen3.5/3.6, and Gemma-4-35B, alongside Qwen and Kimi K2/K2.5 MoE variants. The GGUF path can refine a public K-Quant checkpoint and write it back in the same format for llama.cpp or Ollama.

At 2.13 bits per parameter, Llama-3.1-Instruct scored 68.55 for 8B and 75.57 for 70B on the zero-shot average across ARC-C/E, HellaSwag, PIQA and Winogrande; the FP16 scores were 73.71 and 78.99. In a separate Qwen3-8B GGUF experiment, the Q2_K average rose from 50.03 to 56.28 without changing the K-Quant format. These results measure quality at specific footprints; they do not establish serving latency or throughput.

### Trade-offs & Limitations
GSQ is useful when a scalar checkpoint is a deployment requirement and initialization alone loses too much quality. In the Llama-3.1-70B comparison at 2.13 bpp, GSQ scored 75.57 versus 71.43 for EfficientQAT and 57.38 for GPTQ, but trailed vector-quantized QTIP at 77.25. The trade is additional calibration-driven optimization in exchange for better quality than those scalar baselines in this test, without adopting a vector codebook. Layer offloading reduces GPU residency; it does not eliminate optimization time, activation storage or checkpoint I/O.

A compatible weight format is not a guarantee that a fast kernel will run. On Ada, vLLM's `compressed-tensors` WNA16 fused MoE path lacks the needed Marlin kernel and falls back to a Triton path that crashes during profiling. An incompatible tensor-parallel shape can trigger that fallback as well. Qwen3.5-MoE requires `transformers >= 5.3`, which conflicts with the Kimi-K2.5 setup; plan separate environments if both are needed. Treat the benchmark figures as model- and evaluation-specific, not as a reason to skip workload validation.

### Hardware & Deployment Guide
GSQ is an Apache-2.0 Python CLI project requiring Python 3.10 or later. `scripts/setup_env.sh` uses `uv.lock` to provision the environment, installs `flash-attn` on top by default and checks imports. The manifest pins PyTorch 2.11.0, torchvision 0.26.0 and vLLM 0.20.2; the default CUDA wheel target is `cu128`. Start with `SMOKE_TEST=1 bash scripts/run.sh` for a two-layer check. The scripts use `torchrun` for local multi-GPU runs. Quantization is self-hosted, but gated weights such as Kimi-K2.5 require Hugging Face access.

Treat quantization and serving as separate hardware checks: H100 is the tested platform, L40S has been used for quantization, and the vLLM serving path targets Hopper or Ampere. MoE tensor parallelism must satisfy attention-head divisibility, KV-head divisibility for GQA, and Marlin alignment of the sharded expert width. At group size 128, the listed valid TP maxima on eight GPUs are 2 for Qwen3-30B-A3B, 4 for Qwen3-235B-A22B and 8 for Kimi K2/K2.5. The serving script clamps TP to a valid value by default. The package manifest is version 0.1.0, with no GitHub release listed.
```

## Key Capabilities
```text
- Optimization: GPTQ initialization followed by Gumbel-Softmax refinement of per-weight assignments and per-group scales.
- Precision: Ternary, 2-bit and 3-bit recipes; the default 2-bit codebook is {-2, -1, 0, 1} multiplied by a learned group scale.
- Memory management: Completed layers are written to `.safetensors` and offloaded to `meta` before checkpoint assembly.
- Model coverage: Dense LLaMA, Qwen and Gemma wrappers, plus distributed expert-parallel wrappers for supported Qwen and Kimi MoE models.
- Export paths: Hugging Face-compatible `compressed-tensors` checkpoints for vLLM and in-format GGUF K-Quant refinement for llama.cpp or Ollama.
- Serving guardrail: `scripts/serve_model.sh` adjusts the requested MoE tensor-parallel size to satisfy attention-head and Marlin shape constraints.
```

## Quick Start / Clone
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```
