Record Class LlamaModelArgs
java.lang.Object
java.lang.Record
smile.llm.model.llama.LlamaModelArgs
- Record Components:
dim- the dimension of token embedding.numLayers- the number of transformer blocks.numHeads- the number of attention heads.numKvHeads- the number of key and value heads.vocabSize- the size of the vocabulary.multipleOf- make SwiGLU hidden layer size multiple of large power of 2.ffnDimMultiplier- the multiplier for the hidden dimension of the feedforward layers.intermediateSize- the explicit FFN hidden dimension size (takes priority over multipleOf/ffnDimMultiplier). When non-null, the FeedForward layer uses this size directly, as provided by HuggingFaceconfig.json'sintermediate_sizefield.normEps- the epsilon value used for numerical stability in normalization layers.ropeTheta- the theta parameter in rotary positional encoding.scaledRope- scale RoPE positional encoding if true.maxBatchSize- the maximum batch size.maxSeqLen- the maximum sequence length for input data.
public record LlamaModelArgs(int dim, int numLayers, int numHeads, Integer numKvHeads, int vocabSize, int multipleOf, Double ffnDimMultiplier, Integer intermediateSize, double normEps, double ropeTheta, boolean scaledRope, int maxBatchSize, int maxSeqLen)
extends Record
Llama / Meta dense-decoder hyperparameters.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default parameter values.LlamaModelArgs(int dim, int numLayers, int numHeads, Integer numKvHeads, int vocabSize, int multipleOf, Double ffnDimMultiplier, double normEps, double ropeTheta, boolean scaledRope, int maxBatchSize, int maxSeqLen) Constructor without an explicit FFN intermediate size (Meta-format layout).LlamaModelArgs(int dim, int numLayers, int numHeads, Integer numKvHeads, int vocabSize, int multipleOf, Double ffnDimMultiplier, Integer intermediateSize, double normEps, double ropeTheta, boolean scaledRope, int maxBatchSize, int maxSeqLen) Creates an instance of aLlamaModelArgsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintdim()Returns the value of thedimrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theffnDimMultiplierrecord component.static LlamaModelArgsLoads the model hyperparameters from a Meta-formatparams.jsonfile.static LlamaModelArgsfromHuggingFace(String path, int maxBatchSize, int maxSeqLen) Loads the model hyperparameters from a HuggingFaceconfig.jsonfile.final inthashCode()Returns a hash code value for this object.intheadDim()Returnsdim / numHeads.Returns the value of theintermediateSizerecord component.Returns aKvCacheLayoutderived from these hyperparameters.intReturns the value of themaxBatchSizerecord component.intReturns the value of themaxSeqLenrecord component.intReturns the value of themultipleOfrecord component.doublenormEps()Returns the value of thenormEpsrecord component.intnumHeads()Returns the value of thenumHeadsrecord component.Returns the value of thenumKvHeadsrecord component.intReturns the value of thenumLayersrecord component.intReturns the resolved number of key/value heads (falls back tonumHeads()).doubleReturns the value of theropeThetarecord component.booleanReturns the value of thescaledRoperecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thevocabSizerecord component.
-
Constructor Details
-
LlamaModelArgs
public LlamaModelArgs()Constructor with default parameter values. -
LlamaModelArgs
public LlamaModelArgs(int dim, int numLayers, int numHeads, Integer numKvHeads, int vocabSize, int multipleOf, Double ffnDimMultiplier, double normEps, double ropeTheta, boolean scaledRope, int maxBatchSize, int maxSeqLen) Constructor without an explicit FFN intermediate size (Meta-format layout). The feed-forward hidden dimension is derived frommultipleOf/ffnDimMultiplier.- Parameters:
dim- the dimension of token embedding.numLayers- the number of transformer blocks.numHeads- the number of attention heads.numKvHeads- the number of key and value heads.vocabSize- the size of the vocabulary.multipleOf- make SwiGLU hidden layer size multiple of large power of 2.ffnDimMultiplier- the multiplier for the hidden dimension of the feedforward layers.normEps- the epsilon value used for numerical stability in normalization layers.ropeTheta- the theta parameter in rotary positional encoding.scaledRope- scale RoPE positional encoding if true.maxBatchSize- the maximum batch size.maxSeqLen- the maximum sequence length for input data.
-
LlamaModelArgs
public LlamaModelArgs(int dim, int numLayers, int numHeads, Integer numKvHeads, int vocabSize, int multipleOf, Double ffnDimMultiplier, Integer intermediateSize, double normEps, double ropeTheta, boolean scaledRope, int maxBatchSize, int maxSeqLen) Creates an instance of aLlamaModelArgsrecord class.- Parameters:
dim- the value for thedimrecord componentnumLayers- the value for thenumLayersrecord componentnumHeads- the value for thenumHeadsrecord componentnumKvHeads- the value for thenumKvHeadsrecord componentvocabSize- the value for thevocabSizerecord componentmultipleOf- the value for themultipleOfrecord componentffnDimMultiplier- the value for theffnDimMultiplierrecord componentintermediateSize- the value for theintermediateSizerecord componentnormEps- the value for thenormEpsrecord componentropeTheta- the value for theropeThetarecord componentscaledRope- the value for thescaledRoperecord componentmaxBatchSize- the value for themaxBatchSizerecord componentmaxSeqLen- the value for themaxSeqLenrecord component
-
-
Method Details
-
resolvedNumKvHeads
public int resolvedNumKvHeads()Returns the resolved number of key/value heads (falls back tonumHeads()).- Returns:
- KV head count.
-
headDim
public int headDim()Returnsdim / numHeads.- Returns:
- attention head dimension.
-
kvCacheLayout
Returns aKvCacheLayoutderived from these hyperparameters.- Returns:
- cache layout for
KvCachePool.
-
from
Loads the model hyperparameters from a Meta-formatparams.jsonfile.- Parameters:
path- the file path.maxBatchSize- the maximum batch size.maxSeqLen- the maximum sequence length for input data.- Returns:
- the model hyperparameters.
- Throws:
IOException- if fail to open the parameter file.
-
fromHuggingFace
public static LlamaModelArgs fromHuggingFace(String path, int maxBatchSize, int maxSeqLen) throws IOException Loads the model hyperparameters from a HuggingFaceconfig.jsonfile. Theconfig.jsonuses different field names and conventions from Meta'sparams.json, notablyhidden_sizeinstead ofdimandintermediate_sizeinstead of a computed FFN hidden dim.- Parameters:
path- the file path.maxBatchSize- the maximum batch size.maxSeqLen- the maximum sequence length;<= 0derives frommax_position_embeddings.- Returns:
- the model hyperparameters.
- Throws:
IOException- if fail to open the config file.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
dim
-
numLayers
-
numHeads
-
numKvHeads
Returns the value of thenumKvHeadsrecord component.- Returns:
- the value of the
numKvHeadsrecord component
-
vocabSize
-
multipleOf
public int multipleOf()Returns the value of themultipleOfrecord component.- Returns:
- the value of the
multipleOfrecord component
-
ffnDimMultiplier
Returns the value of theffnDimMultiplierrecord component.- Returns:
- the value of the
ffnDimMultiplierrecord component
-
intermediateSize
Returns the value of theintermediateSizerecord component.- Returns:
- the value of the
intermediateSizerecord component
-
normEps
-
ropeTheta
-
scaledRope
public boolean scaledRope()Returns the value of thescaledRoperecord component.- Returns:
- the value of the
scaledRoperecord component
-
maxBatchSize
public int maxBatchSize()Returns the value of themaxBatchSizerecord component.- Returns:
- the value of the
maxBatchSizerecord component
-
maxSeqLen
-