Skip to content

Conversation

@GOavi101
Copy link
Contributor

@GOavi101 GOavi101 commented Dec 11, 2025

  • Add comprehensive test suite comparing MSE and MinMax observers
  • Test on random tensors with various distributions
  • Test on real model weights from transformers
  • Add 'slow' pytest marker to pyproject.toml for long-running tests

#2094

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GOavi101, 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 robust set of tests designed to evaluate and compare the quantization error produced by MSE and MinMax observers. The primary objective is to ensure that the MSE observer consistently delivers equal or superior quantization quality across a wide range of data distributions, from synthetic tensors to real-world model weights. This enhancement is crucial for validating the effectiveness of the MSE observer in optimizing model compression.

Highlights

  • New Test Suite for Observers: A comprehensive test suite has been added to compare the performance of MSE (Mean Squared Error) and MinMax observers in quantization.
  • Diverse Test Scenarios: The tests cover various scenarios, including random tensors with different distributions, tensors of various shapes, and tensors with extreme values.
  • Real Model Weight Testing: The suite includes tests on actual model weights extracted from transformers models to validate observer behavior on realistic data.
  • Pytest 'slow' Marker: A new 'slow' pytest marker has been introduced in pyproject.toml to categorize long-running tests, such as those involving model downloads.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

- Add comprehensive test suite comparing MSE and MinMax observers
- Test on random tensors with various distributions
- Test on real model weights from transformers
- Add 'slow' pytest marker to pyproject.toml for long-running tests

Signed-off-by: Avishek Goswami <[email protected]>
@GOavi101 GOavi101 force-pushed the add-mse-vs-minmax-tests branch from 5421f26 to 5352b1c Compare December 11, 2025 04:45
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive test suite to compare the performance of MSE and MinMax observers for quantization. The tests cover random tensors with various distributions, different tensor shapes, extreme values, and real model weights, which is great for ensuring robustness.

I've found a couple of critical issues related to shape mismatches when assigning weights to test modules, which would cause tests to fail. I've also pointed out a minor case of dead code. After addressing these points, the PR should be in good shape.

- Fix tensor shape mismatch: use tensor directly instead of tensor.T
- Fix weight_tensor shape mismatch: use weight_tensor directly instead of weight_tensor.T
- Remove unused weights variable in test_mse_vs_minmax_extreme_values

Signed-off-by: Avishek Goswami <[email protected]>
@github-actions
Copy link

👋 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.

@GOavi101
Copy link
Contributor Author

pytest tests/llmcompressor/observers/test_mse_vs_minmax.py -
v
============================================== test session starts ==============================================
platform darwin -- Python 3.13.11, pytest-9.0.1, pluggy-1.6.0 -- /Users/avishek/llm_comp/llm-compressor/venv/bin/python3.13
cachedir: .pytest_cache
rootdir: /Users/avishek/llm_comp/llm-compressor
configfile: pyproject.toml
plugins: mock-3.15.1, anyio-4.12.0, rerunfailures-16.1
collected 33 items                                                                                              

tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-tensor-True-8] PASSED [  3%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-tensor-False-8] PASSED [  6%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-channel-True-8] PASSED [  9%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-channel-False-8] PASSED [ 12%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-tensor_group-True-4] PASSED [ 15%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-tensor_group-False-4] PASSED [ 18%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-channel-True-4] PASSED [ 21%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[narrow-channel-False-4] PASSED [ 24%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-tensor-True-8] PASSED [ 27%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-tensor-False-8] PASSED [ 30%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-channel-True-8] PASSED [ 33%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-channel-False-8] PASSED [ 36%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-tensor_group-True-4] PASSED [ 39%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-tensor_group-False-4] PASSED [ 42%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-channel-True-4] PASSED [ 45%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[medium-channel-False-4] PASSED [ 48%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-tensor-True-8] PASSED [ 51%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-tensor-False-8] PASSED [ 54%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-channel-True-8] PASSED [ 57%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-channel-False-8] PASSED [ 60%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-tensor_group-True-4] PASSED [ 63%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-tensor_group-False-4] PASSED [ 66%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-channel-True-4] PASSED [ 69%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_random_tensor[wide-channel-False-4] PASSED [ 72%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_various_shapes[tensor_shape0] PASSED [ 75%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_various_shapes[tensor_shape1] PASSED [ 78%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_various_shapes[tensor_shape2] PASSED [ 81%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_various_shapes[tensor_shape3] PASSED [ 84%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_extreme_values PASSED             [ 87%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_real_model_weights[channel-True-8] PASSED [ 90%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_real_model_weights[channel-False-8] PASSED [ 93%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_real_model_weights[tensor_group-True-4] PASSED [ 96%]
tests/llmcompressor/observers/test_mse_vs_minmax.py::test_mse_vs_minmax_on_real_model_weights[tensor_group-False-4] PASSED [100%]

============================================== 33 passed in 5.70s ===============================================

Total: 33 test cases - All showing MSE observer produces quantization error ≤ MinMax observer's quantization error.

Copy link
Collaborator

@kylesayrs kylesayrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants