Conversation
Adds a new Developer Tutorials section with three tutorials: - Adding a New Modifier: covers the modifier lifecycle, Pydantic params, HooksMixin, and a concrete WeightClampModifier example - Adding a New Observer: covers the Observer contract, stateful observers, and a PercentileObserver example with recipe usage - Adding MoE Model Support: covers MoECalibrationModule, the calibration forward pattern, and a step-by-step guide referencing the GLM-4.7 example Also adds the section to .nav.yml between User Guides and Examples. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
👋 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. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the project's documentation by adding a dedicated "Developer Guides" section. This new section provides essential resources for contributors looking to extend the LLM Compressor framework, covering key areas such as implementing custom modifiers, creating new observers for quantization, and integrating support for Mixture of Experts (MoE) models. The guides offer in-depth explanations of core contracts, lifecycles, and practical examples to facilitate easier and more effective contributions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
…ew Model" Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces new developer tutorials for LLM Compressor, covering how to add custom Modifiers, Observers, and support for MoE models. The documentation updates include new markdown files and navigation links. Review feedback suggests improving the clarity of lifecycle hook descriptions in the modifier tutorial, defining the ds variable in the MoE example, and optimizing the get_min_max implementation in the observer tutorial for efficiency and robustness.
| return True | ||
|
|
||
| def on_start(self, state: State, event: Event, **kwargs): | ||
| # Called when calibration starts (first BATCH_START event). |
There was a problem hiding this comment.
The comment here is slightly misleading. on_start is not necessarily called on the first BATCH_START event of calibration, but rather on the first BATCH_START event for which the modifier becomes active (i.e., when event.current_index >= self.start). For better clarity, I suggest changing the comment.
| # Called when calibration starts (first BATCH_START event). | |
| # Called on the BATCH_START event when the modifier's `start` step is reached. |
| ... | ||
|
|
||
| def on_end(self, state: State, event: Event, **kwargs): | ||
| # Called when calibration ends. |
There was a problem hiding this comment.
Similar to on_start, the comment for on_end could be more precise. It's triggered when the modifier's end step is reached, on a BATCH_END event. I suggest updating the comment for accuracy.
| # Called when calibration ends. | |
| # Called on the BATCH_END event when the modifier's `end` step is reached. |
|
|
||
| oneshot( | ||
| model=model, | ||
| dataset=ds, |
There was a problem hiding this comment.
| min_vals = torch.tensor( | ||
| [ | ||
| torch.quantile(observed[..., i], lower / 100.0).item() | ||
| for i in range(observed.shape[-2]) | ||
| ] | ||
| ) | ||
| max_vals = torch.tensor( | ||
| [ | ||
| torch.quantile(observed[..., i], upper / 100.0).item() | ||
| for i in range(observed.shape[-2]) | ||
| ] | ||
| ) |
There was a problem hiding this comment.
The current implementation of get_min_max uses a list comprehension, which can be inefficient and is not robust for multi-dimensional qparam_shape. A vectorized approach using torch.quantile directly on a reshaped tensor would be more idiomatic, performant, and correct.
Consider replacing the logic for computing min_vals and max_vals with the following:
# Vectorized implementation for efficiency and correctness with multi-dimensional qparam_shape
# The observed tensor has shape (num_observations, *qparam_shape, group_size)
qparam_shape_len = len(observed.shape) - 2
# Permute to bring qparam_shape dimensions to the front, then flatten observation and group dims
permute_dims = list(range(1, 1 + qparam_shape_len)) + [0, qparam_shape_len + 1]
reshaped = observed.permute(*permute_dims).flatten(start_dim=qparam_shape_len)
min_vals = torch.quantile(reshaped, lower / 100.0, dim=-1)
max_vals = torch.quantile(reshaped, upper / 100.0, dim=-1)Replaces the GLM-4.7 reference with the Llama4 implementation as the canonical example. Updates the forward pattern, contract section, and step-by-step to reflect Llama4-specific details including packed expert unpacking, is_permanent=True, shared_expert handling, and router score application to expert outputs rather than inputs. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…e/zp Clarifies that observers return min and max values, which are then passed to calculate_qparams and generate_gparam in compressed-tensors to produce scale and zero_point. Adds a section explaining how the base class uses observer output, and updates the example docstring and tips accordingly. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…vers - Correct: observers compute min/max values, not scale/zero_point directly; compressed-tensors calculate_qparams/generate_gparam handle that conversion - Fix base class description: correct method names (get_min_max, get_global_min_max) and accurate description of what the base class handles - Document all observer variants: memoryless_minmax, static_minmax, minmax, memoryless_mse, mse (previously only MinMax and MSE were mentioned) - Split observer_kwargs table by observer type with accurate defaults Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Summary
Adds a new Developer Guides section to the docs for contributors extending LLM Compressor:
on_initialize,on_start,on_update,on_end,on_finalize), Pydantic parameter declaration,HooksMixinusage, and a concreteWeightClampModifierwalkthroughcompressed-tensorscalculate_qparamsandgenerate_gparamconsume those values, covers theObservercontract, stateful observers, and aPercentileObserverexample with recipe usageMoECalibrationModulecontract, and a step-by-step guide usingSequentialLlama4TextMoeas the canonical reference. Covers Llama4-specific patterns: packed expert unpacking via a helperModuleList,is_permanent=Truefor vLLM compatibility,shared_experthandling, and applying routing scores to expert outputs (not inputs) to avoid NaNs during calibrationAlso updates
.nav.ymlto add the new section between User Guides and Examples.Updates the existing User Guides:
guides/observers.md) — corrects observer descriptions (min/max values, not scale/zero_point), fixes base class method names, documents all previously undocumented observer variants (memoryless_minmax,static_minmax,memoryless_mse), and splitsobserver_kwargstable by observer type with accurate defaults🤖 Generated with Claude Code