/** * cpu_ops.ts — the small set of exact CPU primitives the reference forward and * backward passes share (linear, RMSNorm, SiLU, softplus). * * Each one mirrors a WGSL kernel exactly, so a gradient computed here is the * gradient of the function the GPU actually evaluates. They are deliberately * plain loops over `Float32Array`: correctness first, and small enough that the * finite-difference check in `tests/backprop.test.ts` is meaningful. */ /** Epsilon used by `rmsnorm_forward` in `ACTIVATIONS_WGSL`. */ export declare const RMSNORM_EPS = 0.000001; export declare function sigmoid(x: number): number; /** SiLU(x) = x * sigmoid(x) — mirrors `silu_forward`. */ export declare function silu(x: number): number; /** d/dx SiLU(x) = sigmoid(x) * (1 + x * (1 - sigmoid(x))). */ export declare function siluGrad(x: number): number; /** Numerically stable softplus — mirrors the kernel's `max(x,0) + log1p(exp(-|x|))`. */ export declare function softplus(x: number): number; /** * Y = X @ W^T + b, mirroring `linear_forward`. * * @param X (M, K) * @param W (N, K) row-major * @param b (N,) * @param out (M, N) — written, not accumulated */ export declare function linearForward(X: Float32Array, W: Float32Array, b: Float32Array, M: number, K: number, N: number, out: Float32Array): void; /** * Backward of {@link linearForward}. `dX` is written; `dW` and `db` are * ACCUMULATED into (so one parameter can collect gradient from several call * sites without a temporary). */ export declare function linearBackward(dY: Float32Array, X: Float32Array, W: Float32Array, M: number, K: number, N: number, dX: Float32Array, dW: Float32Array, db: Float32Array): void; /** * RMSNorm forward — mirrors `rmsnorm_forward`: * inv[r] = 1 / sqrt(mean(x[r]²) + eps); y[r,i] = x[r,i] * inv[r] * w[i] */ export declare function rmsNormForward(x: Float32Array, w: Float32Array, M: number, D: number, out: Float32Array, inv: Float32Array, eps?: number): void; /** * RMSNorm backward. `dx` and `dw` are ACCUMULATED into — `dx` in particular is * usually the residual path, which already carries a gradient. */ export declare function rmsNormBackward(dY: Float32Array, x: Float32Array, w: Float32Array, inv: Float32Array, M: number, D: number, dx: Float32Array, dw: Float32Array, _eps?: number): void; //# sourceMappingURL=cpu_ops.d.ts.map