-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af1e187
commit a3017cf
Showing
21 changed files
with
321 additions
and
155 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import torch | ||
from torch import nn | ||
|
||
class Circuit(nn.Module): | ||
def __init__(self): | ||
super(Circuit, self).__init__() | ||
|
||
def forward(self, x): | ||
return torch.special.erf(x) | ||
|
||
def main(): | ||
torch_model = Circuit() | ||
# Input to the model | ||
shape = [3] | ||
x = torch.rand(1,*shape, requires_grad=True) | ||
torch_out = torch_model(x) | ||
# Export the model | ||
torch.onnx.export(torch_model, # model being run | ||
x, # model input (or a tuple for multiple inputs) | ||
"network.onnx", # where to save the model (can be a file or file-like object) | ||
export_params=True, # store the trained parameter weights inside the model file | ||
opset_version=10, # 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'}}) | ||
|
||
d = ((x).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data = dict(input_shapes = [shape], | ||
input_data = [d], | ||
output_data = [((o).detach().numpy()).reshape([-1]).tolist() for o in torch_out]) | ||
|
||
# Serialize data into file: | ||
json.dump( data, open( "input.json", 'w' ) ) | ||
|
||
if __name__ == "__main__": | ||
main() |
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.7970018,0.14464009,0.4023286]],"input_shapes":[[3]],"output_data":[[0.734375,0.1640625,0.421875]]} |
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,13 @@ | ||
pytorch2.0.0:n | ||
inputoutput/Erf"Erf torch_jitZ! | ||
input | ||
batch_size | ||
b" | ||
output | ||
batch_size | ||
B |
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,41 @@ | ||
import json | ||
import torch | ||
from torch import nn | ||
|
||
class Circuit(nn.Module): | ||
def __init__(self): | ||
super(Circuit, self).__init__() | ||
self.layer = nn.GELU() # approximation = false in our case | ||
|
||
def forward(self, x): | ||
return self.layer(x) | ||
|
||
def main(): | ||
torch_model = Circuit() | ||
# Input to the model | ||
shape = [3] | ||
x = torch.rand(1,*shape, requires_grad=True) | ||
torch_out = torch_model(x) | ||
# Export the model | ||
torch.onnx.export(torch_model, # model being run | ||
x, # model input (or a tuple for multiple inputs) | ||
"network.onnx", # where to save the model (can be a file or file-like object) | ||
export_params=True, # store the trained parameter weights inside the model file | ||
opset_version=10, # 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'}}) | ||
|
||
d = ((x).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data = dict(input_shapes = [shape], | ||
input_data = [d], | ||
output_data = [((o).detach().numpy()).reshape([-1]).tolist() for o in torch_out]) | ||
|
||
# Serialize data into file: | ||
json.dump( data, open( "input.json", 'w' ) ) | ||
|
||
if __name__ == "__main__": | ||
main() |
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.61017877,0.21496391,0.8960367]],"input_shapes":[[3]],"output_data":[[0.44274902,0.12817383,0.72998047]]} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import torch | ||
from torch import nn | ||
|
||
class Circuit(nn.Module): | ||
def __init__(self): | ||
super(Circuit, self).__init__() | ||
self.layer = nn.GELU('tanh') # approximation = false in our case | ||
|
||
def forward(self, x): | ||
return self.layer(x) | ||
|
||
def main(): | ||
torch_model = Circuit() | ||
# Input to the model | ||
shape = [3] | ||
x = torch.rand(1,*shape, requires_grad=True) | ||
torch_out = torch_model(x) | ||
# Export the model | ||
torch.onnx.export(torch_model, # model being run | ||
x, # model input (or a tuple for multiple inputs) | ||
"network.onnx", # where to save the model (can be a file or file-like object) | ||
export_params=True, # store the trained parameter weights inside the model file | ||
opset_version=10, # 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'}}) | ||
|
||
d = ((x).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data = dict(input_shapes = [shape], | ||
input_data = [d], | ||
output_data = [((o).detach().numpy()).reshape([-1]).tolist() for o in torch_out]) | ||
|
||
# Serialize data into file: | ||
json.dump( data, open( "input.json", 'w' ) ) | ||
|
||
if __name__ == "__main__": | ||
main() |
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.85212487,0.0874908,0.5229686]],"input_shapes":[[3]],"output_data":[[0.6819153,0.045654297,0.3659973]]} |
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.