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

   ## Summary:
   - Supported Median operator: Add relax.median & Apply median op into 
exported_program_translator
   - Input: Tensor, Axis, KeepDim
   - Output: (Values, Indices)
   ## Expected:
   ### 1. Axis = None, KeepDim = False
   ```
   class MedianWithoutDim(nn.Module):
       def forward(self, x):
           return torch.median(x)
   ```
   
   ```
   class Module:
       def main(x: R.Tensor((2, 3, 4), dtype="float32")) -> 
R.Tuple(R.Tensor((), dtype="float32")):
           with R.dataflow():
               lv: R.Tensor((), dtype="float32") = R.median(x, axis=None, 
keepdims=False)
               gv: R.Tuple(R.Tensor((), dtype="float32")) = (lv,)
               R.output(gv)
           return gv
   ```
   
   
   ### 2. Axis = 0, KeepDim = False
   ```
   class MedianDim(nn.Module):
       def forward(self, x):
           return torch.median(x, dim=0)
   ```
   ```
   class Module:
       def main(x: R.Tensor((2, 3, 4), dtype="float32")) -> 
R.Tuple(R.Tensor((3, 4), dtype="float32"), R.Tensor((3, 4), dtype="int64")):
           with R.dataflow():
               lv: R.Tuple(R.Tensor((3, 4), dtype="float32"), R.Tensor((3, 4), 
dtype="int64")) = R.median(x, axis=[0], keepdims=False)
               lv1: R.Tensor((3, 4), dtype="float32") = lv[0]
               lv2: R.Tensor((3, 4), dtype="int64") = lv[1]
               gv: R.Tuple(R.Tensor((3, 4), dtype="float32"), R.Tensor((3, 4), 
dtype="int64")) = lv1, lv2
               R.output(gv)
           return gv
   ```
   ### 3. Axis = -1, KeepDim = True
   ```
   class MedianKeepDim(nn.Module):
       def forward(self, x):
           return torch.median(x, dim=-1, keepdim=True)
   ```
   ```
   class Module:
       def main(x: R.Tensor((2, 3, 4), dtype="float32")) -> 
R.Tuple(R.Tensor((2, 3, 1), dtype="float32"), R.Tensor((2, 3, 1), 
dtype="int64")):
           with R.dataflow():
               lv: R.Tuple(R.Tensor((2, 3, 1), dtype="float32"), R.Tensor((2, 
3, 1), dtype="int64")) = R.median(x, axis=[-1], keepdims=True)
               lv1: R.Tensor((2, 3, 1), dtype="float32") = lv[0]
               lv2: R.Tensor((2, 3, 1), dtype="int64") = lv[1]
               gv: R.Tuple(R.Tensor((2, 3, 1), dtype="float32"), R.Tensor((2, 
3, 1), dtype="int64")) = lv1, lv2
               R.output(gv)
           return gv
   ```


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