Skip to content

Commit 43b3b14

Browse files
authored
Merge branch 'master' into auto-gen/index_copy_
2 parents 0b5f06e + 452303b commit 43b3b14

62 files changed

Lines changed: 6738 additions & 455 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/command.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
with:
2323
command: "/test"
2424
allowed_contexts: pull_request
25+
allow_forks: "true"
26+
skip_reviews: "true"
27+
fork_review_bypass: "true"
2528
permissions: "write,admin"
2629

2730
- id: parse-command
@@ -32,7 +35,7 @@ jobs:
3235
op=$(echo $params | cut -d ':' -f 1)
3336
runner=$(echo $params | cut -d ':' -f 2)
3437
echo "op=${op}" >> $GITHUB_OUTPUT
35-
echo "runner=${op}" >> $GITHUB_OUTPUT
38+
echo "runner=${runner}" >> $GITHUB_OUTPUT
3639
3740
test-operator:
3841
needs: process-command

benchmark/core_shapes.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,37 @@ GenericBenchmarkExcluse1D:
197197
- [64, 512, 512]
198198
- [1024, 1024, 1024]
199199

200+
tril:
201+
shapes:
202+
- [64, 64]
203+
- [1024, 1024]
204+
- [4096, 4096]
205+
- [64, 512, 512]
206+
- [1024, 1024, 1024]
207+
- [1024, 16, 16]
208+
- [512, 32, 32]
209+
- [128, 64, 64]
210+
shape_desc: "(B), M, N"
211+
212+
tril_extreme_diagonal:
213+
shapes:
214+
- [4096, 4096]
215+
shape_desc: "M, N"
216+
217+
tril_out_transposed:
218+
shapes:
219+
- [1024, 1024]
220+
- [16, 128, 128]
221+
- [512, 32, 32]
222+
shape_desc: "(B), M, N"
223+
224+
tril_out_sliced:
225+
shapes:
226+
- [1024, 1024]
227+
- [16, 128, 128]
228+
- [512, 32, 32]
229+
shape_desc: "(B), M, N"
230+
200231
GenericBenchmarkExcluse3D:
201232
shapes:
202233
- [1048576] # 1024 * 1024

benchmark/test_concatenate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
import torch
3+
4+
from . import base, consts, utils
5+
6+
7+
def _input_fn(shape, dtype, device):
8+
inp1 = utils.generate_tensor_input(shape, dtype, device)
9+
inp2 = utils.generate_tensor_input(shape, dtype, device)
10+
inp3 = utils.generate_tensor_input(shape, dtype, device)
11+
yield [inp1, inp2, inp3], {"dim": 0}
12+
13+
14+
@pytest.mark.concatenate
15+
def test_concatenate():
16+
bench = base.GenericBenchmark(
17+
op_name="concatenate",
18+
torch_op=torch.concatenate,
19+
input_fn=_input_fn,
20+
dtypes=consts.FLOAT_DTYPES + consts.INT_DTYPES,
21+
)
22+
bench.run()

