Repository navigation
Find decoder layers through PEFT wrappers and other layouts - #20
Merged
Merged
Conversation
Steering, residual-norm calibration and extraction hooked model.model.layers directly, which a PEFT-wrapped model (e.g. one carrying an Afterlife LoRA) doesn't have. modulo.layers.decoder_layers unwraps PEFT and tries the usual paths, then falls back to the ModuleList matching num_hidden_layers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
Steering, residual-norm calibration and extraction hooked
model.model.layersdirectly. A PEFT-wrapped model (e.g. one carrying an Afterlife LoRA adapter) doesn't have that path:peft_model.modelis the*ForCausalLM, so its layers are atpeft_model.model.model.layers, and the first steered turn (orcreate) raisesAttributeError. Found while running Modulo and Afterlife together in habitat.What
modulo/layers.py:unwrap()goes through PEFT viaget_base_model().decoder_layers()triesmodel.layers, the multimodallanguage_modellayouts, OPT,transformer.handgpt_neox.layers, in that order. If none match, it falls back to theModuleListas long asnum_hidden_layers. If that fails too, it raises a clear error.num_layers()reads the config, including multimodaltext_config.agent.py,extraction.pyandcli.pynow use the helpers instead ofmodel.model.layers/config.num_hidden_layers.Plain models are unaffected:
model.layersis tried first.Testing
tests/test_layers.pycovers:curiosity +4during the same turn. It answered with the adapter's trained fact, with steering active.🤖 Generated with Claude Code