Skip to content

Commit b06a301

Browse files
committed
Update ONNX graphsurgeon to v0.3.11
Signed-off-by: Rajeev Rao <rajeevrao@nvidia.com>
1 parent b5ff243 commit b06a301

24 files changed

Lines changed: 503 additions & 391 deletions

File tree

tools/onnx-graphsurgeon/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
Dates are in YYYY-MM-DD format.
44

55

6+
## v0.3.11 (2021-07-14)
7+
### Changed
8+
- Updated `fold_constants()` so that it no longer fails if a shape folding pass fails when `error_ok` is `True`.
9+
10+
### Fixed
11+
- Fixed a bug where `fold_constants()` would fail if a model contained a `Slice` node without a `starts` or `ends` input.
12+
13+
614
## v0.3.10 (2021-05-20)
715
### Added
8-
- Added support for folding `Shape -> Slice` patterns even when the entire shape may not be known.
16+
- Added support for folding `Shape -> Slice` patterns even when the entire shape may not be known.
917

1018

1119
## v0.3.9 (2021-04-20)

tools/onnx-graphsurgeon/docs/conf.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
#
1616
import sys
1717
import os
18+
1819
ROOT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir)
1920
sys.path.insert(0, ROOT_DIR)
2021
import onnx_graphsurgeon as gs
2122

2223
extensions = [
23-
'sphinx.ext.autodoc',
24-
'sphinx.ext.intersphinx',
25-
'sphinx.ext.autosummary',
26-
'sphinx.ext.napoleon',
27-
'sphinx.ext.mathjax',
24+
"sphinx.ext.autodoc",
25+
"sphinx.ext.intersphinx",
26+
"sphinx.ext.autosummary",
27+
"sphinx.ext.napoleon",
28+
"sphinx.ext.mathjax",
2829
]
2930

3031
# Want to be able to generate docs with no dependencies installed
@@ -42,50 +43,48 @@
4243

4344
autosummary_generate = True
4445

45-
source_suffix = ['.rst']
46+
source_suffix = [".rst"]
4647

4748
# The master toctree document.
48-
master_doc = 'index'
49+
master_doc = "index"
4950

5051
# General information about the project.
51-
project = 'ONNX GraphSurgeon'
52-
copyright = '2020, NVIDIA'
53-
author = 'NVIDIA'
52+
project = "ONNX GraphSurgeon"
53+
copyright = "2020, NVIDIA"
54+
author = "NVIDIA"
5455

5556
version = gs.__version__
5657
# The full version, including alpha/beta/rc tags.
5758
release = version
5859

5960
# Style
60-
pygments_style = 'colorful'
61+
pygments_style = "colorful"
6162

62-
html_theme = 'sphinx_rtd_theme'
63+
html_theme = "sphinx_rtd_theme"
6364

6465
# Use the TRT theme and NVIDIA logo
65-
html_static_path = ['_static']
66+
html_static_path = ["_static"]
6667

67-
html_logo = '_static/img/nvlogo_white.png'
68+
html_logo = "_static/img/nvlogo_white.png"
6869

6970
# Hide source link
7071
html_show_sourcelink = False
7172

7273
# Output file base name for HTML help builder.
73-
htmlhelp_basename = 'OnnxGraphSurgeonDoc'
74+
htmlhelp_basename = "OnnxGraphSurgeonDoc"
7475

7576
# Template files to extend default Sphinx templates.
7677
# See https://www.sphinx-doc.org/en/master/templating.html for details.
7778
templates_path = ["_templates"]
7879

7980
# For constructor arguments to show up in Sphinx generated doc
80-
autoclass_content = 'both'
81+
autoclass_content = "both"
8182

8283
# Unlimited depth sidebar.
83-
html_theme_options = {
84-
'navigation_depth': -1
85-
}
84+
html_theme_options = {"navigation_depth": -1}
8685

87-
html_sidebars = { '**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html'] }
86+
html_sidebars = {"**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"]}
8887

8988
# Allows us to override the default page width in the Sphinx theme.
9089
def setup(app):
91-
app.add_css_file('style.css')
90+
app.add_css_file("style.css")

