Record Class DeepSeekModelArgs
java.lang.Object
java.lang.Record
smile.llm.model.deepseek.DeepSeekModelArgs
- Record Components:
vocabSize- vocabulary size.dim- hidden size.numLayers- backbone layers.numHeads- query heads (one shared KV head).headDim- attention head dimension (rope dims are the lastropeHeadDim).ropeHeadDim- rotated head dimensions.qLoraRank- query low-rank dimension.oLoraRank- output low-rank dimension per group.oGroups- output projection groups.normEps- RMSNorm epsilon (1e-20in the released model).moeInterSize- routed/shared expert FFN width.numRoutedExperts- routed experts per layer.- shared experts per layer (1).numExpertsPerTok- experts per token.routeScale- multiplier on the renormalised routing weights.swigluLimit- expert activation clamp.windowSize- sliding-window length.compressRatios- per layer (backbone then MTP): 0 = window only, r = KV compressed r-to-1.kvSourceLayers- layers that compute the compressed KV the following layers share.indexSourceLayers- layers that run an indexer (the others reuse the last result).originalSeqLen- YaRN original context length.ropeTheta- RoPE base for window-only layers.compressRopeTheta- RoPE base for layers with compressed KV.ropeFactor- YaRN factor.betaFast- YaRN beta fast.betaSlow- YaRN beta slow.indexNumHeads- indexer heads.indexHeadDim- indexer head dimension.indexTopk- compressed positions kept per query.candidateSourceLayer- layer whose block scores restrict later indexers (-1= off).candidateTopkBlocks- candidate blocks kept.candidateBlockSize- positions per candidate block.hcMult- residual copies.hcSinkhornIters- Sinkhorn iterations of the connection mixing.hcEps- Hyper-Connections epsilon.engramLayers- layers with an engram lookup.engramNumEmbeddings- table rows per engram layer.engramMaxNgram- largest n-gram (n-grams of size 2..n are hashed).engramVocabSize- bucket size each (n-gram, head) starts searching primes from.engramHeads- hash heads per n-gram.engramHeadDim- table row width.engramPadId- token filling n-gram slots without history.engramCompressedVocab- compressed vocabulary size (every hash multiplier derives from it).numMtpLayers- MTP/DSpark layers.dsparkBlockSize- DSpark block size.dsparkNoiseToken- DSpark mask token.dsparkTargetLayers- backbone layers tapped by the DSpark head.dsparkMarkovRank- DSpark Markov head rank.dsparkRoutedExperts- routed experts of the MTP layers.dsparkExpertsPerTok- experts per token of the MTP layers.imageTokenId- id of the image placeholder token.maxSeqLen- maximum sequence length served (runtime, not from the config).
public record DeepSeekModelArgs(int vocabSize, int dim, int numLayers, int numHeads, int headDim, int ropeHeadDim, int qLoraRank, int oLoraRank, int oGroups, double normEps, int moeInterSize, int numRoutedExperts, int numSharedExperts, int numExpertsPerTok, double routeScale, double swigluLimit, int windowSize, int[] compressRatios, int[] kvSourceLayers, int[] indexSourceLayers, int originalSeqLen, double ropeTheta, double compressRopeTheta, double ropeFactor, int betaFast, int betaSlow, int indexNumHeads, int indexHeadDim, int indexTopk, int candidateSourceLayer, int candidateTopkBlocks, int candidateBlockSize, int hcMult, int hcSinkhornIters, double hcEps, int[] engramLayers, long[] engramNumEmbeddings, int engramMaxNgram, int engramVocabSize, int engramHeads, int engramHeadDim, int engramPadId, int engramCompressedVocab, int numMtpLayers, int dsparkBlockSize, int dsparkNoiseToken, int[] dsparkTargetLayers, int dsparkMarkovRank, int dsparkRoutedExperts, int dsparkExpertsPerTok, int imageTokenId, int maxSeqLen)
extends Record
DeepSeek-V4.1 text-tower hyperparameters (checkpoint
config.json, section text_config).
The architecture: a residual stream of hcMult parallel copies mixed by Hyper-Connections; a
single-KV-head attention with an attention sink over a sliding window plus compressed KV selected by a
two-level indexer; n-gram "engram" lookups in a few layers; and a sqrt-softplus routed MoE with FP4 experts.
Layers numLayers .. of compressRatios belong to the MTP/DSpark head.
-
Constructor Summary
ConstructorsConstructorDescriptionDeepSeekModelArgs(int vocabSize, int dim, int numLayers, int numHeads, int headDim, int ropeHeadDim, int qLoraRank, int oLoraRank, int oGroups, double normEps, int moeInterSize, int numRoutedExperts, int numSharedExperts, int numExpertsPerTok, double routeScale, double swigluLimit, int windowSize, int[] compressRatios, int[] kvSourceLayers, int[] indexSourceLayers, int originalSeqLen, double ropeTheta, double compressRopeTheta, double ropeFactor, int betaFast, int betaSlow, int indexNumHeads, int indexHeadDim, int indexTopk, int candidateSourceLayer, int candidateTopkBlocks, int candidateBlockSize, int hcMult, int hcSinkhornIters, double hcEps, int[] engramLayers, long[] engramNumEmbeddings, int engramMaxNgram, int engramVocabSize, int engramHeads, int engramHeadDim, int engramPadId, int engramCompressedVocab, int numMtpLayers, int dsparkBlockSize, int dsparkNoiseToken, int[] dsparkTargetLayers, int dsparkMarkovRank, int dsparkRoutedExperts, int dsparkExpertsPerTok, int imageTokenId, int maxSeqLen) Validates the shape relations the model code relies on. -
Method Summary
Modifier and TypeMethodDescriptionintbetaFast()Returns the value of thebetaFastrecord component.intbetaSlow()Returns the value of thebetaSlowrecord component.intReturns the value of thecandidateBlockSizerecord component.intReturns the value of thecandidateSourceLayerrecord component.intReturns the value of thecandidateTopkBlocksrecord component.intcompressRatio(int layer) Compression ratio of a layer.int[]Returns the value of thecompressRatiosrecord component.doubleReturns the value of thecompressRopeThetarecord component.intdim()Returns the value of thedimrecord component.intReturns the value of thedsparkBlockSizerecord component.intReturns the value of thedsparkExpertsPerTokrecord component.intReturns the value of thedsparkMarkovRankrecord component.intReturns the value of thedsparkNoiseTokenrecord component.intReturns the value of thedsparkRoutedExpertsrecord component.int[]Returns the value of thedsparkTargetLayersrecord component.intReturns the value of theengramCompressedVocabrecord component.intNumber of hashed columns per token and engram layer ((maxNgram - 1) * heads).intReturns the value of theengramHeadDimrecord component.intReturns the value of theengramHeadsrecord component.int[]Returns the value of theengramLayersrecord component.intReturns the value of theengramMaxNgramrecord component.long[]Returns the value of theengramNumEmbeddingsrecord component.intReturns the value of theengramPadIdrecord component.intengramSlot(int layer) Index of the layer inengramLayers.intReturns the value of theengramVocabSizerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doublehcEps()Returns the value of thehcEpsrecord component.inthcMult()Returns the value of thehcMultrecord component.intReturns the value of thehcSinkhornItersrecord component.intheadDim()Returns the value of theheadDimrecord component.intReturns the value of theimageTokenIdrecord component.intReturns the value of theindexHeadDimrecord component.intReturns the value of theindexNumHeadsrecord component.int[]Returns the value of theindexSourceLayersrecord component.intReturns the value of theindexTopkrecord component.booleanisCandidateSource(int layer) Whether the layer is the candidate-block source of the two-level top-k.booleanisIndexSource(int layer) Whether the layer runs an indexer.booleanisKvSource(int layer) Whether the layer computes (and owns the cache of) the compressed KV.int[]Returns the value of thekvSourceLayersrecord component.layerPrefix(int layer) The checkpoint name prefix of a layer:layers.Nfor the backbone,mtp.Kfor the DSpark stages (layer indicesnumLayers + K).static DeepSeekModelArgsReads the arguments from a checkpoint'sconfig.json.intReturns the value of themaxSeqLenrecord component.int[]moeConfig(int layer) Routed experts and experts per token of a layer (the MTP layers use their own counts).intReturns the value of themoeInterSizerecord component.doublenormEps()Returns the value of thenormEpsrecord component.intReturns the value of thenumExpertsPerTokrecord component.intnumHeads()Returns the value of thenumHeadsrecord component.intReturns the value of thenumLayersrecord component.intReturns the value of thenumMtpLayersrecord component.intReturns the value of thenumRoutedExpertsrecord component.intReturns the value of thenumSharedExpertsrecord component.intoGroups()Returns the value of theoGroupsrecord component.intReturns the value of theoLoraRankrecord component.intReturns the value of theoriginalSeqLenrecord component.intReturns the value of theqLoraRankrecord component.doubleReturns the value of theropeFactorrecord component.intReturns the value of theropeHeadDimrecord component.doubleReturns the value of theropeThetarecord component.doubleReturns the value of therouteScalerecord component.slice(int layers) Returns the arguments of a truncated model made of the first layers, for slice validation.doubleReturns the value of theswigluLimitrecord component.final StringtoString()Returns a string representation of this record class.booleanusesCandidates(int layer) Whether the layer's indexer only scores inside the candidate blocks.intReturns the value of thevocabSizerecord component.intReturns the value of thewindowSizerecord component.withMaxSeqLen(int maxSeqLen) Returns a copy with another maximum sequence length.
-
Constructor Details
-
DeepSeekModelArgs
public DeepSeekModelArgs(int vocabSize, int dim, int numLayers, int numHeads, int headDim, int ropeHeadDim, int qLoraRank, int oLoraRank, int oGroups, double normEps, int moeInterSize, int numRoutedExperts, int numSharedExperts, int numExpertsPerTok, double routeScale, double swigluLimit, int windowSize, int[] compressRatios, int[] kvSourceLayers, int[] indexSourceLayers, int originalSeqLen, double ropeTheta, double compressRopeTheta, double ropeFactor, int betaFast, int betaSlow, int indexNumHeads, int indexHeadDim, int indexTopk, int candidateSourceLayer, int candidateTopkBlocks, int candidateBlockSize, int hcMult, int hcSinkhornIters, double hcEps, int[] engramLayers, long[] engramNumEmbeddings, int engramMaxNgram, int engramVocabSize, int engramHeads, int engramHeadDim, int engramPadId, int engramCompressedVocab, int numMtpLayers, int dsparkBlockSize, int dsparkNoiseToken, int[] dsparkTargetLayers, int dsparkMarkovRank, int dsparkRoutedExperts, int dsparkExpertsPerTok, int imageTokenId, int maxSeqLen) Validates the shape relations the model code relies on.
-
-
Method Details
-
compressRatio
public int compressRatio(int layer) Compression ratio of a layer.- Parameters:
layer- layer index (backbone, ornumLayers + kfor MTP layer k).- Returns:
- 0 for window-only attention, otherwise the KV compression ratio.
-
isKvSource
public boolean isKvSource(int layer) Whether the layer computes (and owns the cache of) the compressed KV.- Parameters:
layer- backbone layer index.- Returns:
truefor the KV source layers.
-
isIndexSource
public boolean isIndexSource(int layer) Whether the layer runs an indexer.- Parameters:
layer- backbone layer index.- Returns:
truefor the index source layers.
-
isCandidateSource
public boolean isCandidateSource(int layer) Whether the layer is the candidate-block source of the two-level top-k.- Parameters:
layer- backbone layer index.- Returns:
truefor the candidate source layer.
-
usesCandidates
public boolean usesCandidates(int layer) Whether the layer's indexer only scores inside the candidate blocks.- Parameters:
layer- backbone layer index.- Returns:
truewhen a candidate source precedes the layer.
-
engramSlot
public int engramSlot(int layer) Index of the layer inengramLayers.- Parameters:
layer- backbone layer index.- Returns:
- the engram slot, or -1 when the layer has no engram.
-
engramHashColumns
public int engramHashColumns()Number of hashed columns per token and engram layer ((maxNgram - 1) * heads).- Returns:
- the hash column count.
-
layerPrefix
The checkpoint name prefix of a layer:layers.Nfor the backbone,mtp.Kfor the DSpark stages (layer indicesnumLayers + K).- Parameters:
layer- layer index.- Returns:
- the prefix.
-
moeConfig
public int[] moeConfig(int layer) Routed experts and experts per token of a layer (the MTP layers use their own counts).- Parameters:
layer- layer index.- Returns:
{routed, perToken}.
-
slice
Returns the arguments of a truncated model made of the first layers, for slice validation. Engram layers beyond the slice are dropped; the remaining engram layers keep their order, so primes and multipliers of a slice equal those of the full model.- Parameters:
layers- number of backbone layers to keep.- Returns:
- the truncated arguments.
-
withMaxSeqLen
Returns a copy with another maximum sequence length.- Parameters:
maxSeqLen- the new limit.- Returns:
- the new arguments.
-
load
Reads the arguments from a checkpoint'sconfig.json.- Parameters:
configJson- theconfig.jsonfile.- Returns:
- the arguments;
maxSeqLenismax_position_embeddings. - Throws:
IOException- if the file cannot be read.
-
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. -
vocabSize
-
dim
-
numLayers
-
numHeads
-
headDim
-
ropeHeadDim
public int ropeHeadDim()Returns the value of theropeHeadDimrecord component.- Returns:
- the value of the
ropeHeadDimrecord component
-
qLoraRank
-
oLoraRank
-
oGroups
-
normEps
-
moeInterSize
public int moeInterSize()Returns the value of themoeInterSizerecord component.- Returns:
- the value of the
moeInterSizerecord component
-
numRoutedExperts
public int numRoutedExperts()Returns the value of thenumRoutedExpertsrecord component.- Returns:
- the value of the
numRoutedExpertsrecord component
-
numExpertsPerTok
public int numExpertsPerTok()Returns the value of thenumExpertsPerTokrecord component.- Returns:
- the value of the
numExpertsPerTokrecord component
-
routeScale
public double routeScale()Returns the value of therouteScalerecord component.- Returns:
- the value of the
routeScalerecord component
-
swigluLimit
public double swigluLimit()Returns the value of theswigluLimitrecord component.- Returns:
- the value of the
swigluLimitrecord component
-
windowSize
public int windowSize()Returns the value of thewindowSizerecord component.- Returns:
- the value of the
windowSizerecord component
-
compressRatios
public int[] compressRatios()Returns the value of thecompressRatiosrecord component.- Returns:
- the value of the
compressRatiosrecord component
-
kvSourceLayers
public int[] kvSourceLayers()Returns the value of thekvSourceLayersrecord component.- Returns:
- the value of the
kvSourceLayersrecord component
-
indexSourceLayers
public int[] indexSourceLayers()Returns the value of theindexSourceLayersrecord component.- Returns:
- the value of the
indexSourceLayersrecord component
-
originalSeqLen
public int originalSeqLen()Returns the value of theoriginalSeqLenrecord component.- Returns:
- the value of the
originalSeqLenrecord component
-
ropeTheta
-
compressRopeTheta
public double compressRopeTheta()Returns the value of thecompressRopeThetarecord component.- Returns:
- the value of the
compressRopeThetarecord component
-
ropeFactor
public double ropeFactor()Returns the value of theropeFactorrecord component.- Returns:
- the value of the
ropeFactorrecord component
-
betaFast
-
betaSlow
-
indexNumHeads
public int indexNumHeads()Returns the value of theindexNumHeadsrecord component.- Returns:
- the value of the
indexNumHeadsrecord component
-
indexHeadDim
public int indexHeadDim()Returns the value of theindexHeadDimrecord component.- Returns:
- the value of the
indexHeadDimrecord component
-
indexTopk
-
candidateSourceLayer
public int candidateSourceLayer()Returns the value of thecandidateSourceLayerrecord component.- Returns:
- the value of the
candidateSourceLayerrecord component
-
candidateTopkBlocks
public int candidateTopkBlocks()Returns the value of thecandidateTopkBlocksrecord component.- Returns:
- the value of the
candidateTopkBlocksrecord component
-
candidateBlockSize
public int candidateBlockSize()Returns the value of thecandidateBlockSizerecord component.- Returns:
- the value of the
candidateBlockSizerecord component
-
hcMult
-
hcSinkhornIters
public int hcSinkhornIters()Returns the value of thehcSinkhornItersrecord component.- Returns:
- the value of the
hcSinkhornItersrecord component
-
hcEps
-
engramLayers
public int[] engramLayers()Returns the value of theengramLayersrecord component.- Returns:
- the value of the
engramLayersrecord component
-
engramNumEmbeddings
public long[] engramNumEmbeddings()Returns the value of theengramNumEmbeddingsrecord component.- Returns:
- the value of the
engramNumEmbeddingsrecord component
-
engramMaxNgram
public int engramMaxNgram()Returns the value of theengramMaxNgramrecord component.- Returns:
- the value of the
engramMaxNgramrecord component
-
engramVocabSize
public int engramVocabSize()Returns the value of theengramVocabSizerecord component.- Returns:
- the value of the
engramVocabSizerecord component
-
engramHeads
public int engramHeads()Returns the value of theengramHeadsrecord component.- Returns:
- the value of the
engramHeadsrecord component
-
engramHeadDim
public int engramHeadDim()Returns the value of theengramHeadDimrecord component.- Returns:
- the value of the
engramHeadDimrecord component
-
engramPadId
public int engramPadId()Returns the value of theengramPadIdrecord component.- Returns:
- the value of the
engramPadIdrecord component
-
engramCompressedVocab
public int engramCompressedVocab()Returns the value of theengramCompressedVocabrecord component.- Returns:
- the value of the
engramCompressedVocabrecord component
-
numMtpLayers
public int numMtpLayers()Returns the value of thenumMtpLayersrecord component.- Returns:
- the value of the
numMtpLayersrecord component
-
dsparkBlockSize
public int dsparkBlockSize()Returns the value of thedsparkBlockSizerecord component.- Returns:
- the value of the
dsparkBlockSizerecord component
-
dsparkNoiseToken
public int dsparkNoiseToken()Returns the value of thedsparkNoiseTokenrecord component.- Returns:
- the value of the
dsparkNoiseTokenrecord component
-
dsparkTargetLayers
public int[] dsparkTargetLayers()Returns the value of thedsparkTargetLayersrecord component.- Returns:
- the value of the
dsparkTargetLayersrecord component
-
dsparkMarkovRank
public int dsparkMarkovRank()Returns the value of thedsparkMarkovRankrecord component.- Returns:
- the value of the
dsparkMarkovRankrecord component
-
dsparkRoutedExperts
public int dsparkRoutedExperts()Returns the value of thedsparkRoutedExpertsrecord component.- Returns:
- the value of the
dsparkRoutedExpertsrecord component
-
dsparkExpertsPerTok
public int dsparkExpertsPerTok()Returns the value of thedsparkExpertsPerTokrecord component.- Returns:
- the value of the
dsparkExpertsPerTokrecord component
-
imageTokenId
public int imageTokenId()Returns the value of theimageTokenIdrecord component.- Returns:
- the value of the
imageTokenIdrecord component
-
maxSeqLen
-