Conversation
…tself _patch_layer_norm_module bound LigerLayerNorm.forward/extra_repr onto the PEFT ModulesToSaveWrapper, bypassing PEFT's adapter dispatch, and set hidden_size on the wrapper and (twice) on original_module but never on modules_to_save.default - so repr() of a patched model raised AttributeError. Mirror _patch_rms_norm_module: patch only modules_to_save.default and original_module, and set hidden_size on both.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The PEFT branch of
_patch_layer_norm_module(src/liger_kernel/transformers/monkey_patch.py:103) diverges from its_patch_rms_norm_modulesibling in three ways, all defects:LigerLayerNorm.forward/extra_repronto theModulesToSaveWrapperitself. The instance-levelforwardshadows PEFT's_forward_wrappeddispatch (which routes to the trainablemodules_to_save.defaultcopy when adapters are enabled, and tooriginal_moduleunderdisable_adapters), silently breaking PEFT semantics. The RMSNorm branch from the same PR correctly leaves the wrapper untouched.hidden_sizeis set on the wrapper and (twice) onoriginal_module, but never onmodules_to_save.default— yetextra_repr(which readsself.hidden_size) is bound to it, sorepr()/print()of a patched model raisesAttributeError: 'LayerNorm' object has no attribute 'hidden_size'.original_module.hidden_sizeassignment is dead weight.The branch is reached whenever
apply_liger_kernel_to_*(model=...)patches a LayerNorm wrapped by a PEFT config'smodules_to_save(e.g. vision-tower layernorms in mllama/InternVL/SmolVLM-style setups). It was introduced by #632 (which fixed #631 for the RMSNorm path) and has zero test coverage —grep -c peft test/transformers/test_monkey_patch.pyon main is 0.Fix
Mirror
_patch_rms_norm_module: patch onlymodules_to_save.defaultandoriginal_module, sethidden_sizeon both, and leave the wrapper'sforwardalone so PEFT's adapter dispatch stays intact. Net −3 lines in src. Adds a regression test covering the PEFT wrapper path, including the invariant that"forward" not in wrapper.__dict__.Verification
Executed on CPU (WSL, torch 2.13, transformers 4.56.2, peft 0.20.0):
AttributeError: 'LayerNorm' object has no attribute 'hidden_size'onprint(wrapper), and the wrapper's__dict__carries the shadowingforward.test/transformers/test_monkey_patch.pypasses — 44 passed, 19 skipped, 0 failed.ruff checkandruff formatclean.Disclosure: the GPU kernel suite (
make test) and convergence tests were not run — no GPU on this box. The change touches only patch-time attribute/binding structure, no kernel code.