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

- **GitHub URL**: https://github.com/huawei-csl/MACaQ
- **Official Docs / Website**: https://huawei-csl.com/blog/macaq/
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: C++
- **License**: Apache-2.0
- **Engineering Health**: A (77/100 · Maintenance 35/35 · Adoption 11/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: Local AI, CLI, GPU
- **Momentum**: 413 ★ total (+7 24h / +15 7d) · 25 forks
- **Topics**: `ascend`, `audio`, `audio-generation`, `diffusers`, `gguf`, `gguf-quantization`, `image-generation`, `llm`, `local-ai`, `local-inference`, `quantization`, `video-generation`
- **When to Use**: Best for: Teams refining existing GGUFs without changing standard llama.cpp, or benchmarking backend-specific low-precision inference for text, image, video, and audio models. Skip if: An off-the-shelf checkpoint already meets your targets, you lack the matching source and teacher needed for GGUF refinement, or you need a turnkey Ascend full-model runtime.

## Overview
```text
### Architecture & Core Mechanics
MACaQ separates calibration and quantization from inference: it produces artifacts for existing runtimes rather than introducing a single multimodal engine. The root tree includes `quantize/` alongside `llamacpp/`, `vllm/`, `diffusers/`, and `pytorch/`. For text, the full llama.cpp workflow uses a bundled runtime for activation transforms; MACaQ-R instead refines weight codes inside an existing GGUF while preserving its native formats and block scales, so the result runs on standard llama.cpp.

The setuptools-built `macaq-mxfp4` package declares Python ≥3.10 and registers `macaq_plugin:register` under `vllm.general_plugins`. Its module list includes Triton-named dense, MoE, and MoE decode modules, plus a cuDNN-named dense module. Those module names describe the packaged integration surface, not a guarantee that each kernel runs on every GPU. Diffusers saves quantized transformers as safetensors checkpoints; the PyTorch speech path saves reloadable W4A4 checkpoints.

### Key Capabilities & Differentiators
The llama.cpp workflow targets 2-, 3-, and 4-bit GGUF for text, with dense, hybrid, and MoE recipes. For Qwen3.6-35B-A3B, MACaQ-R Q4_K_XL reduces KL divergence to FP16 from 0.015731 for Unsloth UD-Q4_K_XL to 0.013367, with both files at 22.36 GB. On Qwen3.8-27B in vLLM, W4A4 records 2.33× prefill and 2.58× decode throughput relative to BF16, with perplexity moving from 2.8463 to 2.8994.

Diffusers covers FLUX.2-klein-4B for images, Wan2.2-TI2V-5B for video and image-to-video, and Stable Audio 1.0 for audio. Image-to-video calibration incorporates conditioning images. Wan2.2 also has a Diff4Diff path with fused W4A4 kernels and optional SVD correction. The separate PyTorch path covers Qwen3-TTS and Chatterbox Turbo, generating WAV audio from saved quantized checkpoints without rerunning calibration.

### Trade-offs & Limitations
Compared with downloading a ready-made GGUF, MACaQ-R adds a calibration stage and requires access to the matching original model and FP16 teacher. The payoff is a chance to reduce divergence from FP16 without increasing file size or replacing standard llama.cpp, as in the Unsloth comparison. KL divergence and perplexity measure different aspects of quality and do not establish downstream task gains. Benchmark representative prompts or media inputs before committing to a quantized artifact.

On vLLM, W4A4 trades a measured perplexity increase for higher throughput on the tested Qwen model. That result is not a latency or throughput guarantee on a different GPU or workload; weight-only inference is a separate path worth testing when the W4A4 path is unsuitable. The reported 122B quantization run—64 minutes and 32.5 GB of device memory—is a calibration and quantization datapoint, not a serving budget. Apache-2.0 covers the code; model and checkpoint terms must be checked separately.

### Hardware & Deployment Guide
Use separate Python 3.12 environments for the chosen backends; the vLLM package's Python ≥3.10 metadata is a packaging floor, not the recommended setup for every backend. For local GGUF refinement, `llamacpp/macaq.py refine` takes the input GGUF (`--model`), matching source (`--hf`), FP16 teacher GGUF (`--teacher`), and calibration text (`--calibration`), plus `--output` and `--work-dir`. The refined artifact can run locally with `llama cli`, including on CPU, or be served with `llama serve`. vLLM is the separate HTTP serving path.

Ascend dense and grouped matmul kernels are available through CANN pull requests, with build compatibility tied to CANN, PyTorch, and `torch_npu`; full-model execution still requires integration with an Ascend inference runtime. No GitHub release is listed, so there is no release milestone to use as a deployment baseline. Pin the repository revision and validate the chosen runtime and checkpoint together before rollout.
```

## Key Capabilities
```text
- GGUF compatibility: MACaQ-R changes weight codes without changing native block formats or scales.
- Representation: The bundled llama.cpp flow targets 2-, 3-, and 4-bit GGUF; explicit stock compatibility applies to MACaQ-R.
- Serving integration: The vLLM general plugin defaults to W4A4 and also supports weight-only execution.
- Video kernels: Diff4Diff for Wan2.2 uses fused W4A4 kernels with optional SVD correction.
- Checkpoint reuse: PyTorch speech checkpoints can be loaded for WAV generation without repeating calibration.
- Accelerator boundary: Ascend dense and grouped matmul kernels are available through CANN pull requests; full-model execution requires runtime integration.
```

## Quick Start / Clone
```bash
.venv-llamacpp/bin/python llamacpp/macaq.py refine \
  --model models/model-q4.gguf --hf models/original \
  --teacher models/original-f16.gguf --calibration data/calibration.txt \
  --output models/model-macaq-r.gguf --work-dir work/refinement
```
