-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_vflip2.py
51 lines (30 loc) · 1.06 KB
/
check_vflip2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# TORCH_COMPILE_DEBUG=1 python check_vflip.py
# TORCH_LOGS=+inductor python check_vflip.py
import torch
import os
if not ("OMP_NUM_THREADS" in os.environ):
torch.set_num_threads(1)
def n_flip(x, dim):
o = torch.flip(x, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
o = torch.flip(o, dims=(dim, ))
return o
n_flip_inductor = torch.compile(n_flip)
x = torch.randint(0, 256, size=(1, 3, 224, 224), dtype=torch.uint8)
y = n_flip_inductor(x, dim=-2)
print(y.shape, y.dtype, y.is_contiguous())
torch.testing.assert_close(y, x.flip(dims=(-2, )))