Core Space Merging Algorithm | Feature Request#646
Core Space Merging Algorithm | Feature Request#646kishore-s-15 wants to merge 10 commits intoarcee-ai:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
- 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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| # Don't treat separate lora_A/lora_B as LoRA - they need to be paired | ||
| # which we can't do in this single-tensor context | ||
| # We only handle full merged models that were LoRA-adapted | ||
| return False # For now, treat all as full weights |
There was a problem hiding this comment.
Unused _is_lora_weight method is dead code
Low Severity
The _is_lora_weight method is defined but never called anywhere in the codebase. It always returns False with a comment "For now, treat all as full weights". Since no code path invokes this method, it adds unnecessary complexity and could confuse future maintainers about the intended design.
|
Hi @cg123, |
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
Adds a new SVD-aligned LoRA merging method that operates in a compact core subspace, plus docs, example, tests, and registry wiring.
core_spacemerge method (mergekit/merge_methods/core_space.py) with low-rank SVD projection, core-space averaging, and fallback to weighted deltasmerge_methods/registry.py; no changes to existing methodsdocs/merge_methods.md), including usage, parameters, and referenceexamples/core_space.ymltests/test_core_space.pycovering SVD bases, low-rank approximation, projection/reconstruction, parameter handlingWritten by Cursor Bugbot for commit 58d750b. This will update automatically on new commits. Configure here.