forked from tracel-ai/burn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reduce sum onnx ops to burn imports (tracel-ai#1723)
- Loading branch information
Showing
11 changed files
with
256 additions
and
2 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
46 changes: 46 additions & 0 deletions
46
crates/burn-import/onnx-tests/tests/reduce_sum/reduce_sum.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,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# used to generate model: onnx-tests/tests/reduce_sum/reduce_sum.onnx | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x): | ||
return ( | ||
# ReduceSum, keepdims=0, axes=None | ||
torch.sum(x), | ||
# ReduceSum, keepdims=1, axes=[1] | ||
torch.sum(x, dim=1, keepdim=True), | ||
# ReduceSum, keepdims=1, axes=[-1] | ||
torch.sum(x, dim=-1, keepdim=True), | ||
) | ||
|
||
|
||
def main(): | ||
# Set random seed for reproducibility | ||
torch.manual_seed(0) | ||
|
||
# Export to onnx | ||
model = Model() | ||
model.eval() | ||
device = torch.device("cpu") | ||
test_input = torch.tensor([[[[1.0, 4.0, 9.0, 25.0]]]], device=device) | ||
|
||
torch.onnx.export(model, test_input, "reduce_sum_opset11.onnx", verbose=False, opset_version=11) | ||
torch.onnx.export(model, test_input, "reduce_sum_opset13.onnx", verbose=False, opset_version=13) | ||
|
||
print("Finished exporting model") | ||
|
||
# Output some test data for use in the test | ||
print(f"Test input data: {test_input}") | ||
output = model.forward(*test_input) | ||
print(f"Test output data: {output}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Binary file added
BIN
+384 Bytes
crates/burn-import/onnx-tests/tests/reduce_sum/reduce_sum_opset11.onnx
Binary file not shown.
Binary file added
BIN
+529 Bytes
crates/burn-import/onnx-tests/tests/reduce_sum/reduce_sum_opset13.onnx
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
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