From eb1f0746ddb1c93adf7c5e8637797b49f6782d77 Mon Sep 17 00:00:00 2001 From: ktiwang Date: Wed, 27 May 2026 21:09:17 +0800 Subject: [PATCH] fix(spin): fix tied embedding corruption in silent_run() and unconditional untie/fuse in run() - Move _untie_word_embeddings() to unconditional top of silent_run() (was missing entirely) - Move _untie_word_embeddings() and _apply_fused_ln() outside 'if R1' condition in run() - Remove duplicate _untie_word_embeddings() call from _apply_fused_ln() This fixes embedding lookup table corruption when tie_word_embeddings=True (affects Qwen3 and all models with tied embeddings). --- angelslim/compressor/transform/rotation/spin.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/angelslim/compressor/transform/rotation/spin.py b/angelslim/compressor/transform/rotation/spin.py index 23ecc98f..72a270b7 100644 --- a/angelslim/compressor/transform/rotation/spin.py +++ b/angelslim/compressor/transform/rotation/spin.py @@ -156,6 +156,7 @@ def _get(key, default): def silent_run(self): """only set linears and Rotations""" + self._untie_word_embeddings() self._apply_fused_ln() if "R1" in self.spin_config.rotation: self._apply_r1(no_transform=True) @@ -167,11 +168,11 @@ def silent_run(self): self._apply_r4(no_transform=True) def run(self): + self._untie_word_embeddings() + # fuse norm + self._apply_fused_ln() # add rotation if "R1" in self.spin_config.rotation: - self._untie_word_embeddings() - # fuse norm - self._apply_fused_ln() self._apply_r1() if "R2" in self.spin_config.rotation: self._apply_r2() @@ -389,8 +390,6 @@ def _apply_fused_ln(self): """ self.logger.info("Applying fused layer norm to a linear layer") - self._untie_word_embeddings() - norm_layers = self.quant_model.get_rotation_mapping_layers( None, norm_mapping=self.norm_mapping,