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

Refactoring of QR: stabilized Gram-Schmidt for split=1 and TS-QR for split=0 #1329

Merged

Conversation

mrfh92
Copy link
Collaborator

@mrfh92 mrfh92 commented Jan 22, 2024

Description

Changes in the implementation of QR:

  • split=1: column-block-wise stabilized/modified Gram Schmidt; thus any shape allowed.
  • split=0: TS-QR ("tall skinny QR"); thus input must be tall-skinny in the sense that each local chunk of data has not less rows than columns. Removing this restriction can be considered as future work.
  • API is now more NumPy/PyTorch-like: inputs are the input matrix and a string mode; the latter can be reduced and r, but we currently do not support complete or raw. (complete is available both in PyTorch and NumPy and should be considered as future work.) The arguments overwrite_a, calc_q, and tiles_per_proc are no more used; instead I have introduced procs_to_merge which is a hyperparameter related to TS-QR.
  • skipping the QR-related unit test (i.e. those from test_qr.py and some from test_svdtools.py) on AMD-hardware has been removed since the new PyTorch/ROCm-images support torch.linalg.qr.

Possible future work:

  • remove tall-skinny assumption for split=0 by combining TS-QR with Gram-Schmidt-like loop
  • The choice mode=complete is available both in PyTorch and NumPy and therefore might be included in future versions, too.

Due Diligence

  • General:
  • Implementation:
    • unit tests: all split configurations tested
    • unit tests: multiple dtypes tested
    • documentation updated where needed

@ghost
Copy link

ghost commented Jan 22, 2024

👇 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

Thank you for the PR!

1 similar comment
Copy link
Contributor

Thank you for the PR!

@mrfh92
Copy link
Collaborator Author

mrfh92 commented Jan 22, 2024

To be done:

  • allow batches of matrices instead of matrices only
  • implement the case split=0 (TS-QR)
  • implement the case overwrite_a = True
  • API-details need to be discussed: Change from calc_r, full_q etc. to the NumPy-like mode=‘reduced’, ‘complete’, or ‘r’? --- since we might need the full options lateron, keeping calc_r, full_q in a _qr routine in the background while defining a qr-routine with NumPy-like API in the foreground might be an option

Copy link

codecov bot commented Jan 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.58%. Comparing base (86fe8a6) to head (830dbea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1329      +/-   ##
==========================================
- Coverage   92.05%   91.58%   -0.48%     
==========================================
  Files          80       80              
  Lines       11950    11647     -303     
==========================================
- Hits        11001    10667     -334     
- Misses        949      980      +31     
Flag Coverage Δ
unit 91.58% <100.00%> (-0.48%) ⬇️

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.

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

1 similar comment
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

1 similar comment
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

github-actions bot commented Mar 1, 2024

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

@ClaudiaComito ClaudiaComito added this to the 1.4.0 milestone Apr 12, 2024
Copy link
Contributor

Thank you for the PR!

Copy link
Contributor

Thank you for the PR!

@mrfh92 mrfh92 requested a review from ClaudiaComito April 15, 2024 10:04
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 for all the work, a few comments:

benchmarks/cb/linalg.py Show resolved Hide resolved
heat/core/linalg/qr.py Show resolved Hide resolved
heat/core/linalg/qr.py Outdated Show resolved Hide resolved
heat/core/linalg/qr.py Outdated Show resolved Hide resolved
heat/core/linalg/qr.py Outdated Show resolved Hide resolved
heat/core/linalg/qr.py Outdated Show resolved Hide resolved
Comment on lines +74 to +76
# handle the case of a single process or split=None: just PyTorch QR
Q, R = torch.linalg.qr(A.larray, mode=mode)
R = DNDarray(
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree, it's not inconsistent to say: we enable all modes for non-distributed DNDarrays, and "reduced" only for distributed DNDarrays.

@mrfh92
Copy link
Collaborator Author

mrfh92 commented Apr 17, 2024

I have addressed all except for the last comment; the last one I didnt understand because I dont see the inconsistency that is not there (?).

Copy link
Contributor

Thank you for the PR!

@mrfh92 mrfh92 requested a review from ClaudiaComito April 17, 2024 12:13
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.

Awesome @mrfh92 thank you so much!

Copy link
Contributor

Thank you for the PR!

1 similar comment
Copy link
Contributor

Thank you for the PR!

@ClaudiaComito ClaudiaComito merged commit 67bc254 into main Apr 17, 2024
53 of 55 checks passed
@ClaudiaComito ClaudiaComito deleted the features/1237-Try_out_pure_stabilized_Gram-Schmidt_for_QR branch April 17, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants