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

   As discussed in previous Unity open dev meeting, this PR implements 
data-dependent operation of reshape.
   
   ```
   # Target shape will be computed at runtime and stored in tensor
   target_shape: R.Tensor(ndim=1) = ...
   # With new 'tensor_to_shape` builtin, we can convert tensor values to 
ShapeExpr
   lv: R.Shape(ndim=2) = R.tensor_to_shape(target_shape)
   # Reshape is extended to take a Var as long as it is bound with ShapeExpr
   gv: R.Tensor(ndim=2, dtype="float32") = R.reshape(data, lv)
   ```
   
   Also, `FoldConstant` is extended to support `tensor_to_shape`. 
   
   ```
   # Before `FoldConstant`: c0, c1 are constants
   lv0 = R.add(c0, c0)
   target_shape = R.multiply(lv0, c1)
   lv2: R.Shape(ndim=2) = R.tensor_to_shape(target_shape)
   gv: R.Tensor(ndim=2, dtype="float32") = R.reshape(data, lv2)
   
   # After `FoldConstant`
   gv: R.Tensor((16, 16), dtype="float32") = R.reshape(data, R.shape([16, 16]))
   ```
   
   Summary of changes
   * Introduce new builtin `tensor_to_shape`
   * Current reshape takes the target shape in `ShapeExpr | Array[PrimExpr]`. 
This PR extends this to take `Var` only when it is bound to `ShapeExpr`. 
   * Extend `FoldConstant` pass to support `tensor_to_shape`
   


-- 
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]

Reply via email to