-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: carry conv/deconv kernel info at the const node level (#684)
- Loading branch information
1 parent
35acbf0
commit 07a5080
Showing
21 changed files
with
321 additions
and
220 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from torch import nn | ||
import torch | ||
import json | ||
import numpy as np | ||
|
||
|
||
class MyModel(nn.Module): | ||
def __init__(self): | ||
super(MyModel, self).__init__() | ||
|
||
def forward(self, w, x, y, z): | ||
|
||
return x << 2, y >> 3, z << 1, w >> 4 | ||
|
||
|
||
circuit = MyModel() | ||
|
||
# random integers between 0 and 100 | ||
x = torch.empty(1, 3).uniform_(0, 100).to(torch.int32) | ||
y = torch.empty(1, 3).uniform_(0, 100).to(torch.int32) | ||
z = torch.empty(1, 3).uniform_(0, 100).to(torch.int32) | ||
w = torch.empty(1, 3).uniform_(0, 100).to(torch.int32) | ||
|
||
torch.onnx.export(circuit, (w, x, y, z), "network.onnx", | ||
export_params=True, # store the trained parameter weights inside the model file | ||
opset_version=16, # the ONNX version to export the model to | ||
do_constant_folding=True, # whether to execute constant folding for optimization | ||
input_names=['input', 'input1', 'input2', | ||
'input3'], # the model's input names | ||
output_names=['output'], # the model's output names | ||
dynamic_axes={'input': {0: 'batch_size'}, # variable length axes | ||
'input1': {0: 'batch_size'}, | ||
'input2': {0: 'batch_size'}, | ||
'input3': {0: 'batch_size'}, | ||
'output': {0: 'batch_size'}, | ||
'output1': {0: 'batch_size'}, | ||
'output2': {0: 'batch_size'}, | ||
'output3': {0: 'batch_size'}}) | ||
|
||
|
||
d = ((w).detach().numpy()).reshape([-1]).tolist() | ||
d1 = ((x).detach().numpy()).reshape([-1]).tolist() | ||
d2 = ((y).detach().numpy()).reshape([-1]).tolist() | ||
d3 = ((z).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data = dict( | ||
input_data=[d, d1, d2, d3], | ||
) | ||
|
||
# Serialize data into file: | ||
json.dump(data, open("input.json", 'w')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"input_data": [[41, 39, 49], [13, 55, 66], [85, 60, 48], [25, 15, 15]]} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"input_data": [[true, true, false], [false, true, true], [true, true, true], [false, true, false]]} | ||
{"input_data": [[false, true, false], [false, true, true], [false, false, false], [false, true, true]]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from torch import nn | ||
import torch | ||
import json | ||
import numpy as np | ||
|
||
|
||
class MyModel(nn.Module): | ||
def __init__(self): | ||
super(MyModel, self).__init__() | ||
|
||
def forward(self, x): | ||
return x % 0.5 | ||
|
||
|
||
circuit = MyModel() | ||
|
||
x = torch.empty(1, 8).uniform_(0, 1) | ||
|
||
out = circuit(x) | ||
|
||
print(out) | ||
|
||
torch.onnx.export(circuit, x, "network.onnx", | ||
export_params=True, # store the trained parameter weights inside the model file | ||
opset_version=17, # the ONNX version to export the model to | ||
do_constant_folding=True, # whether to execute constant folding for optimization | ||
input_names=['input'], # the model's input names | ||
output_names=['output'], # the model's output names | ||
dynamic_axes={'input': {0: 'batch_size'}, # variable length axes | ||
'output': {0: 'batch_size'}}) | ||
|
||
|
||
d1 = ((x).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data = dict( | ||
input_data=[d1], | ||
) | ||
|
||
# Serialize data into file: | ||
json.dump(data, open("input.json", 'w')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"input_data": [[0.24276268482208252, 0.7709522247314453, 0.3388288617134094, 0.04099464416503906, 0.5914043188095093, 0.6746469736099243, 0.32862555980682373, 0.6761162877082825]]} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.