File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ def _process_constant_node(node: ir.Node) -> None:
71
71
if attr_value is None or not isinstance (attr_value , ir .Attr ):
72
72
return
73
73
74
+ # Even if this is an attribute, the value property might not be set, which
75
+ # happens e.g. in case of attribute references, i.e., ref_attr_name is set
76
+ if attr_value .value is None :
77
+ # For now reject this to prevent TypeError from accessing Nones below
78
+ return
79
+
74
80
const_value : ir .TensorProtocol
75
81
if attr_name in {"value_float" , "value_floats" }:
76
82
const_value = ir .Tensor (
Original file line number Diff line number Diff line change @@ -597,6 +597,22 @@ def test_multi_graph_identity_output_preserves_output_name(self):
597
597
)
598
598
self .assertEqual ([input .name for input in optimized .graph .inputs ], ["x" ])
599
599
600
+ # This should not be constant-foldable as the constant references an
601
+ # attribute and thus the shape cannot be resolved. At the same time it
602
+ # should not fail due to the attribute value being None in
603
+ # _process_constant_node
604
+ def test_attribute_reference (self ):
605
+ model = """
606
+ <ir_version: 7, opset_import: ["" : 17]>
607
+ agraph () => (int64[N] z) {
608
+ x = Constant <value_ints: ints = @attr> ()
609
+ z = Shape (x)
610
+ }
611
+ """
612
+
613
+ optimized = self ._fold (model )
614
+ self .assertEqual (len (optimized .graph ), 2 )
615
+
600
616
601
617
if __name__ == "__main__" :
602
618
unittest .main ()
You can’t perform that action at this time.
0 commit comments