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 last ropeHeadDim).
ropeHeadDim - rotated head dimensions.
qLoraRank - query low-rank dimension.
oLoraRank - output low-rank dimension per group.
oGroups - output projection groups.
normEps - RMSNorm epsilon (1e-20 in the released model).
moeInterSize - routed/shared expert FFN width.
numRoutedExperts - routed experts per layer.
numSharedExperts - 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 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, or numLayers + k for 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:
      true for the KV source layers.
    • isIndexSource

      public boolean isIndexSource(int layer)
      Whether the layer runs an indexer.
      Parameters:
      layer - backbone layer index.
      Returns:
      true for 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:
      true for 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:
      true when a candidate source precedes the layer.
    • engramSlot

      public int engramSlot(int layer)
      Index of the layer in engramLayers.
      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

      public String layerPrefix(int layer)
      The checkpoint name prefix of a layer: layers.N for the backbone, mtp.K for the DSpark stages (layer indices numLayers + 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

      public DeepSeekModelArgs slice(int layers)
      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

      public DeepSeekModelArgs withMaxSeqLen(int maxSeqLen)
      Returns a copy with another maximum sequence length.
      Parameters:
      maxSeqLen - the new limit.
      Returns:
      the new arguments.
    • load

      public static DeepSeekModelArgs load(File configJson) throws IOException
      Reads the arguments from a checkpoint's config.json.
      Parameters:
      configJson - the config.json file.
      Returns:
      the arguments; maxSeqLen is max_position_embeddings.
      Throws:
      IOException - if the file cannot be read.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • vocabSize

      public int vocabSize()
      Returns the value of the vocabSize record component.
      Returns:
      the value of the vocabSize record component
    • dim

      public int dim()
      Returns the value of the dim record component.
      Returns:
      the value of the dim record component
    • numLayers

      public int numLayers()
      Returns the value of the numLayers record component.
      Returns:
      the value of the numLayers record component
    • numHeads

      public int numHeads()
      Returns the value of the numHeads record component.
      Returns:
      the value of the numHeads record component
    • headDim

      public int headDim()
      Returns the value of the headDim record component.
      Returns:
      the value of the headDim record component
    • ropeHeadDim

      public int ropeHeadDim()
      Returns the value of the ropeHeadDim record component.
      Returns:
      the value of the ropeHeadDim record component
    • qLoraRank

      public int qLoraRank()
      Returns the value of the qLoraRank record component.
      Returns:
      the value of the qLoraRank record component
    • oLoraRank

      public int oLoraRank()
      Returns the value of the oLoraRank record component.
      Returns:
      the value of the oLoraRank record component
    • oGroups

      public int oGroups()
      Returns the value of the oGroups record component.
      Returns:
      the value of the oGroups record component
    • normEps

      public double normEps()
      Returns the value of the normEps record component.
      Returns:
      the value of the normEps record component
    • moeInterSize

      public int moeInterSize()
      Returns the value of the moeInterSize record component.
      Returns:
      the value of the moeInterSize record component
    • numRoutedExperts

      public int numRoutedExperts()
      Returns the value of the numRoutedExperts record component.
      Returns:
      the value of the numRoutedExperts record component
    • numSharedExperts

      public int numSharedExperts()
      Returns the value of the numSharedExperts record component.
      Returns:
      the value of the numSharedExperts record component
    • numExpertsPerTok

      public int numExpertsPerTok()
      Returns the value of the numExpertsPerTok record component.
      Returns:
      the value of the numExpertsPerTok record component
    • routeScale

      public double routeScale()
      Returns the value of the routeScale record component.
      Returns:
      the value of the routeScale record component
    • swigluLimit

      public double swigluLimit()
      Returns the value of the swigluLimit record component.
      Returns:
      the value of the swigluLimit record component
    • windowSize

      public int windowSize()
      Returns the value of the windowSize record component.
      Returns:
      the value of the windowSize record component
    • compressRatios

      public int[] compressRatios()
      Returns the value of the compressRatios record component.
      Returns:
      the value of the compressRatios record component
    • kvSourceLayers

      public int[] kvSourceLayers()
      Returns the value of the kvSourceLayers record component.
      Returns:
      the value of the kvSourceLayers record component
    • indexSourceLayers

      public int[] indexSourceLayers()
      Returns the value of the indexSourceLayers record component.
      Returns:
      the value of the indexSourceLayers record component
    • originalSeqLen

      public int originalSeqLen()
      Returns the value of the originalSeqLen record component.
      Returns:
      the value of the originalSeqLen record component
    • ropeTheta

      public double ropeTheta()
      Returns the value of the ropeTheta record component.
      Returns:
      the value of the ropeTheta record component
    • compressRopeTheta

      public double compressRopeTheta()
      Returns the value of the compressRopeTheta record component.
      Returns:
      the value of the compressRopeTheta record component
    • ropeFactor

      public double ropeFactor()
      Returns the value of the ropeFactor record component.
      Returns:
      the value of the ropeFactor record component
    • betaFast

      public int betaFast()
      Returns the value of the betaFast record component.
      Returns:
      the value of the betaFast record component
    • betaSlow

      public int betaSlow()
      Returns the value of the betaSlow record component.
      Returns:
      the value of the betaSlow record component
    • indexNumHeads

      public int indexNumHeads()
      Returns the value of the indexNumHeads record component.
      Returns:
      the value of the indexNumHeads record component
    • indexHeadDim

      public int indexHeadDim()
      Returns the value of the indexHeadDim record component.
      Returns:
      the value of the indexHeadDim record component
    • indexTopk

      public int indexTopk()
      Returns the value of the indexTopk record component.
      Returns:
      the value of the indexTopk record component
    • candidateSourceLayer

      public int candidateSourceLayer()
      Returns the value of the candidateSourceLayer record component.
      Returns:
      the value of the candidateSourceLayer record component
    • candidateTopkBlocks

      public int candidateTopkBlocks()
      Returns the value of the candidateTopkBlocks record component.
      Returns:
      the value of the candidateTopkBlocks record component
    • candidateBlockSize

      public int candidateBlockSize()
      Returns the value of the candidateBlockSize record component.
      Returns:
      the value of the candidateBlockSize record component
    • hcMult

      public int hcMult()
      Returns the value of the hcMult record component.
      Returns:
      the value of the hcMult record component
    • hcSinkhornIters

      public int hcSinkhornIters()
      Returns the value of the hcSinkhornIters record component.
      Returns:
      the value of the hcSinkhornIters record component
    • hcEps

      public double hcEps()
      Returns the value of the hcEps record component.
      Returns:
      the value of the hcEps record component
    • engramLayers

      public int[] engramLayers()
      Returns the value of the engramLayers record component.
      Returns:
      the value of the engramLayers record component
    • engramNumEmbeddings

      public long[] engramNumEmbeddings()
      Returns the value of the engramNumEmbeddings record component.
      Returns:
      the value of the engramNumEmbeddings record component
    • engramMaxNgram

      public int engramMaxNgram()
      Returns the value of the engramMaxNgram record component.
      Returns:
      the value of the engramMaxNgram record component
    • engramVocabSize

      public int engramVocabSize()
      Returns the value of the engramVocabSize record component.
      Returns:
      the value of the engramVocabSize record component
    • engramHeads

      public int engramHeads()
      Returns the value of the engramHeads record component.
      Returns:
      the value of the engramHeads record component
    • engramHeadDim

      public int engramHeadDim()
      Returns the value of the engramHeadDim record component.
      Returns:
      the value of the engramHeadDim record component
    • engramPadId

      public int engramPadId()
      Returns the value of the engramPadId record component.
      Returns:
      the value of the engramPadId record component
    • engramCompressedVocab

      public int engramCompressedVocab()
      Returns the value of the engramCompressedVocab record component.
      Returns:
      the value of the engramCompressedVocab record component
    • numMtpLayers

      public int numMtpLayers()
      Returns the value of the numMtpLayers record component.
      Returns:
      the value of the numMtpLayers record component
    • dsparkBlockSize

      public int dsparkBlockSize()
      Returns the value of the dsparkBlockSize record component.
      Returns:
      the value of the dsparkBlockSize record component
    • dsparkNoiseToken

      public int dsparkNoiseToken()
      Returns the value of the dsparkNoiseToken record component.
      Returns:
      the value of the dsparkNoiseToken record component
    • dsparkTargetLayers

      public int[] dsparkTargetLayers()
      Returns the value of the dsparkTargetLayers record component.
      Returns:
      the value of the dsparkTargetLayers record component
    • dsparkMarkovRank

      public int dsparkMarkovRank()
      Returns the value of the dsparkMarkovRank record component.
      Returns:
      the value of the dsparkMarkovRank record component
    • dsparkRoutedExperts

      public int dsparkRoutedExperts()
      Returns the value of the dsparkRoutedExperts record component.
      Returns:
      the value of the dsparkRoutedExperts record component
    • dsparkExpertsPerTok

      public int dsparkExpertsPerTok()
      Returns the value of the dsparkExpertsPerTok record component.
      Returns:
      the value of the dsparkExpertsPerTok record component
    • imageTokenId

      public int imageTokenId()
      Returns the value of the imageTokenId record component.
      Returns:
      the value of the imageTokenId record component
    • maxSeqLen

      public int maxSeqLen()
      Returns the value of the maxSeqLen record component.
      Returns:
      the value of the maxSeqLen record component