siyiweigeHEW commented on PR #20239:
URL: https://github.com/apache/tvm/pull/20239#issuecomment-5551776283

   > `10 ** abs(decimals)` is evaluated as a Python integer before it is 
converted to the target dtype. PyTorch accepts values such as `decimals=309`, 
and `torch.export` emits a valid `aten.round.decimals` node, but 
`relax.const(10**309, "float32")` and the float64 variant raise `OverflowError: 
int too large to convert to float`. As a result, these valid exported programs 
still fail during import. Even larger values can also require constructing an 
unnecessarily large host integer.
   > 
   > Please construct or saturate the scale directly in the target 
floating-point dtype, or handle scale overflow explicitly, and add a regression 
test with a large `decimals` value.
   
   Thanks for catching these edge cases.
   
   I agree that the current implementation should not perform the scaling 
intermediates in the input dtype for float16/bfloat16, since large positive or 
negative decimals can cause the scale or intermediate result to overflow. I’ll 
update the implementation to perform the scaling computation in float32 for 
low-precision inputs and cast the final result back to the original dtype. I’ll 
also add regression tests covering both positive and negative decimals for 
float16 and bfloat16.
   
   For very large decimals such as 309, I’ll also avoid constructing 
10**decimals as a large Python integer before converting it to the target 
dtype. I’ll handle scale construction/overflow explicitly in the target 
floating-point dtype so that valid torch.round inputs do not fail during import.
   
   I’ll push an updated commit with these changes and the corresponding 
regression tests. Thanks again for pointing these out.


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