Class MultiHeadSelfAttention
java.lang.Object
io.github.kirstenali.deepj.layers.transformer.attention.MultiHeadSelfAttention
- Direct Known Subclasses:
RoPEMultiHeadSelfAttention
Multi-head causal self-attention for a single sequence (no batch dimension).
Input/Output shape: [seqLen x dModel]
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMultiHeadSelfAttention(int dModel, int nHeads, boolean causalMask, Random rnd) -
Method Summary
Modifier and TypeMethodDescriptionprotected TensortransformQueryKey(Tensor heads, int seqLen) Hook called on split-head Q and K tensors ([nHeads·seqLen × headDim]) before the scaled dot-product.protected TensortransformQueryKeyBackward(Tensor gradHeads, int seqLen) Inverse oftransformQueryKey(io.github.kirstenali.deepj.tensor.Tensor, int), called on Q/K gradients in backward.
-
Field Details
-
nHeads
protected final int nHeadsExposed to subclasses that need head count for custom Q/K transforms (e.g. RoPE). -
headDim
protected final int headDimExposed to subclasses that need per-head dimension for custom Q/K transforms.
-
-
Constructor Details
-
MultiHeadSelfAttention
-
-
Method Details
-
forward
-
backward
-
transformQueryKey
Hook called on split-head Q and K tensors ([nHeads·seqLen × headDim]) before the scaled dot-product. No-op by default; override to apply RoPE etc. -
transformQueryKeyBackward
Inverse oftransformQueryKey(io.github.kirstenali.deepj.tensor.Tensor, int), called on Q/K gradients in backward. No-op by default; override to invert whatever forward transform was applied. -
parameters
- Specified by:
parametersin interfaceTrainable
-