cccxinli commented on issue #15048:
URL: https://github.com/apache/tvm/issues/15048#issuecomment-1587021929

   I tried to debug it, and I found:
   
   1.  Why call ReprPrintTIR function when lower Relay IR?
   It will step into function LowerShapeFunc 
(src/relay/backend/te_compiler.cc:770) because node is dynamic, and will call 
shape function for node. The shape function of add op has been registered so 
that related to the broadcast_shape_func (python/tvm/relay/op/_tensor.py).
   The _broadcast_shape_func is decorated by script. During parse_python in 
source_to_op (python/tvm/te/hybrid/parser.py), the string replacement in code:
   ```
    assert y[ndim2 - i] == 1, "Incompatible broadcast type %s and %s" % (
                       x[ndim1 - i],
                       y[ndim2 - i],
                   )
   ```
   will call x[ndim1 - i].__repr__() which globally registered in 
src/node/repr_printer.cc:90. Finally step into ReprPrinTIR in 
src/script/printer/tir/utils.h:170, and will endless in SetCommonPrefix in this 
function.
   
   2. Why SetCommonPrefix endless?
   This case will call broadcast_shape_func several times because it include 
several op.add. I count the number of times of step into Visit object function 
(src/script/printer/ir_docsifier.cc:93) in SetCommonPrefix. Result as follows, 
The next one is about eight times bigger than the last one.
   
![image](https://github.com/apache/tvm/assets/39092231/7aca4795-a4ed-41e0-ac4b-59fb5986dd0b)
   
   The output of _broadcast_shape_func like:
   
![image](https://github.com/apache/tvm/assets/39092231/fe2a920b-f905-4bab-82c5-4e11704e7a25)
   
   It include several shape_p0 which is the last output. I think that's 
probably the reason that visit the same shape_p0 several times.
   
   3.  How to resolve?
   The Visitor in SetCommonPrefix need to exclude repetition Tensor I guess.
   


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