Skip to content

[Relax][Op] Add missing TOPI-backed operators: correlation, lrn, dilate, dilation2d - #20758

Open
Asthenia0412 wants to merge 4 commits into
apache:mainfrom
Asthenia0412:feat/contribution-20261016
Open

Asthenia0412 wants to merge 4 commits into
apache:mainfrom
Asthenia0412:feat/contribution-20261016

Conversation

@Asthenia0412

Copy link
Copy Markdown

Adding 4 Relax ops backed by existing TOPI implementations.

@Asthenia0412
Asthenia0412 force-pushed the feat/contribution-20261016 branch from 2932000 to 668c0cd Compare October 17, 2026 01:24
…te, dilation2d

Add 4 new Relax operators that were previously only available in TOPI:
- relax.nn.correlation: Cross-correlation between two feature maps (NCHW layout)
- relax.nn.lrn: Local Response Normalization (AlexNet-style across channels)
- relax.nn.dilate: Upsample with holes (insert zeros between elements)
- relax.image.dilation2d: Morphological dilation (NCHW and NHWC layouts)

Each operator includes:
- C++ Attrs class with TVM_FFI_DECLARE_OBJECT_INFO_FINAL macro
- Python Relax op definition with proper attrs and docstrings
- TOPI legalization in legalize_ops/
- Export in __init__.py modules

These operators fill gaps between TOPI's rich operator set and Relax's
op surface, enabling easier frontend integration (ONNX/TFLite/Torch)
for models that use these common but previously unsupported ops.
@Asthenia0412
Asthenia0412 force-pushed the feat/contribution-20261016 branch from 668c0cd to f1fbe0b Compare October 17, 2026 02:26
Asthenia0412 and others added 3 commits October 17, 2026 04:30
PR apache#20758 added correlation, lrn, dilate, dilation2d ops with
Attribute reflection registration, but missed the corresponding
OpDef registration in the C++ OpRegistry. Without OpDef, Python
side legalize_ops cannot find the Op via Op.get(), causing
'Operator not registered' errors during import.

Add OpDef for: relax.image.dilation2d, relax.nn.correlation,
relax.nn.lrn, relax.nn.dilate.
- Fix isinstance() calls to use X | Y union syntax (UP038)
- Apply ruff-format to Python files
- Apply clang-format to C++ files
- Remove incorrect 'from tvm_tirx import DataType' imports from image.py and nn.py
- Replace all 'DataType' type annotations with 'tvm_ffi.dtype'
- The original PR mistakenly replaced tvm_ffi.dtype with DataType,
  which caused NameError at module import time since DataType is not
  available in the runtime namespace.

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

None yet

Development

Successfully merging this pull request may close these issues.

1 participant