-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mpact][test] add a count-equal idiom (for sparse consideration) (#73)
The equal operator currently does not sparsify under PyTorch, but if it were, this would be a great candidate to further optimize with doing the sum() without materializing the intermediate result!
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# RUN: %PYTHON %s | FileCheck %s | ||
|
||
import torch | ||
import numpy as np | ||
|
||
from mpact.mpactbackend import mpact_jit | ||
|
||
from mpact.models.kernels import CountEq | ||
|
||
|
||
net = CountEq() | ||
|
||
# Construct dense and sparse matrices. | ||
A = torch.tensor( | ||
[ | ||
[0.0, 1.0, 0.0, 0.0], | ||
[0.0, 0.0, 0.0, 2.0], | ||
[0.0, 0.0, 1.0, 1.0], | ||
[3.0, 0.0, 3.0, 0.0], | ||
], | ||
dtype=torch.float32, | ||
) | ||
|
||
# TODO: very interesting idiom to sparsify (collapse the sum | ||
# into the eq for full sparsity), but needs PyTorch support | ||
S = A | ||
# S = A.to_sparse() | ||
# S = A.to_sparse_csr() | ||
|
||
# | ||
# CHECK: pytorch | ||
# CHECK: 10 | ||
# CHECK: 3 | ||
# CHECK: 1 | ||
# CHECK: 2 | ||
# CHECK: 0 | ||
# CHECK: mpact | ||
# CHECK: 10 | ||
# CHECK: 3 | ||
# CHECK: 1 | ||
# CHECK: 2 | ||
# CHECK: 0 | ||
# | ||
|
||
# Run it with PyTorch. | ||
print("pytorch") | ||
for i in range(5): | ||
target = torch.tensor(i) | ||
res = net(S, target).item() | ||
print(res) | ||
|
||
print("mpact") | ||
for i in range(5): | ||
target = torch.tensor(i) | ||
res = mpact_jit(net, S, target) | ||
print(res) |
664f828
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.20
.benchmark/python/benchmarks/regression_benchmark.py::test_nop_sparse
921316.0419683264
iter/sec (stddev: 3.040267017295168e-7
)1129071.6661179548
iter/sec (stddev: 8.14334988631514e-8
)1.23
This comment was automatically generated by workflow using github-action-benchmark.
CC: @reidtatge