Skip to content
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

Add NearSwap #480

Merged
merged 13 commits into from
Jan 25, 2025
Merged

Add NearSwap #480

merged 13 commits into from
Jan 25, 2025

Conversation

popbyte
Copy link
Contributor

@popbyte popbyte commented Jan 5, 2025

NearSwap Algorithm

NearSwap retains most of the weights of the base model, but when a weight is similar between the two, it is interpolated to the secondary model value. A parameter t specifies the sameness threshold. When the distance between two values is below t, the weight from the secondary model is used.

This PR implements the NearSwap algorithm from here

@popbyte popbyte marked this pull request as draft January 5, 2025 06:08
@popbyte popbyte marked this pull request as ready for review January 5, 2025 06:47
@popbyte
Copy link
Contributor Author

popbyte commented Jan 5, 2025

CI should now pass, please review

1) Undo functional changes to nearswap in commit 905c328 - the t / lweight step is necessary for this to make sense.
2) All in pytorch to avoid unnecessary CPU-GPU transfer.
3) added minor detail to error messages
@ElliotStein
Copy link
Contributor

Thanks for the PR! I’ve made a couple of changes:
1. I swapped out NumPy for PyTorch to avoid unnecessary CPU-GPU data transfers.
2. I restored the lweights = t / lweights line, which I believe is necessary since the t parameter wasn’t being used otherwise.

This looks like a solid implementation of the algorithm described at QuartetAnemoi-70B-t0.0001.

To clarify the algorithm (Given base_model and secondary_model):
• Use weights from secondary_model directly when they are close to those in base_model (within threshold t).
• Interpolate between base_model and secondary_model otherwise, with t/abs(V0-V1) as the scaling parameter.
• The further apart the weights are, the more the interpolation favours the base_model

Is that understanding correct?

@popbyte
Copy link
Contributor Author

popbyte commented Jan 7, 2025

  1. I restored the lweights = t / lweights line, which I believe is necessary since the t parameter wasn’t being used otherwise

Oops, that was accidentally removed.

Is that understanding correct?

Yes.

@cg123
Copy link
Collaborator

cg123 commented Jan 25, 2025

Thanks for the PR! I've updated it to work with the new merge method registry.

@cg123 cg123 merged commit 84c83f8 into arcee-ai:main Jan 25, 2025
4 checks passed
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.

3 participants