-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_speed.py
64 lines (49 loc) · 1.83 KB
/
test_speed.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import torch.utils.benchmark as benchmark
import dqtorch
import torch
def _forward_and_backward(fun, args):
for x in args:
x.requires_grad = True
out = fun(*args)
loss = out.sum()
loss.backward()
for x in args:
x.requires_grad = False
# create two quaternions
n_pts = 4096 * 128
# n_pts = 2048*128 # a typical workload for NeRF training
qr_1 = dqtorch.axis_angle_to_quaternion(torch.randn(n_pts, 3).cuda())
qr_2 = dqtorch.axis_angle_to_quaternion(torch.randn(n_pts, 3).cuda())
# 1. test the speed up of quaternino_mul over native pytorch implementaion
print('------ quaternion_mul --------')
t = benchmark.Timer(
stmt='_quaternion_mul_pytorch(qr_1, qr_2)',
setup='from dqtorch import _quaternion_mul_pytorch',
globals={'qr_1': qr_1, 'qr_2': qr_2})
print(t.timeit(200))
t = benchmark.Timer(
stmt='quaternion_mul(qr_1, qr_2)',
setup='from dqtorch import quaternion_mul',
globals={'qr_1': qr_1, 'qr_2': qr_2})
print(t.timeit(200))
t = benchmark.Timer(
stmt='_forward_and_backward(fun, (qr_1, qr_2))',
setup='from __main__ import _forward_and_backward',
globals={'fun':dqtorch._quaternion_mul_pytorch, 'qr_1': qr_1, 'qr_2': qr_2})
print(t.timeit(200))
t = benchmark.Timer(
stmt='_forward_and_backward(fun, (qr_1, qr_2))',
setup='from __main__ import _forward_and_backward',
globals={'fun':dqtorch.quaternion_mul, 'qr_1': qr_1, 'qr_2': qr_2})
print('native pytorch: ', t.timeit(200))
print('------ quaternion_conjugate --------')
t = benchmark.Timer(
stmt='quaternion_conjugate(qr_1)',
setup='from dqtorch import quaternion_conjugate',
globals={'qr_1': qr_1})
print(t.timeit(200))
t = benchmark.Timer(
stmt='_quaternion_conjugate_pytorch(qr_1)',
setup='from dqtorch import _quaternion_conjugate_pytorch',
globals={'qr_1': qr_1})
print(t.timeit(200))