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

- **GitHub URL**: https://github.com/IST-DASLab/RCO
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: B (52/100 · Maintenance 12/35 · Adoption 14/25 · Releases 6/20 · License 20/20)
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: CLI
- **Momentum**: 91 ★ total (+0 24h / +3 7d) · 13 forks
- **When to Use**: Best for: LLM compression research and offline checkpoint preparation when you need to compare layer bit widths or expert allocations under a fixed budget and can validate the exported artifact on the intended runtime. Skip if: A fixed-bit checkpoint already meets your quality target, you need a turnkey inference server, or your target runtime cannot load the packed format or heterogeneous expert layout you need.

## Overview
```text
### Architecture & Core Mechanics
RCO separates compression into candidate preparation, constrained search, and checkpoint export. For quantization, run_quantize.py builds a per-layer GPTQ database; src/search/quant.py uses its dequantized candidates to evaluate model loss. The pruning path in src/search/prune.py applies straight-through survival masks to MoE routing weights and does not require that database. Both paths feed into run_build_checkpoint.py.

The optimizer in src/manifold.py represents each group's choices as softmax logits. It projects the loss gradient onto the tangent space of the weighted expected-cost constraint, retracts the Adam update back to the budget surface by binary search, and reprojects momentum. Separately, the forward pass uses annealed Gumbel perturbations and exact multiple-choice knapsack DP to select a feasible assignment; the backward pass uses a straight-through softmax surrogate. Python CLIs drive the PyTorch and Transformers stack. The optional vLLM patch is a serving integration, not a search dependency.

### Key Capabilities & Differentiators
Mixed-precision search assigns 2–8 bits to linear layers and weights each choice by that layer's parameter count. For a target such as the Qwen3-8B example's 2.5-bit average, the budget applies to the searched weights, not every byte in the final artifact. run_split_checkpoint.py can populate one bit-width slot from an existing compressed-tensors checkpoint. Export supports dense bf16 fake quantization or packed weights rebuilt from integer codes, scales, zero points, and other metadata in _qparams.pt sidecars.

MoE pruning searches an exact expert-count budget and writes a keep/prune mask; the OLMoE example uses a 25% prune target. Export can zero experts and router rows without changing tensor shapes, or remove the experts and shrink the router. Calibration accepts plain-text sources such as FineWeb-Edu and chat data such as Evol-CodeAlpaca and Tulu Math, with assistant-token masks for chat. Pruning also supports equal-sample mixtures of calibration sources.

### Trade-offs & Limitations
Unlike a dynamic program that optimizes a fixed per-layer proxy, RCO uses end-to-end model loss to update the search logits and uses DP for the budget-feasible discrete choices. Unlike a penalty method, feasibility does not depend on tuning a penalty coefficient. That does not make the assignment globally optimal: gradients come from a straight-through surrogate, and the stated discrete solver complexity is O(N*K*B) in the number of groups, options, and solver budget. Compared with evolutionary baselines EvoPress and EvoESAP, this is a gradient-driven research workflow; validate its quality and search cost under your own calibration setup.

The main operational cost is preparing and storing candidates, then exporting a checkpoint that the target runtime can actually serve. Fixed-bit quantization is simpler when precision is already decided. The default fake-quant and zero-pruning exports support compatibility testing but do not save weight storage. Packed or physically pruned exports warrant a loader and kernel check before inferring throughput gains. The code is Apache-2.0; base-model and dataset terms are separate.

### Hardware & Deployment Guide
Run the top-level Python entry points from the repository root without an editable install, or use the wrappers in scripts/. The pinned stack includes torch==2.11.0+cu126, transformers==5.7.0, accelerate==1.13.0, and datasets==4.8.5. Ensure the PyTorch build and CUDA driver are compatible for the GPU workflow. compressed-tensors==0.15.0.1 is needed for packed checkpoint import or export, not for the core search. The workflow runs locally against model and calibration artifacts; no hosted compression API is required.

The documented GPTQ command uses eight torchrun workers. Establish GPU memory and scratch-space requirements for your own model and calibration settings before a full run. For deployment, test the exported checkpoint on the target loader: heterogeneous physical pruning needs per-layer expert-count support, and the supplied vLLM patch targets Qwen3-Next specifically. There is no published GitHub release listed; record the exact repository revision and dependency set used to produce each artifact.
```

## Key Capabilities
```text
- Budget control: A scalar retraction corrects expected-cost drift after Adam updates; multiple-choice knapsack DP enforces the discrete budget during the forward pass.
- Candidate database: run_quantize.py writes dequantized GPTQ weights and integer quantization sidecars; run_split_checkpoint.py imports one bit-width slot from a compressed-tensors checkpoint.
- Cost models: Mixed precision weights 2–8-bit choices by layer parameter count; MoE pruning budgets the number of removed experts.
- Calibration: Text and chat datasets are supported, with assistant-token masks for chat loss and equal-sample dataset mixtures in pruning search.
- Export semantics: Packed quantization and physical expert removal change what is stored; default bf16 fake quantization and zero-mode pruning do not shrink weights on disk.
- Serving boundary: Uniform expert removal can use stock Hugging Face or vLLM loaders; heterogeneous removal records per_layer_num_experts, with an optional Qwen3-Next-targeted vLLM patch.
```

## Quick Start / Clone
```bash
pip install -r requirements.txt
```
