Record Class QwenModelArgs
java.lang.Object
java.lang.Record
smile.llm.model.qwen.QwenModelArgs
- Record Components:
dim- token embedding / hidden size.numLayers- number of hybrid decoder blocks.numHeads- number of query attention heads (full-attn layers).numKvHeads- number of key/value heads (full-attn layers).headDim- attention head dimension (may differ fromdim/numHeads).vocabSize- vocabulary size.intermediateSize- SwiGLU FFN hidden size.normEps- RMSNorm epsilon.ropeTheta- RoPE base theta.partialRotaryFactor- fraction ofheadDimrotated by RoPE.linearConvKernelDim- Gated DeltaNet causal conv kernel size.linearKeyHeadDim- DeltaNet key head dimension.linearValueHeadDim- DeltaNet value head dimension.linearNumKeyHeads- DeltaNet key head count.linearNumValueHeads- DeltaNet value head count.layerTypes- per-layer mixer type (linear_attentionorfull_attention).maxBatchSize- maximum inference batch size.maxSeqLen- maximum sequence length.mtpNumHiddenLayers- native MTP draft layers (0= none).defaultNumSpeculativeTokens- default draft depth when speculation is enabled.
public record QwenModelArgs(int dim, int numLayers, int numHeads, int numKvHeads, int headDim, int vocabSize, int intermediateSize, double normEps, double ropeTheta, double partialRotaryFactor, int linearConvKernelDim, int linearKeyHeadDim, int linearValueHeadDim, int linearNumKeyHeads, int linearNumValueHeads, String[] layerTypes, int maxBatchSize, int maxSeqLen, int mtpNumHiddenLayers, int defaultNumSpeculativeTokens)
extends Record
Qwen3.5 dense hybrid text-tower hyperparameters.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTiny defaults suitable for unit tests.QwenModelArgs(int dim, int numLayers, int numHeads, int numKvHeads, int headDim, int vocabSize, int intermediateSize, double normEps, double ropeTheta, double partialRotaryFactor, int linearConvKernelDim, int linearKeyHeadDim, int linearValueHeadDim, int linearNumKeyHeads, int linearNumValueHeads, String[] layerTypes, int maxBatchSize, int maxSeqLen) Constructor without MTP fields (mtpNumHiddenLayers = 0).QwenModelArgs(int dim, int numLayers, int numHeads, int numKvHeads, int headDim, int vocabSize, int intermediateSize, double normEps, double ropeTheta, double partialRotaryFactor, int linearConvKernelDim, int linearKeyHeadDim, int linearValueHeadDim, int linearNumKeyHeads, int linearNumValueHeads, String[] layerTypes, int maxBatchSize, int maxSeqLen, int mtpNumHiddenLayers, int defaultNumSpeculativeTokens) Creates an instance of aQwenModelArgsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]defaultLayerTypes(int numLayers, int interval) Builds the default 3:1 hybrid layer type pattern.intReturns the value of thedefaultNumSpeculativeTokensrecord component.intdim()Returns the value of thedimrecord component.final booleanIndicates whether some other object is "equal to" this one.static QwenModelArgsfromHuggingFace(String path, int maxBatchSize, int maxSeqLen) Loads hyperparameters from a HuggingFaceconfig.json.static QwenModelArgsfromTextConfig(tools.jackson.databind.JsonNode text, int maxBatchSize, int maxSeqLen) Parses a text-config JSON object into model args.intfullAttentionLayerIndex(int stackLayerId) Maps a stack layer id to the KV-cache pool layer index, or-1when the stack layer is linear attention.final inthashCode()Returns a hash code value for this object.booleanhasMtp()Returns whether a native MTP head is configured.intheadDim()Returns the value of theheadDimrecord component.intReturns the value of theintermediateSizerecord component.Returns a KV cache layout covering only full-attention layers.kvCacheLayout(TensorShardSpec shard) KV layout for a tensor-parallel shard (local KV head count).String[]Returns the value of thelayerTypesrecord component.intlinearAttentionLayerIndex(int stackLayerId) Maps a stack layer id to the DeltaNet state-pool layer index, or-1when the stack layer is full attention.intDeltaNet fused QKV channel count (2*key_dim + value_dim).intlinearConvDim(TensorShardSpec shard) Local DeltaNet conv channel count for a TP shard.intReturns the value of thelinearConvKernelDimrecord component.intReturns the value of thelinearKeyHeadDimrecord component.intReturns the value of thelinearNumKeyHeadsrecord component.intReturns the value of thelinearNumValueHeadsrecord component.intReturns the value of thelinearValueHeadDimrecord component.intReturns the value of themaxBatchSizerecord component.intReturns the value of themaxSeqLenrecord component.intReturns the value of themtpNumHiddenLayersrecord component.doublenormEps()Returns the value of thenormEpsrecord component.intReturns the number of full-attention layers.intnumHeads()Returns the value of thenumHeadsrecord component.intReturns the value of thenumKvHeadsrecord component.intReturns the value of thenumLayersrecord component.intReturns the number of linear-attention (DeltaNet) layers.doubleReturns the value of thepartialRotaryFactorrecord component.intresolveNumSpeculativeTokens(int requested) Resolves draft depth for a request, capped atMAX_SPECULATIVE_TOKENS.doubleReturns the value of theropeThetarecord component.intReturns the rotary dimensionround(headDim * partialRotaryFactor).final StringtoString()Returns a string representation of this record class.intReturns the value of thevocabSizerecord component.
-
Field Details
-
LINEAR_ATTENTION
Layer type for Gated DeltaNet (linear attention).- See Also:
-
FULL_ATTENTION
-
MAX_SPECULATIVE_TOKENS
public static final int MAX_SPECULATIVE_TOKENSMaximum draft tokens per speculative round (block size 8).- See Also:
-
-
Constructor Details
-
QwenModelArgs
public QwenModelArgs()Tiny defaults suitable for unit tests. -
QwenModelArgs
public QwenModelArgs(int dim, int numLayers, int numHeads, int numKvHeads, int headDim, int vocabSize, int intermediateSize, double normEps, double ropeTheta, double partialRotaryFactor, int linearConvKernelDim, int linearKeyHeadDim, int linearValueHeadDim, int linearNumKeyHeads, int linearNumValueHeads, String[] layerTypes, int maxBatchSize, int maxSeqLen) Constructor without MTP fields (mtpNumHiddenLayers = 0).- Parameters:
dim- model hidden size.numLayers- decoder layer count.numHeads- query head count.numKvHeads- key/value head count.headDim- per-head dimension.vocabSize- vocabulary size.intermediateSize- FFN intermediate size.normEps- RMSNorm epsilon.ropeTheta- RoPE base theta.partialRotaryFactor- partial RoPE fraction.linearConvKernelDim- DeltaNet conv kernel size.linearKeyHeadDim- DeltaNet key head dim.linearValueHeadDim- DeltaNet value head dim.linearNumKeyHeads- DeltaNet key head count.linearNumValueHeads- DeltaNet value head count.layerTypes- per-layer attention type strings.maxBatchSize- max concurrent batch size.maxSeqLen- max sequence length.
-
QwenModelArgs
public QwenModelArgs(int dim, int numLayers, int numHeads, int numKvHeads, int headDim, int vocabSize, int intermediateSize, double normEps, double ropeTheta, double partialRotaryFactor, int linearConvKernelDim, int linearKeyHeadDim, int linearValueHeadDim, int linearNumKeyHeads, int linearNumValueHeads, String[] layerTypes, int maxBatchSize, int maxSeqLen, int mtpNumHiddenLayers, int defaultNumSpeculativeTokens) Creates an instance of aQwenModelArgsrecord class.- Parameters:
dim- the value for thedimrecord componentnumLayers- the value for thenumLayersrecord componentnumHeads- the value for thenumHeadsrecord componentnumKvHeads- the value for thenumKvHeadsrecord componentheadDim- the value for theheadDimrecord componentvocabSize- the value for thevocabSizerecord componentintermediateSize- the value for theintermediateSizerecord componentnormEps- the value for thenormEpsrecord componentropeTheta- the value for theropeThetarecord componentpartialRotaryFactor- the value for thepartialRotaryFactorrecord componentlinearConvKernelDim- the value for thelinearConvKernelDimrecord componentlinearKeyHeadDim- the value for thelinearKeyHeadDimrecord componentlinearValueHeadDim- the value for thelinearValueHeadDimrecord componentlinearNumKeyHeads- the value for thelinearNumKeyHeadsrecord componentlinearNumValueHeads- the value for thelinearNumValueHeadsrecord componentlayerTypes- the value for thelayerTypesrecord componentmaxBatchSize- the value for themaxBatchSizerecord componentmaxSeqLen- the value for themaxSeqLenrecord componentmtpNumHiddenLayers- the value for themtpNumHiddenLayersrecord componentdefaultNumSpeculativeTokens- the value for thedefaultNumSpeculativeTokensrecord component
-
-
Method Details
-
hasMtp
public boolean hasMtp()Returns whether a native MTP head is configured.- Returns:
truewhen a native MTP head is configured.
-
resolveNumSpeculativeTokens
public int resolveNumSpeculativeTokens(int requested) Resolves draft depth for a request, capped atMAX_SPECULATIVE_TOKENS.- Parameters:
requested-<= 0usesdefaultNumSpeculativeTokens().- Returns:
- draft count in
[0, MAX_SPECULATIVE_TOKENS].
-
rotaryDim
public int rotaryDim()Returns the rotary dimensionround(headDim * partialRotaryFactor).- Returns:
- rotary dim (must be even for complex RoPE).
-
numFullAttentionLayers
public int numFullAttentionLayers()Returns the number of full-attention layers.- Returns:
- full-attention layer count.
-
numLinearAttentionLayers
public int numLinearAttentionLayers()Returns the number of linear-attention (DeltaNet) layers.- Returns:
- linear-attention layer count.
-
fullAttentionLayerIndex
public int fullAttentionLayerIndex(int stackLayerId) Maps a stack layer id to the KV-cache pool layer index, or-1when the stack layer is linear attention.- Parameters:
stackLayerId- zero-based decoder layer index.- Returns:
- full-attention ordinal, or
-1.
-
linearAttentionLayerIndex
public int linearAttentionLayerIndex(int stackLayerId) Maps a stack layer id to the DeltaNet state-pool layer index, or-1when the stack layer is full attention.- Parameters:
stackLayerId- zero-based decoder layer index.- Returns:
- linear-attention ordinal, or
-1.
-
kvCacheLayout
Returns a KV cache layout covering only full-attention layers.- Returns:
- cache layout for
KvCachePool.
-
kvCacheLayout
KV layout for a tensor-parallel shard (local KV head count).- Parameters:
shard- TP shard description, ornullfor the full layout.- Returns:
- cache layout for
KvCachePool.
-
linearConvDim
Local DeltaNet conv channel count for a TP shard.- Parameters:
shard- TP shard description, ornullfor the full width.- Returns:
- conv channel count.
-
linearConvDim
public int linearConvDim()DeltaNet fused QKV channel count (2*key_dim + value_dim).- Returns:
- conv channel count.
-
fromHuggingFace
public static QwenModelArgs fromHuggingFace(String path, int maxBatchSize, int maxSeqLen) throws IOException Loads hyperparameters from a HuggingFaceconfig.json. Accepts either a top-level text config (qwen3_5_text) or a multimodal wrapper with nestedtext_config.- Parameters:
path- path toconfig.json.maxBatchSize- maximum batch size.maxSeqLen- maximum sequence length;<= 0derives frommax_position_embeddingsin the config.- Returns:
- model args.
- Throws:
IOException- if the file cannot be read.
-
fromTextConfig
public static QwenModelArgs fromTextConfig(tools.jackson.databind.JsonNode text, int maxBatchSize, int maxSeqLen) Parses a text-config JSON object into model args.- Parameters:
text- text config node.maxBatchSize- maximum batch size.maxSeqLen- maximum sequence length;<= 0derives frommax_position_embeddingsin the config.- Returns:
- model args.
-
defaultLayerTypes
Builds the default 3:1 hybrid layer type pattern.- Parameters:
numLayers- number of layers.interval- full-attention interval (every N-th layer is full).- Returns:
- layer type array.
-
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
public int numKvHeads()Returns the value of thenumKvHeadsrecord component.- Returns:
- the value of the
numKvHeadsrecord component
-
headDim
-
vocabSize
-
intermediateSize
public int intermediateSize()Returns the value of theintermediateSizerecord component.- Returns:
- the value of the
intermediateSizerecord component
-
normEps
-
ropeTheta
-
partialRotaryFactor
public double partialRotaryFactor()Returns the value of thepartialRotaryFactorrecord component.- Returns:
- the value of the
partialRotaryFactorrecord component
-
linearConvKernelDim
public int linearConvKernelDim()Returns the value of thelinearConvKernelDimrecord component.- Returns:
- the value of the
linearConvKernelDimrecord component
-
linearKeyHeadDim
public int linearKeyHeadDim()Returns the value of thelinearKeyHeadDimrecord component.- Returns:
- the value of the
linearKeyHeadDimrecord component
-
linearValueHeadDim
public int linearValueHeadDim()Returns the value of thelinearValueHeadDimrecord component.- Returns:
- the value of the
linearValueHeadDimrecord component
-
linearNumKeyHeads
public int linearNumKeyHeads()Returns the value of thelinearNumKeyHeadsrecord component.- Returns:
- the value of the
linearNumKeyHeadsrecord component
-
linearNumValueHeads
public int linearNumValueHeads()Returns the value of thelinearNumValueHeadsrecord component.- Returns:
- the value of the
linearNumValueHeadsrecord component
-
layerTypes
Returns the value of thelayerTypesrecord component.- Returns:
- the value of the
layerTypesrecord component
-
maxBatchSize
public int maxBatchSize()Returns the value of themaxBatchSizerecord component.- Returns:
- the value of the
maxBatchSizerecord component
-
maxSeqLen
-
mtpNumHiddenLayers
public int mtpNumHiddenLayers()Returns the value of themtpNumHiddenLayersrecord component.- Returns:
- the value of the
mtpNumHiddenLayersrecord component
-
defaultNumSpeculativeTokens
public int defaultNumSpeculativeTokens()Returns the value of thedefaultNumSpeculativeTokensrecord component.- Returns:
- the value of the
defaultNumSpeculativeTokensrecord component
-