forked from nimashoghi/smart-quantization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
58 lines (44 loc) · 1.03 KB
/
test.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
#%%
from argparse import ArgumentParser
from smart_compress.compress.smart import SmartFP
parser = ArgumentParser()
parser = SmartFP.add_argparse_args(parser)
args = parser.parse_args([])
#%%
import torch
torch.manual_seed(100)
# %%
args.precision = 32
args.scale_factor = 1
args.use_sample_stats = True
fp = SmartFP(args)
fp
from tqdm import trange
import torch
import pandas as pd
diffs = 0
COUNT = 100
x = torch.rand((100)).random_(0, 1000)
x_orig = x.clone()
for t in trange(COUNT):
data = []
for i in range(1000):
x = fp(x)
for value, value_xorig in zip(x, x_orig):
data.append(
dict(
x_orig=float(value_xorig),
x=float(value),
x_diff=float(value - value_xorig),
)
)
# print()
# print()
# print(x, x_orig, x - x_orig)
df = pd.DataFrame(data)
df["x_diff"].hist()
m = df["x_diff"].mean()
diffs += m
print(m, diffs / (t + 1))
print(diffs / COUNT)
# %%