Skip to content
class

LogBackward

LogBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise natural logarithm y=ln⁡(x)y = \ln(x).

Saves the input x so the backward pass can divide the upstream gradient by it. Defined only for strictly positive inputs; non-positive values produce NaN / −∞-\infty, matching the reference framework.

Math

\frac{\partial y}{\partial x} = \frac{1}{x}, \qquad \frac{\partial \mathcal{L}}{\partial x} = \frac{1}{x}\,\frac{\partial \mathcal{L}}{\partial y}, \quad x > 0.$$

Attributes

schema_v1OpSchema
Registered as "log" with AmpPolicy::ForceFP32.

Notes

Dispatch: Accelerate vvlogf/vvlog (CPU) / MLX log (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::log to compute y=ln⁡xy = \ln x.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=1/x\partial y/\partial x = 1/x, scaled by grad_out.

fn

grad_formula_impl

int grad_formula_impl(const int & g, const int & x, const int &)

Graph-mode backward: ∂x=g/x\partial x = g / x kept inside the autograd graph.