Skip to content

[BugFix][Relax] Add legalize for isnan, isinf, isfinite#19492

Open
as4230 wants to merge 1 commit intoapache:mainfrom
as4230:fix/relax-legalize-isnan-isinf-isfinite
Open

[BugFix][Relax] Add legalize for isnan, isinf, isfinite#19492
as4230 wants to merge 1 commit intoapache:mainfrom
as4230:fix/relax-legalize-isnan-isinf-isfinite

Conversation

@as4230
Copy link
Copy Markdown
Contributor

@as4230 as4230 commented May 1, 2026

The Relax ops relax.isnan, relax.isinf, and relax.isfinite are registered in the op registry and emit valid IR, but lack FLegalize entries so LegalizeOps() leaves them unlowered and relax.build() crashes at codegen with:

InternalError: CodeGenVM cannot handle this intrinsic now:
Op(relax.isnan)

Same crash on isinf and isfinite, on both LLVM and CUDA targets.

The TOPI implementations already exist (python/tvm/topi/math.py). The fix is three register_legalize calls following the _call_topi_without_attr pattern used by the other unary ops in the same file.

Fixes #19452.

The Relax ops `relax.isnan`, `relax.isinf`, and `relax.isfinite` are
registered in the op registry and emit valid IR, but lack FLegalize
entries so LegalizeOps() leaves them unlowered and relax.build()
crashes at codegen with:

    InternalError: CodeGenVM cannot handle this intrinsic now:
    Op(relax.isnan)

Same crash on `isinf` and `isfinite`, on both LLVM and CUDA targets.

The TOPI implementations already exist (python/tvm/topi/math.py).
The fix is three register_legalize calls following the _call_topi_without_attr
pattern used by the other unary ops in the same file.

Fixes apache#19452.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds legalization support for the unary operations isfinite, isinf, and isnan in the Relax framework, mapping them to their corresponding TOPI implementations. It also includes unit tests to verify the legalization of these operations for float32 tensors. I have no feedback to provide.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] R.isnan, R.isinf, R.isfinite crash at build time — CodeGenVM intrinsic not implemented

1 participant