Hzfengsy commented on PR #18119:
URL: https://github.com/apache/tvm/pull/18119#issuecomment-3043516523

   I disagree with the premise that (2, 3) + (2, n) can be statically inferred 
to have the shape (2, 3). The validity of this operation depends on the runtime 
value of `n`.
   
   Specifically:
   
   - If `n=1` or `n=3`, the operation is valid due to broadcasting, and the 
output shape is indeed `(2, 3)`.
   - If `n` is any other value, the shapes are incompatible, and the operation 
should raise a runtime error.
   
   To handle this correctly, we need a mechanism for runtime shape validation. 
I suggest the following steps:
   
   1. Assume the valid shape: For this specific operation, we can tentatively 
define the output shape as `(2, 3)` (as this pull request does), since it's the 
only possible shape for a valid operation.
   2. Insert a runtime check: We MUST add an assertion to the model to verify 
at runtime that `n` is either 1 or 3.
   3. (Optional) Hoist the checks: We could write an optimization pass to lift 
all such runtime assertions to the beginning of the model and potentially 
combine them for efficiency.
   
   cc @tqchen 


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