forward method
Runs the transformer block forward pass.
x is the input tensor.
cache is an optional key-value cache for attention.
Returns the output tensor after attention and feed-forward layers.
Implementation
Tensor2D forward(Tensor2D x, {KVCache? cache}) {
final x1 = ln1.forward(x);
final attn = mha.forward(x1, cache: cache);
final res1 = Ops.add(x, attn);
final x2 = ln2.forward(res1);
final f = ffn.forward(x2);
return Ops.add(res1, f);
}