benchmark/test_einsum.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
from typing import Generator
2+
3+
import pytest
4+
import torch
5+
6+
from . import base, consts
7+
8+
9+
class EinsumBenchmark(base.Benchmark):
10+
DEFAULT_METRICS = consts.DEFAULT_METRICS[:] + ["tflops"]
11+
DEFAULT_SHAPES = [(1, 512, 512, 512), (1, 1024, 1024, 1024), (16, 512, 512, 512)]
12+
13+
def __init__(self, *args, batched=False, input_fn=None, **kwargs):
14+
self.batched = batched
15+
super().__init__(*args, **kwargs)
16+
17+
def set_more_shapes(self):
18+
return []
19+
20+
def set_shapes(self, *args, **kwargs):
21+
self.shapes = self.DEFAULT_SHAPES
22+
23+
def get_input_iter(self, dtype) -> Generator:
24+
for b, m, n, k in self.shapes:
25+
if self.batched:
26+
inp1 = torch.randn([b, m, k], dtype=dtype, device=self.device)
27+
inp2 = torch.randn([b, k, n], dtype=dtype, device=self.device)
28+
else:
29+
inp1 = torch.randn([m, k], dtype=dtype, device=self.device)
30+
inp2 = torch.randn([k, n], dtype=dtype, device=self.device)
31+
yield inp1, inp2
32+
33+
def get_tflops(self, op, *args, **kwargs):
34+
A, B = args[0], args[1]
35+
if self.batched:
36+
return A.shape[0] * A.shape[1] * B.shape[2] * A.shape[2] * 2
37+
return A.shape[0] * B.shape[1] * A.shape[1] * 2
38+
39+
40+
class EinsumGenericBenchmark(base.GenericBenchmark):
41+
def set_shapes(self, *args, **kwargs):
42+
pass # keep shapes set by caller
43+
44+
45+
def dot_input_fn(shape, dtype, device):
46+
(n,) = shape
47+
yield torch.randn(n, dtype=dtype, device=device), torch.randn(
48+
n, dtype=dtype, device=device
49+
)
50+
51+
52+
def outer_input_fn(shape, dtype, device):
53+
m, n = shape
54+
yield torch.randn(m, dtype=dtype, device=device), torch.randn(
55+
n, dtype=dtype, device=device
56+
)
57+
58+
59+
def unary_2d_input_fn(shape, dtype, device):
60+
m, n = shape
61+
yield (torch.randn(m, n, dtype=dtype, device=device),)
62+
63+
64+
def unary_3d_input_fn(shape, dtype, device):
65+
m, n, k = shape
66+
yield (torch.randn(m, n, k, dtype=dtype, device=device),)
67+
68+
69+
def ellipsis_input_fn(shape, dtype, device):
70+
b, h, m, k, n = shape
71+
yield torch.randn(b, h, m, k, dtype=dtype, device=device), torch.randn(
72+
b, h, k, n, dtype=dtype, device=device
73+
)
74+
75+
76+
@pytest.mark.einsum
77+
def test_einsum_matmul():
78+
bench = EinsumBenchmark(
79+
input_fn=None,
80+
op_name="einsum",
81+
torch_op=lambda A, B: torch.einsum("ij,jk->ik", A, B),
82+
dtypes=consts.FLOAT_DTYPES,
83+
)
84+
bench.run()
85+
86+
87+
@pytest.mark.einsum
88+
def test_einsum_bmm():
89+
bench = EinsumBenchmark(
90+
input_fn=None,
91+
op_name="einsum",
92+
torch_op=lambda A, B: torch.einsum("bij,bjk->bik", A, B),
93+
dtypes=consts.FLOAT_DTYPES,
94+
batched=True,
95+
)
96+
bench.run()
97+
98+
99+
@pytest.mark.einsum
100+
def test_einsum_dot():
101+
bench = EinsumGenericBenchmark(
102+
input_fn=dot_input_fn,
103+
op_name="einsum",
104+
torch_op=lambda A, B: torch.einsum("i,i->", A, B),
105+
dtypes=consts.FLOAT_DTYPES,
106+
)
107+
bench.shapes = [(1024,), (4096,), (65536,)]
108+
bench.run()
109+
110+
111+
@pytest.mark.einsum
112+
def test_einsum_outer():
113+
bench = EinsumGenericBenchmark(
114+
input_fn=outer_input_fn,
115+
op_name="einsum",
116+
torch_op=lambda A, B: torch.einsum("i,j->ij", A, B),
117+
dtypes=consts.FLOAT_DTYPES,
118+
)
119+
bench.shapes = [(1024, 1024), (4096, 4096)]
120+
bench.run()
121+
122+
123+
@pytest.mark.einsum
124+
def test_einsum_trace():
125+
bench = EinsumGenericBenchmark(
126+
input_fn=unary_2d_input_fn,
127+
op_name="einsum",
128+
torch_op=lambda A: torch.einsum("ii->", A),
129+
dtypes=consts.FLOAT_DTYPES,
130+
)
131+
bench.shapes = [(1024, 1024), (4096, 4096)]
132+
bench.run()
133+
134+
135+
@pytest.mark.einsum
136+
def test_einsum_diagonal():
137+
bench = EinsumGenericBenchmark(
138+
input_fn=unary_2d_input_fn,
139+
op_name="einsum",
140+
torch_op=lambda A: torch.einsum("ii->i", A),
141+
dtypes=consts.FLOAT_DTYPES,
142+
)
143+
bench.shapes = [(1024, 1024), (4096, 4096)]
144+
bench.run()
145+
146+
147+
@pytest.mark.einsum
148+
def test_einsum_transpose():
149+
bench = EinsumGenericBenchmark(
150+
input_fn=unary_2d_input_fn,
151+
op_name="einsum",
152+
torch_op=lambda A: torch.einsum("ij->ji", A),
153+
dtypes=consts.FLOAT_DTYPES,
154+
)
155+
bench.shapes = [(1024, 1024), (4096, 4096)]
156+
bench.run()
157+
158+
159+
@pytest.mark.einsum
160+
def test_einsum_sum_all():
161+
bench = EinsumGenericBenchmark(
162+
input_fn=unary_3d_input_fn,
163+
op_name="einsum",
164+
torch_op=lambda A: torch.einsum("ijk->", A),
165+
dtypes=consts.FLOAT_DTYPES,
166+
)
167+
bench.shapes = [(64, 64, 64), (128, 128, 128)]
168+
bench.run()
169+
170+
171+
@pytest.mark.einsum
172+
def test_einsum_sum_dim():
173+
bench = EinsumGenericBenchmark(
174+
input_fn=unary_3d_input_fn,
175+
op_name="einsum",
176+
torch_op=lambda A: torch.einsum("ijk->j", A),
177+
dtypes=consts.FLOAT_DTYPES,
178+
)
179+
bench.shapes = [(64, 64, 64), (128, 128, 128)]
180+
bench.run()
181+
182+
183+
@pytest.mark.einsum
184+
def test_einsum_ellipsis():
185+
bench = EinsumGenericBenchmark(
186+
input_fn=ellipsis_input_fn,
187+
op_name="einsum",
188+
torch_op=lambda A, B: torch.einsum("...ij,...jk->...ik", A, B),
189+
dtypes=consts.FLOAT_DTYPES,
190+
)
191+
bench.shapes = [(2, 4, 64, 64, 128), (2, 8, 128, 128, 256)]
192+
bench.run()

benchmark/test_feature_dropout.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
import torch
3+
4+
from . import base, consts, utils
5+
6+
7+
def _input_fn(shape, dtype, device):
8+
inp = utils.generate_tensor_input(shape, dtype, device)
9+
yield inp, 0.5, True
10+
11+
12+
@pytest.mark.feature_dropout
13+
def test_feature_dropout():
14+
bench = base.GenericBenchmarkExcluse1D(
15+
input_fn=_input_fn,
16+
op_name="feature_dropout",
17+
torch_op=torch.feature_dropout,
18+
dtypes=consts.FLOAT_DTYPES,
19+
)
20+
bench.run()
21+
22+
23+
@pytest.mark.feature_dropout_
24+
def test_feature_dropout_():
25+
bench = base.GenericBenchmarkExcluse1D(
26+
input_fn=_input_fn,
27+
op_name="feature_dropout_",
28+
torch_op=torch.feature_dropout_,
29+
dtypes=consts.FLOAT_DTYPES,
30+
)
31+
bench.run()

0 commit comments

Comments
 (0)