-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new node type for inputs that are initialized (#29)
<img width="823" alt="image" src="https://github.com/justinchuby/model-explorer-onnx/assets/11205048/7be1e179-c5b2-4540-8973-cbe2a70a211e">
- Loading branch information
1 parent
dea54ba
commit 6aea85b
Showing
4 changed files
with
188 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
ir_version: 8 | ||
graph { | ||
node { | ||
input: "input" | ||
output: "output" | ||
name: "node_Identity_0" | ||
op_type: "Identity" | ||
doc_string: "An identity node 1" | ||
} | ||
node { | ||
input: "input_initialized" | ||
output: "output_initialized" | ||
name: "node_Identity_1" | ||
op_type: "Identity" | ||
doc_string: "An identity node 2" | ||
} | ||
node { | ||
input: "normal_initializer" | ||
output: "val_0" | ||
name: "node_Identity_2" | ||
op_type: "Identity" | ||
doc_string: "An identity node 3" | ||
} | ||
name: "initializer_node_tests" | ||
initializer { | ||
dims: 3 | ||
data_type: 1 | ||
name: "input_initialized" | ||
raw_data: "\000\000\000\000\000\000\200?\000\000\000@" | ||
} | ||
initializer { | ||
dims: 1 | ||
data_type: 7 | ||
name: "normal_initializer" | ||
raw_data: "*\000\000\000\000\000\000\000" | ||
} | ||
input { | ||
name: "input" | ||
type { | ||
tensor_type { | ||
elem_type: 1 | ||
shape { | ||
dim { | ||
dim_value: 42 | ||
} | ||
} | ||
} | ||
} | ||
doc_string: "An input" | ||
} | ||
input { | ||
name: "input_initialized" | ||
type { | ||
tensor_type { | ||
elem_type: 1 | ||
shape { | ||
dim { | ||
dim_value: 3 | ||
} | ||
} | ||
} | ||
} | ||
doc_string: "An initialized input" | ||
} | ||
output { | ||
name: "output" | ||
type { | ||
tensor_type { | ||
elem_type: 1 | ||
shape { | ||
dim { | ||
dim_value: 42 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
output { | ||
name: "output_initialized" | ||
type { | ||
tensor_type { | ||
elem_type: 1 | ||
shape { | ||
dim { | ||
dim_value: 3 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
opset_import { | ||
domain: "" | ||
version: 20 | ||
} |
File renamed without changes.
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,70 @@ | ||
import pathlib | ||
|
||
import onnx | ||
from onnxscript import ir | ||
import numpy as np | ||
|
||
|
||
def main(): | ||
input_ = ir.Input( | ||
"input", ir.Shape([42]), ir.TensorType(ir.DataType.FLOAT), "An input" | ||
) | ||
input_initialized = ir.Input( | ||
"input_initialized", | ||
ir.Shape([3]), | ||
ir.TensorType(ir.DataType.FLOAT), | ||
"An initialized input", | ||
) | ||
input_initializer = ir.Tensor( | ||
np.array([0.0, 1.0, 2.0], dtype=np.float32), name="input_initialized" | ||
) | ||
input_initialized.const_value = input_initializer | ||
normal_value = ir.Value(name="normal_initializer") | ||
normal_initializer = ir.Tensor( | ||
np.array([42], dtype=np.int64), name="normal_initializer" | ||
) | ||
normal_value.const_value = normal_initializer | ||
output = ir.Value( | ||
shape=ir.Shape([42]), type=ir.TensorType(ir.DataType.FLOAT), name="output" | ||
) | ||
output_initialized = ir.Value( | ||
shape=ir.Shape([3]), | ||
type=ir.TensorType(ir.DataType.FLOAT), | ||
name="output_initialized", | ||
) | ||
graph = ir.Graph( | ||
[input_, input_initialized], | ||
[output, output_initialized], | ||
nodes=[ | ||
ir.Node( | ||
"", | ||
"Identity", | ||
[input_], | ||
outputs=[output], | ||
doc_string="An identity node 1", | ||
), | ||
ir.Node( | ||
"", | ||
"Identity", | ||
[input_initialized], | ||
outputs=[output_initialized], | ||
doc_string="An identity node 2", | ||
), | ||
ir.Node("", "Identity", [normal_value], doc_string="An identity node 3"), | ||
], | ||
initializers=[input_initialized, normal_value], | ||
opset_imports={"": 20}, | ||
name="initializer_node_tests", | ||
) | ||
model = ir.Model(graph, ir_version=8) | ||
model_proto = ir.serde.serialize_model(model) | ||
onnx.save( | ||
model_proto, | ||
pathlib.Path(__file__).parent.parent.parent | ||
/ "testdata" | ||
/ "initializer_node_tests.textproto", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |