Add Reasoning-Aware Compression (RAC) pruning recipe for reasoning models - #32414
Merged
Qiaolin-Yu merged 3 commits intoAug 14, 2026
Merged
Conversation
Implements the recipe from "Reasoning Models Can be Accurately Pruned Via Chain-of-Thought Reconstruction" (ICLR 2026, arXiv:2509.12464). One-shot pruning methods pick weights by minimizing a layer-wise reconstruction error against a calibration activation matrix built from *prompt* tokens. That is a fair proxy when the prompt dominates the token count, but reasoning models invert the ratio: nearly every forward pass the pruned model runs is over a token it generated itself. Calibrating on prompts alone optimizes for a distribution the model barely visits, and the resulting model rambles -- it emits more chain-of-thought and answers less accurately, so pruning makes it slower. RAC fixes this by calibrating on the dense model's own on-policy rollout: X_RAC = [X_prompt, X_decode]. The solver is untouched. Collecting that rollout is the expensive half (the paper's budget is 1M on-policy CoT tokens), and it is batched autoregressive generation, which is what SGLang is for. So this lands as an offline recipe under examples/usage: rac_collect_traces.py sgl.Engine samples on-policy CoT -> traces.jsonl rac_prune.py llm-compressor runs SparseGPT/Wanda on those traces rac_serve_and_eval.py SGLang serves the result and scores MATH-500 The pruning solver stays in llm-compressor, imported lazily, so SGLang gains no new dependency. Traces are emitted as token ids and consumed as token ids, so the sequence the pruner reconstructs is exactly the one the model produced. Calibration runs at batch size 1 because pad-token activations would otherwise enter the layer-wise Hessian. rac_collect_traces.py also has a prompt_only mode that builds the paper's ablation baseline from the same prompts, and rac_serve_and_eval.py reports mean CoT length and wall clock next to accuracy, since accuracy alone hides the failure mode above. Co-Authored-By: Ryan Lucas <ryanluc@mit.edu> Co-Authored-By: Kayhan Behdin <kbehdin@linkedin.com>
PKUWZP
requested review from
JustinTong0323,
sogalin,
wisclmy0611 and
zijiexia
as code owners
July 26, 2026 01:04
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Collaborator
|
could you fix the conflicts? |
Qiaolin-Yu
approved these changes
Aug 12, 2026
Resolves the docs_new/ -> docs/ directory rename from main by relocating the RAC page to docs/docs/advanced_features/reasoning_aware_compression.mdx.
Contributor
Author
@Qiaolin-Yu I think someone with the write access should add both labels to this PR:
|
Contributor
Author
I think once the labels are updated, the conflicts should be resolved. |
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
…dels (sgl-project#32414) Co-authored-by: Ryan Lucas <ryanluc@mit.edu> Co-authored-by: Kayhan Behdin <kbehdin@linkedin.com> Co-authored-by: Zhipeng Wang <zwanga@wustl.edu>
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
…dels (sgl-project#32414) Co-authored-by: Ryan Lucas <ryanluc@mit.edu> Co-authored-by: Kayhan Behdin <kbehdin@linkedin.com> Co-authored-by: Zhipeng Wang <zwanga@wustl.edu>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Co-authored with Ryan Lucas (MIT) and Kayhan Behdin (LinkedIn).
Motivation
Compressing reasoning models with standard pruning does more damage than compressing a conventional LLM, and it can make the model slower.
One-shot pruning picks weights by minimizing a layer-wise reconstruction error against a calibration activation matrix
X:Xis conventionally built from prompt tokens (C4, or task prompts). That is a fair proxy when the prompt dominates the token count. Reasoning models invert the ratio: they emit thousands of chain-of-thought tokens per query, so nearly every forward pass the pruned model will ever run is over a token it generated itself. Calibrating on prompts alone optimizes the pruned weights for a distribution the model barely visits.The resulting failure mode is worse than a graceful accuracy drop — the pruned model rambles, emitting more thinking tokens for a less accurate answer, so pruning increases end-to-end latency. From the paper (DeepSeek-R1-Distill-Qwen-7B, MATH-500, SparseGPT @ 50% sparsity, 1M calibration tokens):
Reasoning-Aware Compression (RAC) fixes this by calibrating on the dense model's own on-policy rollout, reconstructing prompt and decode activations jointly:
The solver is untouched, so RAC is a drop-in calibration-set swap for any existing SparseGPT/Wanda workflow.
From Reasoning Models Can be Accurately Pruned Via Chain-of-Thought Reconstruction (Lucas, Behdin, Wang, Tang, Song, Mazumder; ICLR 2026). Reference implementation: RyanLucas3/Reasoning-Aware-Compression.
Why this belongs in SGLang, and what deliberately does not
Collecting the rollout is Phase I of the paper's Algorithm 1 and is the expensive half — the paper's budget is 1M on-policy CoT tokens per calibration set. That is batched autoregressive generation, which is what SGLang is for; the reference implementation does it with a Hugging Face
generateloop.The pruning solver itself is training-time code and is not proposed for
python/sglang/srt/. This PR lands as an offline recipe underexamples/usage/, matching the existingexamples/usage/modelopt_quantize_and_export.pyprecedent, and delegates the solver tollm-compressor:rac_collect_traces.pysgl.Enginesamples on-policy CoT →traces.jsonlrac_prune.pyllm-compressorruns SparseGPT/Wanda against those activationsrac_serve_and_eval.pyllmcompressoris imported lazily and is not added to SGLang's dependencies — Phases I and III need only SGLang.Also out of scope, and better as separate PRs: sparse-serving kernels (2:4 / cuSPARSELt runtime paths), and vendoring a SparseGPT solver into the engine.
Modifications
examples/usage/reasoning_aware_compression/— three scripts plus a README with full reproduction commands for the paper's DeepSeek-R1-Distill-Qwen-1.5B @ 50% row.docs/docs/advanced_features/reasoning_aware_compression.mdx, registered indocs/docs.jsonafter the quantization page.Design points worth reviewer attention:
skip_tokenizer_init=Trueand emits token ids; Phase II consumes them directly. The sequence the pruner reconstructs is exactly the one the model produced, with no detokenize/retokenize drift.--calibration-mode prompt_onlyreproduces the paper's ablation baseline from the same prompts, so the comparison motivating the method is runnable from the shipped code.llm-compressor's magnitude modifier is a gradual training-time modifier, not a one-shot solver; the README says so rather than shipping an option that cannot work.Accuracy Test
The smoke path a reviewer with a GPU can run in a few minutes:
Phase I should report a decode share well above 50%; Phase II a realized sparsity within a hair of the target.
Checklist
docs/docs/advanced_features/reasoning_aware_compression.mdx).CI States
Latest PR Test (Base): ✅ Run #31775916472
Latest PR Test (Extra): ❌ Run #31775916423