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

Scalar multiplication #355

Merged

Conversation

matthiasdellago
Copy link
Contributor

Description

Implemented mul and rmul for Factoredmatrix to support scalar multiplication with *.
Supports floats, ints and single-element Tensors.
Approriate error messages and test are in place.

Fixes #348

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@neelnanda-io
Copy link
Collaborator

Thanks! It feels a bit inelegant to arbitrarily multiply the matrix on the right (rather than the left, or sqrt(scalar) on both), but it's probably best as is - users aren't supposed to use individual components of the factoredmatrix in general, and this avoids numerical errors of sqrt.

I left some nits, but overall LGTM

@neelnanda-io
Copy link
Collaborator

neelnanda-io commented Jul 23, 2023

Looks like you have some formatting errors

@matthiasdellago
Copy link
Contributor Author

Thanks! It feels a bit inelegant to arbitrarily multiply the matrix on the right (rather than the left, or sqrt(scalar) on both), but it's probably best as is - users aren't supposed to use individual components of the factoredmatrix in general, and this avoids numerical errors of sqrt.

Agreed. Aside from the numerical error my main resoning was to reduce the amount of computation required.

Looks like you have some formatting errors

Yes, I forgot to set up my development environment properly. I'm on it.

@matthiasdellago
Copy link
Contributor Author

Resolved the nits, and fixed the formatting. 👍
Thanks for making TransformerLens btw, i really enjoy using it! :)

@jbloomAus
Copy link
Collaborator

Thanks!

@jbloomAus jbloomAus merged commit 090081f into TransformerLensOrg:main Jul 26, 2023
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.

[Proposal] Scalar Multiplication * for FactoredMatrix
3 participants