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

Batched matrix multiplication. #1261

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

Conversation

FOsterfeld
Copy link
Collaborator

split dimension is a batch dimension

Due Diligence

  • General:
    • base branch must be main for new features, latest release branch (e.g. release/1.3.x) for bug fixes
    • title of the PR is suitable to appear in the Release Notes
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • documentation updated where needed

Description

Issue/s resolved: #

Changes proposed:

Type of change

Memory requirements

Performance

Does this change modify the behaviour of other functions? If so, which?

yes / no

split dimension is a batch dimension
@mrfh92 mrfh92 marked this pull request as draft November 8, 2023 13:37
@ghost
Copy link

ghost commented Nov 8, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Copy link
Contributor

github-actions bot commented Nov 8, 2023

Thank you for the PR!

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

Attention: Patch coverage is 94.17040% with 13 lines in your changes missing coverage. Please review.

Project coverage is 91.93%. Comparing base (bc5ec47) to head (2719f4d).

Files Patch % Lines
heat/core/linalg/basics.py 94.17% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1261      +/-   ##
==========================================
+ Coverage   91.87%   91.93%   +0.05%     
==========================================
  Files          80       80              
  Lines       11822    12041     +219     
==========================================
+ Hits        10862    11070     +208     
- Misses        960      971      +11     
Flag Coverage Δ
unit 91.93% <94.17%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -487,9 +487,12 @@ def matmul(a: DNDarray, b: DNDarray, allow_resplit: bool = False) -> DNDarray:
sanitation.sanitize_in(a)
sanitation.sanitize_in(b)

if a.gshape[-1] != b.gshape[0]:
batch_dim = max(a.ndim, b.ndim) - 2
batched = batch_dim > 2
Copy link
Collaborator

@mrfh92 mrfh92 Nov 10, 2023

Choose a reason for hiding this comment

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

maybe > 0 instead of >2 or did I understand sth wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, you're right, it should be 0.

@mrfh92
Copy link
Collaborator

mrfh92 commented Nov 13, 2023

Sieht gut aus soweit 👍

Vorschläge für die weitere Arbeit:

  • Wenn du oben neben "codecov" (rotes X) auf Details und dann auf "View this Pull Request on Codecov" gehst, kannst du sehen, welche Zeilen deiner Änderungen nicht getestet werden bisher. Entsprechende Tests kannst du in heat/core/linalg/tests/test_basics.py unterbringen.
    Mit diesem Fall wäre dann gebatchte Matrizenmultiplikation für den Fall abgedeckt, dass die LA-Dimensionen nicht gesplitted sind. Dies entspricht quasi dem Hinzufügen von Batchdimensionen zum Fall "2xsplit=None" im ursprünglichen Code.
  • Als nächstes könnten wir den Fall angehen, dass zu den anderen 8 (?) bestehenden Fällen Batch-dimensionen hinzugefügt werden; nun wäre allerdings die Batchdimension nicht gesplitted und dafür evtl. die LA-Dimension. Mit etwas Glück lässt sich das recht einfach aus dem bestehenden Code erzeugen, da ja PyTorch bereits gut mit Batches arbeiten kann.
  • Den Fall, dass einmal eine LA-Dimension gesplitted ist und einmal eine Batchdimension gesplitted ist, würde ich ausschließen und eine enstprechende Fehlermeldung ausgeben.

@LScheib LScheib assigned LScheib and FOsterfeld and unassigned LScheib Nov 13, 2023
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Jan 2, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Jan 8, 2024

Thank you for the PR!

Copy link
Contributor

github-actions bot commented Jan 9, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Feb 1, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Feb 5, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Feb 6, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Mar 7, 2024

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

github-actions bot commented Jun 3, 2024

Thank you for the PR!

…gebra_for_arrays_with_dimension_2_in_particular_matmul
Copy link
Contributor

Thank you for the PR!

@FOsterfeld
Copy link
Collaborator Author

FOsterfeld commented Jun 20, 2024

Regarding the possible memory issues of #360, I benchmarked the maximal memory usage of matmul for two n x n matrices in the possible split cases.

plot_matmul-heat_2

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

Successfully merging this pull request may close these issues.

None yet

3 participants