Repository navigation
[Relax][FRONTEND][Pytorch] Add support for searchsorted - #20760
Open
Netra-Srinivasan-McW wants to merge 2 commits into
Open
Netra-Srinivasan-McW wants to merge 2 commits into
Netra-Srinivasan-McW wants to merge 2 commits into
Conversation
Author
Author
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Missing searchsorted rank and batch-shape validation allows incompatible inputs to reach CPU code that reads beyond the sequence buffer.
5 open issues
What changed in this PR
Adds PyTorch searchsorted support to TVM Relax, addressing the unsupported operator reported in #20739 for models such as pplx-embed-v2-late-9b.
Changes:
- Introduces the Relax operator, attributes, type inference, and Python/script APIs.
- Adds FX and exported-program conversion, CPU legalization, and GPU dispatch.
- Adds structural and CPU numerical tests covering search options and dynamic batch shapes.
| File | Description |
|---|---|
tests/python/relax/test_frontend_from_fx.py |
Adds structural FX import coverage. |
tests/python/relax/test_frontend_from_exported_program.py |
Adds structural and numerical tests, including dynamic shapes. |
src/relax/op/tensor/search.h |
Declares the C++ operator constructor. |
src/relax/op/tensor/search.cc |
Registers the operator, attributes, and type inference. |
python/tvm/relax/transform/legalize_ops/search.py |
Adds CPU legalization through TOPI. |
python/tvm/relax/script/ir_builder/op.py |
Exposes R.searchsorted in Relax scripts. |
python/tvm/relax/op/search.py |
Adds the public Python wrapper and documentation. |
python/tvm/relax/op/__init__.py |
Exports the new operator. |
python/tvm/relax/frontend/torch/fx_translator.py |
Registers FX conversion. |
python/tvm/relax/frontend/torch/exported_program_translator.py |
Registers tensor and scalar overloads. |
python/tvm/relax/frontend/torch/base_fx_graph_translator.py |
Translates operands, scalar constants, and search options. |
python/tvm/relax/backend/dispatch_sort_scan.py |
Selects CPU or GPU TOPI implementations. |
include/tvm/relax/op/search.h |
Defines output-dtype and insertion-side attributes. |
Review effort: Max
Netra-Srinivasan-McW
force-pushed
the
searchsorted-support
branch
from
November 17, 2026 10:24
bc90aa8 to
73ce2c4
Compare
Author
|
Hi @mshr-h, @yzhliu, @tqchen, @tlopex, I have updated the PR to address all the review changes:
Could you please take a look into the changes made when you get a chance? Thanks! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This PR adds support for the
searchsortedoperator in TVM Relax, which is used in transformer models such as Perplexity AI's pplx-embed-v2-late-9b.The following requirements have been covered:
Tests have been added to validate the operator's behavior and compilation across the supported targets, covering both static and dynamic shapes.
Closes #20739