class

MicroGPT::AttentionHead

Inherits Reference < Object

Constructors

new(head_dim : Int32)
Source

Instance methods

attn_weights
Source
attn_weights=(attn_weights : Mat | Nil)
Source
backward(grad : Mat) : Tuple(Mat, Mat, Mat)

Backward: returns {dq, dk, dv} for the fused projection backward

Source
forward(q : Mat, k : Mat, v : Mat, mask : Mat | Nil = nil) : Mat

Forward: compute attention from pre-projected Q, K, V If mask is provided, it's added to scores (pre-computed -inf pattern)

Source
head_dim
Source
k=(k : Mat | Nil)
Source
q=(q : Mat | Nil)
Source
v=(v : Mat | Nil)
Source