@@ -1126,8 +1126,12 @@ def shadowing_names(
11261126 verbose : int = 0 ,
11271127 existing : Optional [Set [str ]] = None ,
11281128 shadow_context : Optional [Set [str ]] = None ,
1129- ) -> Set [str ]:
1130- """Returns the shadowing names."""
1129+ post_shadow_context : Optional [Set [str ]] = None ,
1130+ ) -> Tuple [Set [str ], Set [str ], Set [str ]]:
1131+ """
1132+ Returns the shadowing names, the names created in the main graph
1133+ after they were created in a subgraphs and the names created by the nodes.
1134+ """
11311135 if isinstance (proto , ModelProto ):
11321136 return shadowing_names (proto .graph )
11331137 if isinstance (proto , GraphProto ):
@@ -1141,6 +1145,7 @@ def shadowing_names(
11411145 | set (i .name for i in proto .sparse_initializer )
11421146 | set (i .name for i in proto .input if i .name ),
11431147 shadow_context = set (),
1148+ post_shadow_context = set (),
11441149 )
11451150 if isinstance (proto , FunctionProto ):
11461151 assert (
@@ -1151,6 +1156,7 @@ def shadowing_names(
11511156 verbose = verbose ,
11521157 existing = set (i for i in proto .input if i ),
11531158 shadow_context = set (),
1159+ post_shadow_context = set (),
11541160 )
11551161
11561162 assert (
@@ -1159,6 +1165,8 @@ def shadowing_names(
11591165 shadow = set ()
11601166 shadow_context = shadow_context .copy ()
11611167 existing = existing .copy ()
1168+ created = set ()
1169+ post_shadow = set ()
11621170 for node in proto :
11631171 not_empty = set (n for n in node .input if n )
11641172 intersection = not_empty & existing
@@ -1172,11 +1180,15 @@ def shadowing_names(
11721180 shadow |= set (i .name for i in g .input ) & shadow_context
11731181 shadow |= set (i .name for i in g .initializer ) & shadow_context
11741182 shadow |= set (i .name for i in g .sparse_initializer ) & shadow_context
1175- shadow | = shadowing_names (
1183+ s , ps , c = shadowing_names (
11761184 g .node , verbose = verbose , existing = existing , shadow_context = existing
11771185 )
1186+ shadow |= s
1187+ created |= c
11781188
11791189 not_empty = set (n for n in node .output if n )
1190+ post_shadow |= not_empty & created
11801191 shadow |= not_empty & shadow_context
11811192 existing |= not_empty
1182- return shadow
1193+ created |= not_empty
1194+ return shadow , post_shadow , created
0 commit comments