Skip to content
class

PowBackward

PowBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for elementwise tensor-tensor power y=aby = a^b with NumPy broadcasting.

Saves both inputs a and b (kSavesInputs = true inherited from BinaryKernel) because both are needed in the backward formulas. The gradient w.r.t. a is finite for any real aa; the gradient w.r.t. b is undefined when a≤0a \leq 0 because log⁡(a)\log(a) is not real — in that regime the returned gradient is non-finite and should be masked by the caller.

Math

y=ab y = a^b ∂L∂a=b⋅ab−1⋅∂L∂y \frac{\partial L}{\partial a} = b \cdot a^{b - 1} \cdot \frac{\partial L}{\partial y} ∂L∂b=log⁡(a)⋅ab⋅∂L∂y \frac{\partial L}{\partial b} = \log(a) \cdot a^b \cdot \frac{\partial L}{\partial y}

Shape

Inputs a, b follow NumPy broadcasting rules; the output y takes the broadcast shape. Both backward branches are sum-reduced back to the original input shapes by sum_to_shape in the apply trampoline.

See Also

mul_op : Elementwise multiplication. log_op : Natural logarithm (used by the ∂L/∂b\partial L/\partial b branch).

Attributes

schema_v1OpSchema
"pow", version 1, AmpPolicy::ForceFP32, integral_closed, deterministic. A floating power runs in FP32 under autocast; an integer or bool power stays in its own dtype.

Notes

For tensor-scalar power (constant exponent) prefer the scalar variant in ScalarParam.h — it skips saving the exponent tensor and avoids the log(a) * a^b branch entirely. See BinaryKernel for the broadcasting / save-tensor / reduce-to-shape machinery.

Static methods

1
static

dispatch

int dispatch(backend::IBackend & be, const int & a, const int & b, const int & shape, Dtype dt)

Route the forward computation through the backend's pow primitive.

Methods

2
fn

grad_formula

int grad_formula(const int & grad_out)

Compute the gradients for both inputs given the output gradient.

fn

grad_formula_impl

int grad_formula_impl(const int & g, const int & a_ptr, const int & b_ptr)

Graph-mode gradient for create_graph=True. dA = where(b == 0, 0, b * a^(b-1)) * g; dB = where(a == 0 && b >= 0, 0, log(a) * a^b) * g.