-
Notifications
You must be signed in to change notification settings - Fork 639
Core Space Merging Algorithm | Feature Request #646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Core Space Merging Algorithm | Feature Request #646
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
- Fix: Ensure rank >= 1 to prevent degenerate matrices - Fix: Remove incorrect lora_A/lora_B identity pairing - Fix: Update tests to match concatenation implementation - Clarify: Works with full models, not separate lora weight files - Add: Test for zero rank edge case - Update: Documentation to explain model requirements
- Fix: Ensure rank >= 1 (prevent zero rank bug) - Fix: Remove incorrect lora_A/lora_B pairing logic - Fix: Apply weight parameter as global scaling factor - Clarify: Equal weighting in core space is architectural constraint - Update: Tests to match implementation - Update: Documentation to accurately describe behavior
Critical fixes: - Fix: Exclude base model from weighted average (task vector approach) - Fix: Apply weight parameter as global scaling factor - Fix: Ensure rank >= 1 to prevent degenerate matrices - Add: Test for base model exclusion in averaging - Update: Documentation to clarify weight parameter behavior The weighted average now correctly computes task vectors, averages them, then adds back to base - matching task arithmetic principles.
Add Core Space Merge Method
Summary
This PR adds the Core Space merge method to mergekit, implementing the algorithm from "Accurate and Efficient Low-Rank Model Merging in Core Space" (Panariello et al., NeurIPS 2025).
Core Space enables efficient merging of LoRA-adapted models by operating in a compact, SVD-aligned subspace, providing significant computational savings while guaranteeing information preservation.
Motivation
LoRA (Low-Rank Adaptation) has become a popular technique for parameter-efficient fine-tuning. However, existing merge methods in mergekit operate in full parameter space, which:
Core Space addresses these issues by:
Changes Made
New Files
1.
mergekit/merge_methods/core_space.py(~300 lines)Complete implementation of the Core Space algorithm:
Classes:
CoreSpaceMerge(MergeMethod)- Main merge method classCoreSpaceTask(Task[torch.Tensor])- Task execution classKey Methods:
_compute_reference_bases()- Computes U_B and V_A via SVD on concatenated LoRA matrices_extract_lora_matrices()- Extracts or approximates A and B matrices from models_core_space_merge()- Projects to core space, merges, and reconstructs_weighted_average()- Fallback for non-LoRA weightsAlgorithm:
2.
tests/test_core_space.py(10 tests)Comprehensive test suite covering:
All tests are passing.
3.
examples/core_space.ymlExample configuration demonstrating basic usage with multiple LoRA adapters.
Configuration
Basic usage:
References
Paper:
Original Implementation: https://github.com/apanariello4/core-space-merging
Note
Introduces the Core Space (
core_space) merge method for SVD‑aligned LoRA merging, registers it, and adds documentation, example config, and unit tests.CoreSpaceMergewithCoreSpaceTaskinmergekit/merge_methods/core_space.pyimplementing SVD‑aligned core‑space merging with fallback weighted average; exposesweightparameter and reference URL.mergekit/merge_methods/registry.py.README.mdmethod table to includeCore Spaceentry.docs/merge_methods.mdwith a new Core Space section (concept, algorithm, inputs/params, example, reference).examples/core_space.ymldemonstrating configuration.tests/test_core_space.pycovering initialization, SVD bases, low‑rank approximation, core‑space projection, parameter handling, multi‑adapter merge simulation, and edge cases.Written by Cursor Bugbot for commit 94c2baf. This will update automatically on new commits. Configure here.