Realm

oa::ml::matrix::causal_linear_attention

Causal kernel-trick attention on raw Q/K/V [BH,S,Dh]. Uses phi(x) = x+1 for nonnegative x and exp(x) otherwise, with max(dot(phi(Q), prefix_sum(phi(K))), epsilon) normalization. Values are not feature-mapped. The fused provider admits 1 <= Dh <= 64; sequence length has no provider cap. It saves Q/K/V, context and one denominator per row for deterministic prefix/suffix reverse mode, never a KV prefix history. Errors Returns an error for unequal/empty shapes, non-F32 or mixed-engine values, head dimension above 64, nonpositive/nonfinite epsilon, shader ABI overflow, allocation or recording failure.

FnRust public API

Function Documentation

pub fn causal_linear_attention( query: &Matrix, key: &Matrix, value: &Matrix, epsilon: f32 ) -> Result<Matrix>
Causal kernel-trick attention on raw Q/K/V [BH,S,Dh]. Uses phi(x) = x+1 for nonnegative x and exp(x) otherwise, with max(dot(phi(Q), prefix_sum(phi(K))), epsilon) normalization. Values are not feature-mapped. The fused provider admits 1 <= Dh <= 64; sequence length has no provider cap. It saves Q/K/V, context and one denominator per row for deterministic prefix/suffix reverse mode, never a KV prefix history. Errors Returns an error for unequal/empty shapes, non-F32 or mixed-engine values, head dimension above 64, nonpositive/nonfinite epsilon, shader ABI overflow, allocation or recording failure.