tools/onnx-graphsurgeon/examples/07_creating_a_model_with_the_layer_api/generate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def mul(self, a, b):
5050
@gs.Graph.register()
5151
def gemm(self, a, b, trans_a=False, trans_b=False):
5252
attrs = {"transA": int(trans_a), "transB": int(trans_b)}
53-
return propagate_dtype(self.layer(op="Gemm", inputs=[a, b], outputs=["gemm_out_gs"], attrs=attrs), a.dtype or b.dtype)
53+
return propagate_dtype(
54+
self.layer(op="Gemm", inputs=[a, b], outputs=["gemm_out_gs"], attrs=attrs), a.dtype or b.dtype
55+
)
5456

5557

5658
# You can also specify a set of opsets when regsitering a function.

tools/onnx-graphsurgeon/examples/08_replacing_a_subgraph/generate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
def min(self, *args):
2424
return self.layer(op="Min", inputs=args, outputs=["min_out"])[0]
2525

26+
2627
@gs.Graph.register()
2728
def max(self, *args):
2829
return self.layer(op="Max", inputs=args, outputs=["max_out"])[0]
2930

31+
3032
@gs.Graph.register()
3133
def identity(self, inp):
3234
return self.layer(op="Identity", inputs=[inp], outputs=["identity_out"])[0]
@@ -44,7 +46,9 @@ def identity(self, inp):
4446
# Add identity nodes to make the graph structure a bit more interesting
4547
inp = graph.identity(graph.inputs[0])
4648
max_out = graph.max(graph.min(inp, MAX_VAL), MIN_VAL)
47-
graph.outputs = [graph.identity(max_out), ]
49+
graph.outputs = [
50+
graph.identity(max_out),
51+
]
4852

4953
# Graph outputs must include dtype information
5054
graph.outputs[0].to_variable(dtype=np.float32, shape=(4, 4))

tools/onnx-graphsurgeon/examples/09_shape_operations_with_the_layer_api/generate.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def shape(self, a):
2929

3030
@gs.Graph.register()
3131
def reduce_prod(self, a, axes, keepdims=True):
32-
return self.layer(op="ReduceProd", inputs=[a], attrs={"axes": axes, "keepdims": int(keepdims)}, outputs=["reduce_prod_out_gs"])[0]
32+
return self.layer(
33+
op="ReduceProd", inputs=[a], attrs={"axes": axes, "keepdims": int(keepdims)}, outputs=["reduce_prod_out_gs"]
34+
)[0]
3335

3436

3537
@gs.Graph.register()
@@ -69,8 +71,8 @@ def concat(self, inputs, axis=0):
6971
partially_flattened = graph.reshape(graph.inputs[0], new_shape)
7072

7173
# Finally, set up the outputs and export.
72-
flattened.name = "flattened" # Rename output tensor to make it easy to find.
73-
flattened.dtype = np.float32 # NOTE: We must include dtype information for graph outputs
74+
flattened.name = "flattened" # Rename output tensor to make it easy to find.
75+
flattened.dtype = np.float32 # NOTE: We must include dtype information for graph outputs
7476
partially_flattened.name = "partially_flattened"
7577
partially_flattened.dtype = np.float32
7678

tools/onnx-graphsurgeon/onnx_graphsurgeon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from onnx_graphsurgeon.ir.tensor import Constant, Tensor, Variable
66
from onnx_graphsurgeon.util.exception import OnnxGraphSurgeonException
77

8-
__version__ = "0.3.10"
8+
__version__ = "0.3.11"

tools/onnx-graphsurgeon/onnx_graphsurgeon/exporters/base_exporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from onnx_graphsurgeon.ir.graph import Graph
1818

19+
1920
class BaseExporter(object):
2021
@staticmethod
2122
def export_graph(graph: Graph):

tools/onnx-graphsurgeon/onnx_graphsurgeon/exporters/onnx_exporter.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,27 @@ def export_tensor_proto(tensor: Constant) -> onnx.TensorProto:
4242
onnx_tensor.name = tensor.name
4343
return onnx_tensor
4444

