Skip to content
class

PowScalarBackward

PowScalarBackward

Autograd node for scalar-exponent power: y=xexpy = x^{\text{exp}}.

The exponent is a Python float (here promoted to double) captured on the node at forward time; the input tensor is saved so the backward pass can reconstruct xexp−1x^{\text{exp}-1} via the same backend kernel.

Math

Forward

yi=xiexpy_i = x_i^{\text{exp}}

Backward

\cdot \frac{\partial L}{\partial y_i}$$ **See Also** `RPowScalarBackward`, `pow_scalar_op`.

Attributes

exp_double
Scalar exponent captured at forward; reused inside grad_formula to compute xexp−1x^{\text{exp}-1} and the leading multiplier.
schema_v1OpSchema
Op name "pow_scalar" with AmpPolicy::ForceFP32 (integer / half precision are unsafe for arbitrary exponents).

Notes

Capturing only the scalar (rather than baking it into the op name) keeps the op table small. pow_scalar is reused inside grad_formula to compute xexp−1x^{\text{exp}-1} — no separate "decrement-exponent" kernel.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & a, double exp)

Forward dispatch with scalar capture — computes y=xexpy = x^{\text{exp}} and wires the backward node manually so exp is persisted.

Parameters

aconst TensorImplPtr&
Input tensor (must be non-null; promoted to FP32 by the schema).
expdouble
Scalar exponent.

Returns

TensorImplPtr

Output tensor with the same shape and (post-promotion) dtype as a; the backward node carries exp.

Methods

2
fn

grad_formula

→Storage
int grad_formula(const int & g)

Computes ∂L/∂x=exp⋅xexp−1⋅g\partial L/\partial x = \text{exp} \cdot x^{\text{exp}-1} \cdot g from the saved input and the captured exp_.

Parameters

gconst Storage&
Upstream gradient ∂L/∂y\partial L/\partial y.

Returns

Storage

Gradient with respect to x — same shape, dtype, and device as the saved input.

fn

grad_formula_impl

→TensorImplPtr
int grad_formula_impl(const int & g, const int & a, const int & out)

Graph-mode equivalent of grad_formula used when higher-order autograd is enabled — produces a fresh TensorImpl whose own backward chain remains intact.

Math

∂∂x(xe)=e⋅xe−1\frac{\partial}{\partial x}(x^e) = e \cdot x^{e-1}

Parameters

gconst TensorImplPtr&
Upstream gradient tensor ∂L/∂y\partial L/\partial y.
aconst TensorImplPtr&
Saved input tensor.
/* out */const TensorImplPtr&
Saved output tensor (unused; preserved for signature parity with other grad_formula_impl overrides).

Returns

TensorImplPtr

Tensor representing exp⋅xexp−1⋅g\text{exp} \cdot x^{\text{exp}-1} \cdot g with a live autograd graph.