Skip to content
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

TTNN throws an exception if second operand of binary Ops require broadcast #13566

Open
Tracked by #13795
uazizTT opened this issue Oct 8, 2024 · 9 comments
Open
Tracked by #13795
Assignees

Comments

@uazizTT
Copy link

uazizTT commented Oct 8, 2024

TTNN throws the following exception when trying to broadcast second operand of a binary op:

RuntimeError: TT_THROW @ tt-metal/src/tt-metal/ttnn/cpp/ttnn/operations/eltwise/binary/device/binary_device_operation.cpp:46: tt::exception

TT_THROW("ttnn::operations::binary::BinaryDeviceOperation: unsupported broadcast");

Apply canonicalization on the operands or allow broadcasting for all operands.

@eyonland
Copy link
Contributor

eyonland commented Oct 8, 2024

Please attach a pytest to reproduce this exact case.

Also, note that the workaround we currently have for broadcasting is to use the ttnn.bcast. For example https://github.com/tenstorrent/tt-metal/blob/main/models/demos/t3000/falcon40b/tt/model_utils.py#L504

@umadevimcw
Copy link
Contributor

@uazizTT Kindly provide the examples to debug further on this issue

@uazizTT
Copy link
Author

uazizTT commented Oct 31, 2024

@umadevimcw Just trying to understand what kind of example you need, if I send you a test case from tt-mlir compiler that asserts at this bug, does that work for you?

@KalaivaniMCW
Copy link
Contributor

KalaivaniMCW commented Nov 4, 2024

@uazizTT Yes any unit test to reproduce would be fine.
Could you specify the binary op which you tested and the shapes and dtypes and memory_config used.
At present broadcast support works only for add, sub and mul.
There is a work in progress #13643 to provide broadcast support

@prajaramanTT
Copy link

@KalaivaniMCW @uazizTT Is this still an open issue ? If not, can you please close this ticket ? Thanks.

@uazizTT
Copy link
Author

uazizTT commented Jan 9, 2025

@KalaivaniMCW @uazizTT Is this still an open issue ? If not, can you please close this ticket ? Thanks.

I think we still need this issue to track support of broadcast across all binary ops. If someone has a list of ops that support broadcasting for both operands of a binary op then please update it here.

@KalaivaniMCW
Copy link
Contributor

KalaivaniMCW commented Jan 16, 2025

@uazizTT The broadcast support for binary operations has been added under binary_ng, the ops available as ttnn.experimental.add etc.
The list of binary ops with new broadcast support here
We are planning to integrate the functionality to existing binary op apis as well after profiling of the ops.
Could you test the shapes that failed earlier or share the shapes and op name here ?

In case of existing binary op apis, list of ops that support broadcasting for both operands are - ttnn.add/sub/mul

@uazizTT
Copy link
Author

uazizTT commented Jan 17, 2025

@KalaivaniMCW Thank you for updating about the progress, is there any other change in the function signatures besides adding experimental? If it just a name change, I can try to test it at our end.

For the shapes, you can try any number of arbitrary shapes. If you think those are working now, the next steps would be run tests from tt-mlir and tt-torch repositories. We need to update the documentation about the function signatures, but you can try to following the build steps to see if those tests are passing with these new operations.

@KalaivaniMCW
Copy link
Contributor

@uazizTT yes.. there maybe some features that are still in progress, like sharding and then output_dtype typecasting. That is why these new ops are under ttnn.experimental - once they have all the eltwise features they will be integrated into the existing binary op APIs.
we don't expect everyone to switch to ttnn.experimental.op as it is temporary ( but if you need to test any cases that failed earlier, you can use the ttnn.experimental API to make sure we've given the support that is expected. ) soon these features will be integrated to the ttnn.op APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants