Skip to content

basic knot merging #140

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

basic knot merging #140

wants to merge 4 commits into from

Conversation

oleksost
Copy link
Contributor

@oleksost oleksost commented Nov 13, 2024

  • added Knot merging for LoRAs from https://arxiv.org/pdf/2410.19735
  • currently Vs are merged with uniform Ties merging method without weights
  • the Knot ingredients (SVD components) are stored in a local file, in the future they probably should be stored in the library. Now, aux data in the lib must be associated with expert, Knot components are not expert specific.

@oleksost oleksost requested a review from sordonia November 13, 2024 16:34
@sordonia sordonia requested a review from Copilot June 6, 2025 00:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Knot merging transform for LoRA experts, computing SVD components, storing them locally, and merging expert weights uniformly via TIES.

  • Added KnotMerge and KnotMergeConfig to perform SVD-based merges.
  • Updated TiesMerge to factor out parameter-merging logic into merge_param.
  • Added a test_knot_merge unit test to validate the new transform.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_library_transforms.py Added test_knot_merge to verify the KnotMerge flow.
mttl/models/library/library_transforms.py Implemented KnotMerge transform and refactored TiesMerge.
Comments suppressed due to low confidence (3)

mttl/models/library/library_transforms.py:11

  • Add import torch at the top of this file so that all references to torch.save, torch.load, and other torch APIs resolve correctly.
from typing import Dict, List, Union

mttl/models/library/library_transforms.py:361

  • [nitpick] Rename the variable ties_mergert to ties_merger to fix the typo and clarify its purpose.
        ties_mergert = TiesMerge()

tests/test_library_transforms.py:96

  • [nitpick] Consider adding assertions to verify that the merged weights themselves match expected values (e.g., compare against a manual U @ final_param calculation) to improve test coverage.
    assert len(merged_layers) == len(exp.expert_weights.keys()) == 1

@LibraryTransform.register("weighted_knot_merge", KnotMergeConfig)
class KnotMerge(LibraryTransform):
"""
Computes a weighted KnoT merge for LoRA ezperts as in https://arxiv.org/pdf/2410.19735
Copy link
Preview

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the typo ezperts to experts in the docstring.

Suggested change
Computes a weighted KnoT merge for LoRA ezperts as in https://arxiv.org/pdf/2410.19735
Computes a weighted KnoT merge for LoRA experts as in https://arxiv.org/pdf/2410.19735

Copilot uses AI. Check for mistakes.

used += keep_mask.sum().item()
else:
# sign majority vote
sign_per_dim = expert_weights.sign().sum(0, keepdim=True).sign()
Copy link
Preview

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second assignment to sign_per_dim overrides the first; remove the redundant line or clarify which operation is intended.

Suggested change
sign_per_dim = expert_weights.sign().sum(0, keepdim=True).sign()

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant