byy723 opened a new pull request, #20431:
URL: https://github.com/apache/tvm/pull/20431

   ## Motivation
   
   For valid symbolic shapes, the `shape_to_tensor` fallback in `FoldConstant` 
can encounter a `PrimExpr` that is not an `IntImmNode`. Dereferencing it as an 
integer constant is unsafe. In the valid `shape_of -> shape_to_tensor -> 
tensor_to_shape -> reshape` path, reshape legalization also assumes a shape 
`Var` is bound directly to a `ShapeExpr`, but it may be bound to a call.
   
   Related to #20260.
   
   ## Changes
   
   - Fold `shape_to_tensor` through the C++ fallback only if each dimension is 
an int64 `IntImmNode` with a value representable as `int64_t`; otherwise retain 
the call.
   - Preserve `reshape` when its target shape `Var` is not bound to a 
`ShapeExpr`, rather than asserting during legalization.
   - Add regression tests for symbolic and mixed shapes, static folding through 
the fallback, and a valid dynamic reshape. The fallback tests temporarily 
remove and restore `FLegalize` to exercise the C++ path.
   
   ## Validation
   
   - The complete `tests/python/relax/test_transform_fold_constant.py` file 
passes: 23 tests on the rebased source.
   - The original valid dynamic-reshape reproducer completes `FoldConstant` 
without an exception.
   - Both the `default` and `cpu_generic` LLVM/CPU pipelines build and execute 
with input lengths 3 and 7; outputs match the inputs.
   - Pre-commit checks pass on the three changed files.
   
   ## Scope
   
   Passing the Tensor result of `shape_to_tensor` directly to `reshape` without 
`tensor_to_shape` remains outside this change. In the BlockBuilder reproducer, 
that input is rejected before `FoldConstant` because `reshape` expects a 
Shape-typed operand. This PR does not relax that contract.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to