-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Greater + GreaterOrEqual onnx import (#1801)
- Loading branch information
1 parent
1f31e20
commit ef4646c
Showing
10 changed files
with
226 additions
and
4 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
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,17 @@ | ||
pytorch2.3.0:� | ||
8 | ||
onnx::Greater_0 | ||
onnx::Greater_12/Greater"Greater | ||
main_graphZ! | ||
onnx::Greater_0 | ||
Z! | ||
onnx::Greater_1 | ||
b | ||
2 | ||
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,38 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: onnx-tests/tests/greater/greater.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x, y): | ||
return torch.gt(x,y) | ||
|
||
def main(): | ||
# Set seed for reproducibility | ||
torch.manual_seed(42) | ||
torch.set_printoptions(precision=8) | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
|
||
onnx_name = "greater.onnx" | ||
|
||
test_input1 = torch.randn(4, 4, device=device) | ||
test_input2 = torch.randn(4, 4, device=device) | ||
torch.onnx.export(model, (test_input1, test_input2), onnx_name, verbose=False, opset_version=16) | ||
|
||
print("Finished exporting model to {}".format(onnx_name)) | ||
|
||
print("Test input data: {} {}".format(test_input1, test_input2)) | ||
output = model.forward(test_input1, test_input2) | ||
print("Test output data: {}".format(output)) | ||
|
||
if __name__ == '__main__': | ||
main() |
17 changes: 17 additions & 0 deletions
17
crates/burn-import/onnx-tests/tests/greater_or_equal/greater_or_equal.onnx
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,17 @@ | ||
pytorch2.3.0:� | ||
T | ||
onnx::GreaterOrEqual_0 | ||
onnx::GreaterOrEqual_12/GreaterOrEqual"GreaterOrEqual | ||
main_graphZ( | ||
onnx::GreaterOrEqual_0 | ||
Z( | ||
onnx::GreaterOrEqual_1 | ||
b | ||
2 | ||
B |
38 changes: 38 additions & 0 deletions
38
crates/burn-import/onnx-tests/tests/greater_or_equal/greater_or_equal.py
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,38 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: onnx-tests/tests/less_or_equal/less_or_equal.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x, y): | ||
return torch.ge(x,y) | ||
|
||
def main(): | ||
# Set seed for reproducibility | ||
torch.manual_seed(42) | ||
torch.set_printoptions(precision=8) | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
|
||
onnx_name = "greater_or_equal.onnx" | ||
|
||
test_input1 = torch.randn(4, 4, device=device) | ||
test_input2 = torch.randn(4, 4, device=device) | ||
torch.onnx.export(model, (test_input1, test_input2), onnx_name, verbose=False, opset_version=16) | ||
|
||
print("Finished exporting model to {}".format(onnx_name)) | ||
|
||
print("Test input data: {} {}".format(test_input1, test_input2)) | ||
output = model.forward(test_input1, test_input2) | ||
print("Test output data: {}".format(output)) | ||
|
||
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
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