Class LlamaBlock
java.lang.Object
smile.llm.model.llama.LlamaBlock
A Llama dense-decoder block: grouped-query attention followed by a
SwiGLU feed-forward network, each with a residual connection and RMSNorm.
-
Constructor Summary
ConstructorsConstructorDescriptionLlamaBlock(int layerId, int dim, int numHeads, int numKvHeads, Integer intermediateSize, int multipleOf, Double ffnDimMultiplier, double normEps) Constructor.LlamaBlock(int layerId, int dim, int numHeads, int numKvHeads, Integer intermediateSize, int multipleOf, Double ffnDimMultiplier, double normEps, KvCacheLayout layout) Convenience constructor that allocates a private test-sized KV pool. -
Method Summary
Modifier and TypeMethodDescriptionReturns the attention submodule.Returns the feed-forward submodule.Decode / prefill forward with per-row cache write positions.Forward pass through the block.
-
Constructor Details
-
LlamaBlock
public LlamaBlock(int layerId, int dim, int numHeads, int numKvHeads, Integer intermediateSize, int multipleOf, Double ffnDimMultiplier, double normEps) Constructor. The attention module receives itsKvCachePoollater viaLlamaModel.setKvCachePool(KvCachePool).- Parameters:
layerId- the identifier of the block.dim- token embedding dimension.numHeads- number of query heads.numKvHeads- number of key/value heads.intermediateSize- explicit FFN hidden size, ornullto derive it.multipleOf- FFN rounding multiple whenintermediateSizeis null.ffnDimMultiplier- optional FFN dim multiplier when deriving size.normEps- RMSNorm epsilon.
-
LlamaBlock
public LlamaBlock(int layerId, int dim, int numHeads, int numKvHeads, Integer intermediateSize, int multipleOf, Double ffnDimMultiplier, double normEps, KvCacheLayout layout) Convenience constructor that allocates a private test-sized KV pool.- Parameters:
layerId- the identifier of the block.dim- token embedding dimension.numHeads- number of query heads.numKvHeads- number of key/value heads.intermediateSize- explicit FFN hidden size, ornull.multipleOf- FFN rounding multiple when deriving size.ffnDimMultiplier- optional FFN dim multiplier.normEps- RMSNorm epsilon.layout- cache layout for the private test pool.
-
-
Method Details
-
attention
-
feedForward
Returns the feed-forward submodule.- Returns:
- feed-forward submodule.
-
forward
-
forward
Decode / prefill forward with per-row cache write positions.- Parameters:
x- input hidden states.positions- absolute write position per batch row.cis- RoPE frequency tensor (uniform[S,…]or gathered[B,…]).mask- attention mask, ornull.- Returns:
- block output.
-