Skip to content

Commit 0c1cee2

Browse files
author
Kaiyu Shi
committed
Use getter to handle missing attr
1 parent 9650ea8 commit 0c1cee2

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

onnxscript/rewriter/fuse_hardswish.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ def pattern(self, op, x: ir.Value) -> ir.Value:
7575
def check(self, op, x: ir.Value, hardsigmoid_out: ir.Value) -> MatchResult:
7676
check_result = MatchResult()
7777
hardsigmoid = hardsigmoid_out.producer()
78-
if not np.isclose(hardsigmoid.attributes["alpha"].value, 1 / 6):
78+
# Use getter to protect when 'alpha' / 'beta' is not in attributes
79+
alpha = hardsigmoid.attributes.get_float("alpha", -1)
80+
beta = hardsigmoid.attributes.get_float("beta", -1)
81+
if not np.isclose(alpha, 1 / 6):
7982
return check_result.fail(
8083
"HardSigmoid alpha must be 1/6 to get fused into HardSwish"
8184
)
82-
if not np.isclose(hardsigmoid.attributes["beta"].value, 0.5):
85+
if not np.isclose(beta, 0.5):
8386
return check_result.fail(
8487
"HardSigmoid beta must be 0.5 to get fused into HardSwish"
8588
)

0 commit comments

Comments
 (0)