I'm having a bit of trouble understanding the semantics of broadcast_in_dim. #108
Replies: 2 comments 5 replies
-
The broadcast dimension maps from the axis of the operand `%operand:
tensor<1x3xi32>` to the axis of the result `%result: tensor<2x3x2xi32>`.
For example, the dimension size 3 at axis 1 of the operand is mapped to the
axis broadcast_dimensions[1] (==1) of the result. Similarly, the dimension
size 1 at axis 0 of the operand is mapped to the axis
broadcast_dimensions[0] (==2) of the result. However, we can see the
dimension size at axis 2 of result is 2. This is a special case of
broadcasting called degenerative broadcasting, where the dimension size, 1
at axis 0, of the operand will be broadcasted to dimension size 2 at axis
2 of the result. (
https://openxla.org/xla/broadcasting#broadcasting_similar-rank_arrays_with_degenerate_dimensions
). Also there could be axes of result which are not covered via the
broadcast_dimensions mapping (e.g. axis 0 of result) which will be
considered as the extra dimensions added.
Let me know if this helps.
…On Mon, Feb 19, 2024 at 2:55 PM lonely eagle ***@***.***> wrote:
The description of the problem is actually quite simple, I didn't
understand the semantics of broadcast_in_dim. I've looked at the relevant
examples, but still can't get my head around it. I'm a bit lost.
// %operand: [
// [1, 2, 3]
// ]
%result = "stablehlo.broadcast_in_dim"(%operand) {
broadcast_dimensions = array<i64: 2, 1>
} : (tensor<1x3xi32>) -> tensor<2x3x2xi32>
// %result: [
// [
// [1, 1],
// [2, 2],
// [3, 3]
// ],
// [
// [1, 1],
// [2, 2],
// [3, 3]
// ]
// ]
In this example above, what I am puzzled about is how it is possible to
make 2 dimensions into 3 dimensions, which is actually ok, what I can't
understand the most is broadcast_dimensions, I've been thinking about it
for a long time and I don't have a clue. I hope someone can help me, thanks!
—
Reply to this email directly, view it on GitHub
<#108>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABISCFL62BCLVM2ES6UXYPTYUNRUNAVCNFSM6AAAAABDPTLJ7GVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGIZTSOJWGY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The Overall, the semantics of the operation is that the operand shape is broadcast to the output shape. In the example, the operand shape is [1,3]. Using the mapping Please let me know if this helps. |
Beta Was this translation helpful? Give feedback.
-
The description of the problem is actually quite simple, I didn't understand the semantics of broadcast_in_dim. I've looked at the relevant examples, but still can't get my head around it. I'm a bit lost.
In this example above, what I am puzzled about is how it is possible to make 2 dimensions into 3 dimensions, which is actually ok, what I can't understand the most is broadcast_dimensions, I've been thinking about it for a long time and I don't have a clue. I hope someone can help me, thanks!
Beta Was this translation helpful? Give feedback.
All reactions