Repository navigation
[BYOC] Fix tir_vars handling for dynamic shape BYOC backends - #20753
Open
Asthenia0412 wants to merge 1 commit into
Open
Asthenia0412 wants to merge 1 commit into
Asthenia0412 wants to merge 1 commit into
Conversation
Asthenia0412
force-pushed
the
fix-byoc-tir-vars
branch
from
October 17, 2026 01:24
165a3f5 to
6476d04
Compare
When compiling Relax models with dynamic shapes through BYOC backends (e.g. TensorRT), FuseOps injects a tir_vars: Shape([...]) parameter into Composite functions that have symbolic arithmetic in their shape expressions. The original code had two bugs: 1. JSONSerializer in codegen_json.h asserted when encountering ShapeType params (tir_vars), since it expected all function params to be tensor inputs. 2. AddNode() asserted when the function return type had no explicit shape (FuseOps generates Composite function returns with only ndim/dtype and no shape annotation). 3. RunCodegen forwarded the ShapeType tir_vars params as regular tensor arguments to the external codegen, which cannot handle them. Fixes: - codegen_json.h serialize(): skip ShapeType params but register them in memo_ (empty entry) so body expressions still resolve - codegen_json.h AddNode(): handle TensorType without shape using -1 as placeholder for unknown dynamic dims - run_codegen.cc: pre-scan BYOC functions, build param filter masks excluding ShapeType params, and filter call-site args accordingly All existing BYOC backends (TensorRT, CUTLASS, DNNL, NNAPI, etc.) benefit from this fix. Existing example_npu tests still pass. Fixes apache#20037
Asthenia0412
force-pushed
the
fix-byoc-tir-vars
branch
from
October 18, 2026 04:20
6476d04 to
579a3c3
Compare
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.
Background
TVM's BYOC (Bring Your Own Codegen) flow with dynamic shapes fails when FuseOps injects ShapeType parameters (tir_vars) into Composite functions. The JSON codegen path doesn't properly handle these non-Tensor arguments, causing crashes in external codegen backends like TensorRT.
Problem
Solution
Testing
n//2): RunCodegen succeeds, call-site correctly filters to (lv, bias)Fixes #20037