-
Notifications
You must be signed in to change notification settings - Fork 146
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
Little idea about sparse matrix multiplication in torch_sparse #356
Comments
Thanks for the issue. Main reason we swapped to from time import time
import torch
torch.manual_seed(2022)
a = torch.rand(512, 512, dtype=torch.double).to_sparse().cuda()
b = torch.rand(512, 512, dtype=torch.double).to_sparse().cuda()
for i in range(100):
if i == 20:
sparse_start_time = time()
y1 = torch.sparse.mm(a, b)
sparse_end_time = time()
for i in range(100):
if i == 20:
spmm_start_time = time()
y2 = torch.spmm(a, b)
spmm_end_time = time()
print(y1)
print("=============================================")
print(y2)
print("=============================================")
print("torch.sparse.mm: ", (sparse_end_time - sparse_start_time), "s")
print("torch.spmm: ", (spmm_end_time - spmm_start_time), "s") Output:
|
Thank you very much for your prompt reply, I redid the test as per your reminder and the test result is consistent with what you said!👍
Output:
|
Hi, why your approach can avoid warm-up times? Thanks |
Warm-up times are avoided by just measuring time from the 20th iteration onwards. I don't know if there exists a better way to do this, but that's what I am constantly using and found out to work quite well. Backward pass does basically two things: (1) Compute the transposed version of the sparse matrix and (2) perform |
Thank you! |
Yes, that is correct. |
First of all, thank you very much for the PyTorch Geometric build, I use it all the time and it's very smooth!
When debugging the base code, I noticed that for sparse matrix multiplication, you call torch.sparse.mm() directly; however, as far as I know, there is another method for pytorch to handle sparse matrix multiplication, torch.spmm();
I would like to know the reason why you finally choose torch.sparse.mm(), since by experimentally verified, torch.spmm() seems to be faster.
In addition, I know that there is another way to implement sparse matrix multiplication in numpy, by calling the relevant functions through the scipy library. In order to test the efficiency of each of them, I conducted an experiment on a separate server with the following code and results.
Since torch_sparse is based on pytorch development, I independently compared torch.sparse.mm and torch.spmm,
The configuration of the server is
2x Intel Xeon Gold 6226R 2.9GHz 16 cores 22MB L3 Cache (Max Turbo Freq. 3.9GHz, Min 3.6GHz)
192GB 3200MHz ECC DDR4-RAM (Six Channel)
2x 1.2TB 10,000 RPM SAS II Hard Drives (Raid 1) and 6x 2.4TB 10,000 RPM SAS II Hard Drives (Raid 10)
2x NVIDIA Quadro RTX 6000 Passive (4,608 Cores, 576 Tensor Cores, 24GB Memory) (GPU)
Dependency package specifics:
BTW,When I try to increase the amount of tensor data in order to test larger sparse matrices, the program reports an error
I've seen your reply under this ERROR before, but I still don't understand why this is happening, I'm interpreting it as a data leak causing an exception.
Finally, I also had a look at the underlying torch.sparse.mm and torch.spmm code, and it seems that torch.sparse.mm can do gradient backpropagation, whereas torch.spmm can't; furthermore, I can't see the underlying code for torch.spmm, and I suspect that he's written directly from c-code.
Maybe my test code is not complete, I just had this doubt while running the code and wanted to share and discuss with you! 😊
Looking forward to your reply!😘
The text was updated successfully, but these errors were encountered: