Skip to content

Rewriter: don't crash fusing Relu/Clip chains when the Clip input has no type - #3102

Open
Kayvan Zahiri (Kayvan-Zahiri) wants to merge 1 commit into
microsoft:mainfrom
Kayvan-Zahiri:fix-relu-clip-untyped
Open

Kayvan Zahiri (Kayvan-Zahiri) wants to merge 1 commit into
microsoft:mainfrom
Kayvan-Zahiri:fix-relu-clip-untyped

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown
Contributor

rewriter.rewrite() raises on a valid model when the input of a fused Clip has no type information, for example when shape inference hasn't been run:

x1 = Abs(X)
x2 = Clip(x1, min, max)
Y  = Clip(x2, min2, max2)
AttributeError: 'NoneType' object has no attribute 'numpy'

extract_min_max read the dtype from node.inputs[0].dtype.numpy(), and x1.dtype is None here. All three Clip rules (Clip/Clip, Clip/Relu, Relu/Clip) hit it, whether the bounds are initializers or Constant nodes. optimizer.optimize() doesn't, because it infers types first.

The spec gives min and max the same type as the input, so the dtype now comes from the bounds when the input has none. The one case left without a dtype is Clip(Relu(x)) with no bounds and an untyped x. There, check() now fails the match instead of building a float64 min.

Tests: a new class runs the three patterns on an untyped intermediate, without shape inference, and checks the no-bounds failure. All 4 tests fail on main with the error above. Rewriter tests: 414 passed. test_fuse_pad_into_conv_6/_7 fail on main too in my environment.

Found while fuzzing the rewrite rules on untyped models, with Claude Code's help.

… no type

Signed-off-by: Kayvan Zahiri <kayvanandre@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant