Skip to content
class

Log2Backward

Log2Backward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise base-2 logarithm y=log⁡2(x)y = \log_2(x).

Saves the input x; the backward divides by xln⁡2x \ln 2. The constant ln⁡2\ln 2 is materialised in grad_formula as a high-precision literal so accuracy is identical to scaling by 1 / log(2.0).

Math

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

Attributes

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

Notes

Dispatch: Accelerate vvlog2f/vvlog2 (CPU) / MLX log2 (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::log2 to compute y=log⁡2xy = \log_2 x.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=1/(xln⁡2)\partial y/\partial x = 1/(x \ln 2), scaled by grad_out.

fn

grad_formula_impl

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

Graph-mode backward: the same derivative built from composable ops, so the gradient itself stays differentiable.