Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for element-wise multiplication with NumPy broadcasting.
Saves both forward inputs because the gradient w.r.t. each input depends
on the other input's value (product rule). Broadcast-reduces each
branch back to the original input shape via sum_to_shape inside
BinaryKernel::apply.
Math
Shape
Inputs follow NumPy broadcasting; output has the broadcasted shape. Each gradient is then reduced to the original input's shape.
See Also
AddBackward, SubBackward, DivBackward
Attributes
kSavesInputsbooltrue (inherited default from BinaryKernel) — both forward inputs are retained for the backward pass.schema_v1OpSchema"mul", schema version 1, AmpPolicy::Promote, deterministic.Notes
CPU dispatch uses Accelerate vDSP_vmul / vDSP_vmulD for F32 / F64.
GPU dispatch uses MLX's broadcast-aware multiply primitive.
Static methods
1dispatch
→Storageint dispatch(backend::IBackend & be, const int & a, const int & b, const int & shape, Dtype dt)Forward dispatch hook called by BinaryKernel::forward.
Parameters
bebackend::IBackend&a, bconst Storage&shape.shapeconst Shape&dtDtypeReturns
StorageOutput storage holding .
Methods
2Compute the storage-level gradients for both operands (product rule).
Math
Parameters
grad_outconst Storage&Returns
std::pair<Storage, Storage>(dA, dB) where dA = grad_out * b_broadcast and dB = grad_out * a_broadcast. Both still at output shape; BinaryKernel::apply performs the broadcast reduction.
Notes
Uses saved_input_broadcasted(k) to expand each saved input to the
broadcast output shape before the element-wise multiplication.
grad_formula_impl
→std::pair<TensorImplPtr, TensorImplPtr>int grad_formula_impl(const int & grad_out, const int & a, const int & b)Graph-mode (TensorImpl) variant of the gradient.
Parameters
grad_outconst TensorImplPtr&a, bconst TensorImplPtr&out_shape_ by BinaryKernel.Returns
std::pair<TensorImplPtr, TensorImplPtr>(grad_out * b, grad_out * a).