padreofthegame commented on issue #13796:
URL: https://github.com/apache/tvm/issues/13796#issuecomment-1447286279

   I came up on the similar problem working with `relay.sum` operator. It looks 
like whenever there is even number of True values in corresponding summing axis 
result will always be False. Taking this observation into account, it really 
looks to me that the summing operation works fine, but since the expected 
output is supposed to be boolean, state of the return value is derived based on 
the LS bit. That may be the explanation for function returning False for even 
number of True values. I solved this by just modifying the `relay.sum` operator 
in relay using cast operation. Similar thing can be done in `topi.sum`, but it 
requires 2 cast operations to be done, which may be unnecessary. 
   
   But looking deeper into code, I realized that both `relay.sum` and 
`topi.sum` realizations, depends on the same `sum` function, which means that 
both problems may be solved by delegating the job inside that function to 
`tvm::any` function instead of `tvm::sum`, in the case of boolean tensors. 
Luckily, `tvm::sum` and `tvm::any` has the same calling arguments, so probably 
the solution for this may be changing the line: 
   
   `return CommReduce(data, axis, tvm::sum, keepdims, atleast1d);`
   
   in the corresponding `sum` function with:
   
   `if(data->dtype.is_bool())`
   `    return CommReduce(data, axis, tvm::any, keepdims, atleast1d);`
   `else`
   `    return CommReduce(data, axis, tvm::sum, keepdims, atleast1d);`
   
   @vinx13 @masahi 


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