-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize ttnn.round
with a direct implementation
#13385
Comments
Hi @jdh8 , |
Thanks for pointing it out! I missed the parameter It can be managed with multiplication by 10n. To be specific, round(x, n) = 10**-n * round(10**n * x) |
I have two proposals:
Which approach looks better? |
I think approach two would be more suitable, as it has a straightforward structure. |
@jdh8 Tested the rounding in the torch round uses banker's rounding algorithm where it follows round nearest even approach, for example for the input Torch result is
Please find the image below (Red is TT's output and Green is Torch output) |
Rounding is only supported by Wormhole, and Wormhole, and Wormhole has the exact function
float_to_int16
if the value is in range.https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/apis/kernel_apis/sfpu/llk.rst#wormhole-only
However,
ttnn.round
is implemented as a combination ofttnn.floor
,ttnn.add
, etc.tt-metal/ttnn/cpp/ttnn/operations/eltwise/unary/device/unary_composite_op.cpp
Lines 640 to 653 in 679b8d5
Then in turn,
ttnn.floor
calls functions that effectively computesttnn.round
.tt-metal/tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_floor.h
Lines 25 to 26 in 679b8d5
Rounding to a nearest integer is extremely useful for argument reduction. We can reuse a direct implementation in other mathematical functions (mostly elementary functions) such as:
ttnn.pow
The text was updated successfully, but these errors were encountered: