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 QR for non tall-skinny matrices and split=0 #1744

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

Conversation

mrfh92
Copy link
Collaborator

@mrfh92 mrfh92 commented Dec 9, 2024

Due Diligence

  • General:
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • benchmarks: created for new functionality (currently not available)
    • benchmarks: performance improved or maintained (currently not available)
    • documentation updated where needed

Description

see title

Issue/s resolved: #1736

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

no

@mrfh92 mrfh92 marked this pull request as ready for review December 9, 2024 16:39
@mrfh92 mrfh92 added linalg ESAPCA relevant for the ESA-funded project "ESAPCA" labels Dec 9, 2024
@mrfh92 mrfh92 self-assigned this Dec 9, 2024
@mrfh92 mrfh92 added the enhancement New feature or request label Dec 9, 2024
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Thank you for the PR!

1 similar comment
Copy link
Contributor

github-actions bot commented Dec 9, 2024

Thank you for the PR!

Hoppe added 2 commits December 10, 2024 10:18
…=0' of github.com:helmholtz-analytics/heat into features/1736-QR_for_non-tall-skinny_matrices_and_split=0
Copy link
Contributor

Thank you for the PR!

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.27%. Comparing base (443afe3) to head (d7f4be5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1744      +/-   ##
==========================================
+ Coverage   92.26%   92.27%   +0.01%     
==========================================
  Files          84       84              
  Lines       12445    12471      +26     
==========================================
+ Hits        11482    11508      +26     
  Misses        963      963              
Flag Coverage Δ
unit 92.27% <100.00%> (+0.01%) ⬆️

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.

@mrfh92
Copy link
Collaborator Author

mrfh92 commented Dec 10, 2024

needs to be merged before #1697

Copy link
Contributor

Thank you for the PR!

@mrfh92 mrfh92 added the PR talk label Dec 16, 2024
@ClaudiaComito ClaudiaComito changed the title QR for non tall-skinny matrices and split=0 Add QR for non tall-skinny matrices and split=0 Jan 13, 2025
@github-actions github-actions bot added core features testing Implementation of tests, or test-related issues labels Jan 20, 2025
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

@ClaudiaComito ClaudiaComito left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mrfh92, great to have this, I only have a few minor comments.

raise ValueError(
"A is split along the rows and the local chunks of data are rectangular with more rows than columns. \n Applying TS-QR in this situation is not reasonable w.r.t. runtime and memory consumption. \n We recomment to split A along the columns instead. \n In case this is not an option for you, please open an issue on GitHub."
# check that data distribution is reasonable for TS-QR
# we regard a matrix with split = 0 as suitable for TS-QR is largest local chunk of data has at least as many rows as columns
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# we regard a matrix with split = 0 as suitable for TS-QR is largest local chunk of data has at least as many rows as columns
# we regard a matrix with split = 0 as suitable for TS-QR if largest local chunk of data has at least as many rows as columns

Comment on lines +192 to +199
column_idx = torch.cumsum(A.lshape_map[:, -2], 0)
column_idx = column_idx[column_idx < A.shape[-1]]
column_idx = torch.cat(
(
torch.tensor([0], device=column_idx.device),
column_idx,
torch.tensor([A.shape[-1]], device=column_idx.device),
)
Copy link
Contributor

@ClaudiaComito ClaudiaComito Jan 20, 2025

Choose a reason for hiding this comment

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

You can use the DNDarray.counts_displs() method here,

_, column_idx = A.counts_displs()

(this returns a tuple though, and I think the final item [A.shape[-1]] needs to be added)

R = A.copy()
# Block-wise Gram-Schmidt orthogonalization, applied to groups of columns
offset = 1 if A.shape[-1] <= A.shape[-2] else 2
for k in range(len(column_idx) - offset):
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, each iteration needs A_copy[..., :, column_idx[k] :] only. Would it make sense to free up memory progressively here by only keeping the necessary slice of A_copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core enhancement New feature or request ESAPCA relevant for the ESA-funded project "ESAPCA" features linalg testing Implementation of tests, or test-related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QR for non-tall-skinny matrices and split=0
4 participants