Skip to content

Add TensorQuantizer Random Hadamard rotation seed#1883

Draft
realAsma wants to merge 5 commits into
asma/tensorquantizer-rotation-modesfrom
asma/tensorquantizer-random-hadamard
Draft

Add TensorQuantizer Random Hadamard rotation seed#1883
realAsma wants to merge 5 commits into
asma/tensorquantizer-rotation-modesfrom
asma/tensorquantizer-random-hadamard

Conversation

@realAsma

@realAsma realAsma commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new feature

Adds rotate.seed to TensorQuantizer rotate config. The default seed=None preserves regular normalized Hadamard rotation. Setting an integer seed enables deterministic Random Hadamard Transform signs and uses the matching inverse order for mode="rotate_back".

This is stacked on #1879.

Usage

quant_cfg = {
    "quant_cfg": [
        {
            "quantizer_name": "*weight_quantizer",
            "cfg": {
                "num_bits": 4,
                "block_sizes": {-1: 128},
                "fake_quant": True,
                "rotate": {
                    "enable": True,
                    "mode": "rotate_back",
                    "seed": 123,
                },
            },
        },
    ],
    "algorithm": "max",
}

Use "seed": None or omit seed for regular Hadamard rotation.

Testing

  • pre-commit run --files CHANGELOG.rst modelopt/torch/quantization/config.py modelopt/torch/quantization/nn/functional.py modelopt/torch/quantization/nn/modules/tensor_quantizer.py tests/unit/torch/quantization/test_tensor_quant_cpu.py tests/gpu/torch/quantization/test_hadamard.py
  • pytest_pwd tests/unit/torch/quantization/test_tensor_quant_cpu.py::TestQuantizerAttributeConfig::test_rotate_mode_serialization tests/unit/torch/quantization/test_tensor_quant_cpu.py::test_tensor_quantizer_rotate_back_rejects_real_quant tests/unit/torch/quantization/test_tensor_quant_cpu.py::test_tensor_quantizer_rotate_mode_can_rotate_back tests/unit/torch/quantization/test_tensor_quant_cpu.py::test_tensor_quantizer_rotate_mode_preserves_default_path -q
  • ssh a8 'cd /home/scratch.akuriparambi_coreai/pr-review-branches/modelopt-tensorquantizer-random-hadamard && /home/akuriparambi/.codex/tools/pytest_pwd tests/gpu/torch/quantization/test_hadamard.py::test_hadamard_transform_seeded_inverse -q'

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: ✅
  • Did you get Claude approval on this PR?: N/A, draft PR

Additional Information

Stacked on #1879.

@copy-pr-bot

copy-pr-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6006f699-8a1a-4443-b9a5-30425d8240d9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch asma/tensorquantizer-random-hadamard

Comment @coderabbitai help to get the list of available commands.

@realAsma realAsma force-pushed the asma/tensorquantizer-rotation-modes branch 2 times, most recently from 960716f to f5451f2 Compare July 4, 2026 13:02
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.

1 participant