Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3737346

Browse files
committed
fix unused
1 parent6532733 commit3737346

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

‎onnx_array_api/graph_api/graph_builder.py‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
importnumpyasnp
44
importonnx.helperasoh
55
importonnx.numpy_helperasonh
6-
fromonnximportAttributeProto,FunctionProto,ModelProto,NodeProto,TensorProto
6+
fromonnximport (
7+
AttributeProto,
8+
FunctionProto,
9+
GraphProto,
10+
ModelProto,
11+
NodeProto,
12+
TensorProto,
13+
)
714
fromonnx.referenceimportReferenceEvaluator
815

916
T="TENSOR"
@@ -655,6 +662,22 @@ def optimize(self, check_order: bool = False):
655662
ifcheck_order:
656663
self.check_order()
657664

665+
defhidden_inputs_graph(self,graph:GraphProto)->Set[str]:
666+
hidden=set()
667+
memo=set(i.nameforiingraph.initializer)
668+
memo|=set(i.nameforiingraph.sparse_initializer)
669+
fornodeingraph.node:
670+
foriinnode.input:
671+
ifinotinmemo:
672+
hidden.add(i)
673+
forattinnode.attribute:
674+
ifatt.type==AttributeProto.GRAPHandatt.g:
675+
hid=self.hidden_inputs_graph(att.g)
676+
less=set(hforhinhidifhnotinmemo)
677+
hidden|=less
678+
memo|=set(node.output)
679+
returnhidden
680+
658681
defremove_unused(self):
659682
"""
660683
Simple function to remove unused nodes.
@@ -671,6 +694,11 @@ def remove_unused(self):
671694
foriinnode.input:
672695
marked[o].add(i)
673696
used=True
697+
forattinnode.attribute:
698+
ifatt.type==AttributeProto.GRAPHandatt.g:
699+
hidden_inputs=self.hidden_inputs_graph(att.g)
700+
foriinhidden_inputs:
701+
marked[i]=set()
674702
ifused:
675703
foriinnode.input:
676704
marked[i]=set()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp