Repository navigation
<
7438
/div>Refactor PEFT to use post-linear lifecycle hooks (
Refactor PEFT to use post-linear lifecycle hooks (peft_adapter) - #469
Merged
Merged
Conversation
…ions. Added `ml/layers/hooks.go` defining the `PostLinearHook` for after-linear projections. Updated documentation.
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.
Description
This PR refactors the PEFT (Parameter-Efficient Fine-Tuning) API to operate as a meta-layer via post-linear lifecycle hooks rather than requiring manual projection replacements.
A follow up to #466
Key Changes
ml/layers/hooks.go):PostLinearHook(func(scope *model.Scope, input, output *Node) *Node).RegisterPostLinearHook(priority, hook)with priority-based sorting and thread-safe registration.ApplyPostLinearHooksandClearPostLinearHooks.layers.DenseWithLayout: Dispatches post-linear hooks immediately afternn.Dense.fnn.Done(): Dispatches post-linear hooks after each layer's linear projection, before non-linearities (activation/dropout/normalization/residual).attention.MultiHeadAttention: Delegates query, key, value, and output projections throughlayers.DenseWithLayout, routing them through the hooks automatically.ml/layers/peft):init()withHookPriorityDefault.peft_adapter: Activates LoRA with adapter sub-scope name (e.g.,scope.In(adapterName)/A,B). If empty (""), PEFT is inactive with zero overhead.peft_adapterto"off","disabled","false", or"none"freezes base weights without creating adapters.peft_target_modules(comma-separated or[]string) filters matching module scopes; unmatched linear layers are frozen without adapters.model.Storeunder their respective sub-scopes.docs/peft.mdwith usage, CLI-setparameters, multi-adapter patterns, and a Developer Guide..agents/AGENTS.mdand.agents/skills/golang-gomlx/.ml/layers/hooks_test.go.ml/layers/peft/peft_test.gocovering FNN, Dense, and MultiHeadAttention with LoRA, target module filtering, freeze-only mode, and multi-adapter switching.