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

No copy gems #801

Merged
merged 8 commits into from Mar 12, 2024
Merged

No copy gems #801

merged 8 commits into from Mar 12, 2024

Conversation

jagrit06
Copy link
Member

@jagrit06 jagrit06 commented Mar 7, 2024

Proposed changes

  • Collapse batch dimensions in gemm
  • Update gemm to only make copies when neither of the last 2 axes are contiguous

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@jagrit06 jagrit06 force-pushed the gemm_no_copy branch 2 times, most recently from ad02fe2 to 2a0e755 Compare March 11, 2024 22:07
@jagrit06 jagrit06 marked this pull request as ready for review March 11, 2024 22:14
@jagrit06
Copy link
Member Author

Some numbers (Done with a simple multi-query attention)"

Before:

 B,   D, nkh, factor,  qsl,  ksl,   dtype, time(s)
 4,  64,  16,      4,    1, 1024, float32, 0.11741
 4,  64,  16,      4,   32, 1024, float32, 0.15783
 4,  64,  16,      4, 1024, 1024, float32, 0.87965
 4,  64,  16,      4, 1024,    1, float32, 0.16385
 4, 128,   8,      4,    1, 1024, float32, 0.17190
 4, 128,   8,      4,   32, 1024, float32, 0.15203
 4, 128,   8,      4, 1024, 1024, float32, 0.69943
 4, 128,   8,      4, 1024,    1, float32, 0.14400

After:

 B,   D, nkh, factor,  qsl,  ksl,   dtype, time(s)
 4,  64,  16,      4,    1, 1024, float32, 0.03891
 4,  64,  16,      4,   32, 1024, float32, 0.07162
 4,  64,  16,      4, 1024, 1024, float32, 0.75681
 4,  64,  16,      4, 1024,    1, float32, 0.13285
 4, 128,   8,      4,    1, 1024, float32, 0.13510
 4, 128,   8,      4,   32, 1024, float32, 0.16739
 4, 128,   8,      4, 1024, 1024, float32, 0.58777
 4, 128,   8,      4, 1024,    1, float32, 0.12501

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

LGTM!! 🚀

@jagrit06 jagrit06 merged commit 5ad133f into main Mar 12, 2024
3 checks passed
@jagrit06 jagrit06 deleted the gemm_no_copy branch March 12, 2024 20:13
atiorh added a commit to argmaxinc/mlx-examples that referenced this pull request Mar 14, 2024
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.

None yet

2 participants