Lunderberg commented on issue #17205:
URL: https://github.com/apache/tvm/issues/17205#issuecomment-2253337351

   Aha!  The problem is that `HintOnDeviceRemover` (the first step of 
`RealizeVDevice`) is mutating the relax expression in-place, which is not 
legal.  As a result, expressions that are in the input `Module` are being 
mutated to have different `StructInfo`.  The second time that `RealizeVDevice` 
is applied, its input has been mutated to already include `vdevice` annotations.
   
   ```python
   ## Running these commands
   
   Module["foo"].show(name="Before")
   relax.transform.RealizeVDevice()(Module)
   Module["foo"].show(name="OrigAfter")
   
   ## Produces the following output
   
   @R.function
   def Before(
       x: R.Tensor((2, 3), dtype="float32"),
       y: R.Tensor((2, 3), dtype="float32"),
       z: R.Tensor((2, 3), dtype="float32"),
   ) -> R.Tensor((2, 3), dtype="float32"):
       R.func_attr({"global_symbol": "foo"})
       with R.dataflow():
           lv0: R.Tensor((2, 3), dtype="float32") = R.hint_on_device(y, 
R.device(dev_type=1, dev_id=0))
           R.output(lv0)
       return lv0
   
   
   @R.function
   def OrigAfter(
       x: R.Tensor((2, 3), dtype="float32"),
       y: R.Tensor((2, 3), dtype="float32", vdevice="llvm:-1"),
       z: R.Tensor((2, 3), dtype="float32"),
   ) -> R.Tensor((2, 3), dtype="float32"):
       R.func_attr({"global_symbol": "foo"})
       with R.dataflow():
           lv0: R.Tensor((2, 3), dtype="float32", vdevice="llvm:-1") = 
R.hint_on_device(
               y, R.device(dev_type=1, dev_id=0)
           )
           R.output(lv0)
       return lv0
   ```
   
   The input module should never be modified when running any `IRModule` 
transform, so this is definitely a bug.


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