Skip to content

Commit 91b94aa

Browse files
김민수김민수
김민수
authored and
김민수
committed
0809
1 parent 902443d commit 91b94aa

File tree

4 files changed

+1088
-0
lines changed

4 files changed

+1088
-0
lines changed

qtorch_1.ipynb

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# 1. Using qtorch to tensor\n",
10+
"\n",
11+
"import torch\n",
12+
"from qtorch.quant import Quantizer, quantizer\n",
13+
"from qtorch import FloatingPoint"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"metadata": {},
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"tensor([[0.9562, 0.8024, 0.3401],\n",
26+
" [0.8613, 0.9098, 0.8928],\n",
27+
" [0.9854, 0.6158, 0.6871]])\n"
28+
]
29+
}
30+
],
31+
"source": [
32+
"random_input = torch.rand([3,3])\n",
33+
"print(random_input)"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 3,
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"name": "stdout",
43+
"output_type": "stream",
44+
"text": [
45+
"tensor([[ 255.0000, -255.0000],\n",
46+
" [ 1.4000, 1.6000]])\n"
47+
]
48+
}
49+
],
50+
"source": [
51+
"constant_input = torch.tensor([[255., -255.],[1.4, 1.6]])\n",
52+
"print(constant_input)"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 4,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"# Set quantizer\n",
62+
"bit = FloatingPoint(exp=2, man=1)\n",
63+
"quant = quantizer(forward_number=bit, forward_rounding=\"nearest\")"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": 5,
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"name": "stdout",
73+
"output_type": "stream",
74+
"text": [
75+
"tensor([[1.0000, 0.7500, 0.5000],\n",
76+
" [0.7500, 1.0000, 1.0000],\n",
77+
" [1.0000, 0.5000, 0.7500]])\n"
78+
]
79+
}
80+
],
81+
"source": [
82+
"random_output = quant(random_input)\n",
83+
"print(random_output)"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 6,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"tensor([[ 3.0000, -3.0000],\n",
96+
" [ 1.5000, 1.5000]])\n"
97+
]
98+
}
99+
],
100+
"source": [
101+
"constant_output = quant(constant_input)\n",
102+
"print(constant_output)"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": []
111+
}
112+
],
113+
"metadata": {
114+
"kernelspec": {
115+
"display_name": "Python 3",
116+
"language": "python",
117+
"name": "python3"
118+
},
119+
"language_info": {
120+
"codemirror_mode": {
121+
"name": "ipython",
122+
"version": 3
123+
},
124+
"file_extension": ".py",
125+
"mimetype": "text/x-python",
126+
"name": "python",
127+
"nbconvert_exporter": "python",
128+
"pygments_lexer": "ipython3",
129+
"version": "3.7.9"
130+
}
131+
},
132+
"nbformat": 4,
133+
"nbformat_minor": 4
134+
}

0 commit comments

Comments
 (0)