45-
4645
@staticmethod
4746
def export_value_info_proto(tensor: Variable, do_type_check: bool) -> onnx.ValueInfoProto:
4847
if do_type_check and tensor.dtype is None:
49-
G_LOGGER.critical("Graph input and output tensors must include dtype information. Please set the dtype attribute for: {:}".format(tensor))
48+
G_LOGGER.critical(
49+
"Graph input and output tensors must include dtype information. Please set the dtype attribute for: {:}".format(
50+
tensor
51+
)
52+
)
5053

5154
if tensor.dtype is not None:
5255
onnx_tensor = onnx.helper.make_tensor_value_info(tensor.name, dtype_to_onnx(tensor.dtype), tensor.shape)
5356
else:
5457
onnx_tensor = onnx.helper.make_empty_tensor_value_info(tensor.name)
5558
return onnx_tensor
5659

57-
5860
@staticmethod
5961
def export_node(node: Node, do_type_check: bool) -> onnx.NodeProto:
6062
# Cannot pass in attrs directly as make_node will change the order
61-
onnx_node = onnx.helper.make_node(node.op, inputs=[t.name for t in node.inputs], outputs=[t.name for t in node.outputs], name=node.name)
63+
onnx_node = onnx.helper.make_node(
64+
node.op, inputs=[t.name for t in node.inputs], outputs=[t.name for t in node.outputs], name=node.name
65+
)
6266
# Convert Tensors and Graphs to TensorProtos and GraphProtos respectively
6367
for key, val in node.attrs.items():
6468
if isinstance(val, Tensor):
@@ -68,7 +72,6 @@ def export_node(node: Node, do_type_check: bool) -> onnx.NodeProto:
6872
onnx_node.attribute.extend([onnx.helper.make_attribute(key, val)])
6973
return onnx_node
7074

71-
7275
@staticmethod
7376
def export_graph(graph: Graph, do_type_check=True) -> onnx.GraphProto:
7477
"""
@@ -83,7 +86,9 @@ def export_graph(graph: Graph, do_type_check=True) -> onnx.GraphProto:
8386
inputs = [OnnxExporter.export_value_info_proto(inp, do_type_check) for inp in graph.inputs]
8487
outputs = [OnnxExporter.export_value_info_proto(out, do_type_check) for out in graph.outputs]
8588
tensor_map = graph.tensors()
86-
initializer = [OnnxExporter.export_tensor_proto(tensor) for tensor in tensor_map.values() if isinstance(tensor, Constant)]
89+
initializer = [
90+
OnnxExporter.export_tensor_proto(tensor) for tensor in tensor_map.values() if isinstance(tensor, Constant)
91+
]
8792

8893
# Remove inputs and outputs to export ValueInfoProtos
8994
for tensor in graph.inputs + graph.outputs:
@@ -93,9 +98,22 @@ def export_graph(graph: Graph, do_type_check=True) -> onnx.GraphProto:
9398
# Omit tensors from value_info if we don't know their shape/dtype
9499
def has_value_info(tensor):
95100
return isinstance(tensor, Variable) and (tensor.dtype is not None or tensor.shape is not None)
96-
value_info = [OnnxExporter.export_value_info_proto(tensor, do_type_check) for tensor in tensor_map.values() if has_value_info(tensor)]
97101

98-
return onnx.helper.make_graph(nodes=nodes, name=graph.name, inputs=inputs, outputs=outputs, initializer=initializer, doc_string=graph.doc_string, value_info=value_info)
102+
value_info = [
103+
OnnxExporter.export_value_info_proto(tensor, do_type_check)
104+
for tensor in tensor_map.values()
105+
if has_value_info(tensor)
106+
]
107+
108+
return onnx.helper.make_graph(
109+
nodes=nodes,
110+
name=graph.name,
111+
inputs=inputs,
112+
outputs=outputs,
113+
initializer=initializer,
114+
doc_string=graph.doc_string,
115+
value_info=value_info,
116+
)
99117

100118

101119
def export_onnx(graph: Graph, do_type_check=True, **kwargs) -> "onnx.ModelProto":

tools/onnx-graphsurgeon/onnx_graphsurgeon/importers/base_importer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from onnx_graphsurgeon.ir.graph import Graph
1818

19+
1920
class BaseImporter(object):
2021
@staticmethod
2122
def import_graph(graph) -> Graph:

0 commit comments

Comments
 (0)