Skip to content

broadcast_mul

Elementwise product of equal-rank tensors, broadcasting size-1 axes.

Category: arithmetic · Identity: broadcast_mul@1

Shape

a, b -> out

Relation: equal rank and batch; each non-batch axis is equal or size 1; output takes the larger extent

Port Direction Pattern dtype
a input a compute
b input b compute
out output out compute

Arguments

This operator takes no scalar arguments.

Description

Compute a * b with equal-rank, non-batch broadcasting.

For example, [B,T,D] * [B,1,D] applies one channel gate per image. Both operands must have the same batch and rank; reshape style vectors explicitly. Gradients sum over broadcast axes, including for higher derivatives. No parameters or buffers; train and eval are identical. Use mul when broadcasting should be forbidden.

Examples

Example 1

A per-image channel gate scales every token.

h = linear(8)
g = mean(h, 1, keepdim=True)
broadcast_mul(h, g)

Input ['B', 6, 4] → output ['B', 6, 8].

Network: [B, 6, 4] -> [B, 6, 8]  dtype=float32
name  operation      input shapes                                      output shapes
n0    linear         x=input:x:[B, 6, 4]                               out=[B, 6, 8]
n1    mean           x=node:n0/out:[B, 6, 8]                           out=[B, 1, 8]
n2    broadcast_mul  a=node:n0/out:[B, 6, 8], b=node:n1/out:[B, 1, 8]  out=[B, 6, 8]

Parameters: 40