HIGGS: ILP-based mixed-precision quantization - #3028
Conversation
Add HIGGS (Heuristic ILP-Guided Grouped Scheme) module for automatic mixed-precision quantization. Uses per-layer MSE sensitivity analysis and integer linear programming to assign optimal quantization schemes per layer while respecting average bitwidth constraints. Key components: - Model-free MSE collection via compressed-tensors converter pipeline - ILP solver with fused-layer constraints and dual weight/activation budgets - Depth-based alpha heuristic for layer importance weighting - Two-phase pipeline: MSE collection + ILP solve, then quantization - Support for WNaM activation quantization schemes (W2A4..W8A16) Also fixes transposed MoE expert tensor handling (e.g. Llama-4) in split_fused_moe_experts and adds pulp dependency for ILP solving. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews
🔴 Require one maintainer reviewWaiting for any of
This rule is failing.All PRs must have at least one approving review from a maintainer before merging.
|
|
The quality checks have failed. Please run |
Includes module-level README with API reference and architecture overview, examples README with usage guide, and detailed alpha heuristic analysis with cross-model validation results and activation quantization findings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces HIGGS, an ILP-based mixed-precision quantization framework, along with example scripts for quantization, perplexity measurement, and activation sweeps. It also updates MoE expert splitting to support transposed expert formats. Key feedback includes making the MoE transposition detection robust to sharded checkpoints by checking both gate_up_proj and down_proj shapes, fixing a bug in the perplexity script where prompt_logprobs=0 prevents logprob retrieval, and avoiding numerical instability in the ILP solver by explicitly constraining invalid schemes to zero instead of using a large penalty coefficient.
| is_transposed = False | ||
| for name, tensor in tensors.items(): | ||
| if "gate_up_proj" in name and tensor.ndim == 3: | ||
| is_transposed = tensor.shape[2] > tensor.shape[1] | ||
| break |
There was a problem hiding this comment.
In a sharded checkpoint, gate_up_proj and down_proj tensors for MoE experts are often split across different files (shards). If a shard only contains down_proj and not gate_up_proj, the current detection logic will fail to find gate_up_proj in tensors, defaulting is_transposed to False. This will cause down_proj to be split incorrectly or fail with a shape mismatch. We can make the transposition detection robust to sharding by checking the shapes of both gate_up_proj (where dim2 > dim1 indicates transposition) and down_proj (where dim1 > dim2 indicates transposition).
| is_transposed = False | |
| for name, tensor in tensors.items(): | |
| if "gate_up_proj" in name and tensor.ndim == 3: | |
| is_transposed = tensor.shape[2] > tensor.shape[1] | |
| break | |
| is_transposed = False | |
| for name, tensor in tensors.items(): | |
| if tensor.ndim == 3: | |
| if "gate_up_proj" in name: | |
| is_transposed = tensor.shape[2] > tensor.shape[1] | |
| break | |
| elif "down_proj" in name: | |
| is_transposed = tensor.shape[1] > tensor.shape[2] | |
| break |
| sampling_params = SamplingParams( | ||
| max_tokens=1, | ||
| temperature=0.0, | ||
| prompt_logprobs=0, | ||
| ) |
There was a problem hiding this comment.
Setting prompt_logprobs=0 in SamplingParams prevents vLLM from computing and returning prompt logprobs. As a result, output.prompt_logprobs will be None, causing the perplexity evaluation loop to skip all tokens and fail to compute perplexity (or divide by zero). To enable prompt logprob retrieval, prompt_logprobs must be set to >= 1 (typically 1 is sufficient to get the logprob of the actual token).
| sampling_params = SamplingParams( | |
| max_tokens=1, | |
| temperature=0.0, | |
| prompt_logprobs=0, | |
| ) | |
| sampling_params = SamplingParams( | |
| max_tokens=1, | |
| temperature=0.0, | |
| prompt_logprobs=1, | |
| ) |
| # Skip if MSE is infinite (scheme not applicable to this layer) | ||
| if mse == float('inf'): | ||
| # Force this variable to 0 by adding very high cost | ||
| objective_terms.append(1e10 * x[layer][scheme]) | ||
| else: | ||
| objective_terms.append(mse * alpha * x[layer][scheme]) |
There was a problem hiding this comment.
Using a very large penalty coefficient like 1e10 in the objective function to force variables to zero can cause numerical instability and scaling issues in the ILP solver (PuLP/CBC). A much more robust and numerically stable approach is to add a constraint fixing the variable to 0 (i.e., x[layer][scheme] == 0) for any invalid/inapplicable schemes.
| # Skip if MSE is infinite (scheme not applicable to this layer) | |
| if mse == float('inf'): | |
| # Force this variable to 0 by adding very high cost | |
| objective_terms.append(1e10 * x[layer][scheme]) | |
| else: | |
| objective_terms.append(mse * alpha * x[layer][scheme]) | |
| # Skip if MSE is infinite (scheme not applicable to this layer) | |
| if mse == float('inf'): | |
| prob += (x[layer][scheme] == 0, f"InvalidScheme_{_sanitize_name(layer)}_{scheme}") | |
| else: | |
| objective_terms.append(mse * alpha * x[layer][scheme]) |
|
The quality checks have failed. Please run |
Summary
split_fused_moe_expertsArchitecture
Key experimental findings
Test plan
pytest tests/llmcompressor/transformers/compression/higgs/python examples/quantization_higgs/llama3_higgs_example.pyilp_quantize(..., quantize=False)returns config without applying quantization🤖 Generated with Claude Code