Skip to content

Transform Operators

An orthogonal transform along one axis. A transform rotates a tensor before it is quantized; the quantization that follows one is on the Quantization page.

Walsh-Hadamard

The rotation step of rotation-based quantization, which spreads outliers across channels so a lower bit width stays accurate.

tileops.transform.HadamardTransformFwdOp

Fast Walsh-Hadamard transform of the last axis, scaled by 1 / sqrt(n).

The row length is n = base_order * m with m a power of two. Read as base_order segments of m, a row becomes x @ kron(B, H_m) / sqrt(n): H_m is the Sylvester Hadamard matrix and B is :meth:base_matrix, the order-base_order Hadamard matrix fast_hadamard_transform's hadamard_transform_12N / 20N / 28N / 40N use. Those kernels do not reduce to this product below m = 4; this op does at every m.

Every add and subtract is a float32 operation on the 16-bit input, and the result rounds once to the input dtype. An output is a sum of n terms of the input's magnitude taken log2(m) levels deep, plus base_order terms where it is above 1, so a cancellation to far below the input's magnitude keeps only float32's precision of those terms.

__init__

__init__(
    base_order=1,
    *,
    target=None
)

Build the op. The row length and dtype are taken from each call.

Parameters:

  • base_order (int, default: 1 ) –

    The order of the Hadamard matrix that mixes the row's segments: 1 for a power-of-two row, or 12, 20, 28 or 40.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    x,
)

Transform the last axis of x.

Parameters:

  • x (Tensor) –

    Input of shape (..., n), float16 or bfloat16.

Returns:

  • Tensor –

    A new tensor shaped and typed as x.