Skip to content

add blockwise rotation. - #2087

Open
lkk12014402 wants to merge 3 commits into
intel:mainfrom
lkk12014402:blockwise-rotation
Open

add blockwise rotation.#2087
lkk12014402 wants to merge 3 commits into
intel:mainfrom
lkk12014402:blockwise-rotation

Conversation

@lkk12014402

@lkk12014402 lkk12014402 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description

This change adds block-wise (layer-wise) rotation to AutoRound's QuaRot/SpinQuant
rotation quantization, enabling rotation to be applied per decoder block, in lock-step
with AutoRound's block-wise quantization
, instead of rotating the whole model up front.

Enabled via a single top-level switch:

AutoRound(model, scheme="MXFP4", rotation_config="quarot", layerwise_rotation=True)

Motivation

The standard QuaRot/SpinQuant flow rotates the entire model first (R1 fused into
embedding/all linears, R2 into attention, R3/R4 as online hooks), then quantizes. This:

  • requires the whole model to be resident in memory at once (heavy for large models), and
  • is decoupled from AutoRound's block-wise quantization pipeline.

Block-wise rotation aligns rotation with block-wise quantization so only one block needs
to be on-device at a time.

Signed-off-by: lkk12014402 <kakao.lv@intel.com>
@lkk12014402

Copy link
Copy Markdown
Contributor Author

Accuracy results — Qwen3-8B · MXFP4 (RTN, iters=0) · PIQA

# Config rotation_config layerwise acc acc_norm
1 MXFP4 baseline 0.7312 0.7454
2 Hadamard "hadamard" 0.7416 0.7601
3 random-Hadamard {"algorithm":"hadamard","hadamard_type":"random_hadamard"} 0.7541 0.7753
4 QuaRot R1R2 "quarot" 0.7437 0.7508
5 QuaRot R1R2R3R4 {"algorithm":"spinquant","r1..r4":true} 0.7312 0.7394
6 block-wise QuaRot R1R2 "quarot" 0.7437 0.7508
7 block-wise QuaRot R1R2R3R4 {"algorithm":"spinquant","r1..r4":true} 0.7312 0.7394

@wenhuach21

Copy link
Copy Markdown
Contributor

Could you help move hadamard's entry (apply_rotation) to composer.py, I guess placing it in prepare_run function is doable https://github.com/intel/auto-round/blob/main/auto_round/algorithms/composer.py#L542

# Block Lifecycle Hooks (layer-wise / block-wise rotation)
# ------------------------------------------------------------------

def _on_block_ready(self, block: torch.nn.Module, block_name, block_idx: int) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better follow the new arch and move the rotation func to rotation folder

m, _, _ = self.alg_composer.dispatch_block(m, input_ids, input_others)

# ── Layer-wise rotation: rotate this block before reference collection ──
self._on_block_ready(m, block_name_or_names, i)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please follow the architecture to decouple the different algorithms. You can discuss with Heng how to support this feature with less coupling.

memory_monitor.log_summary()
pbar.update(1)

self._finalize_block_processing(self.model)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

similar issue

@wenhuach21

Copy link
Copy Markdown
Contributor

Also, please fix this issue ASAP: #2036. It's a critical issue that should be prioritized.

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