Class DeepSeekModel

java.lang.Object
smile.llm.model.deepseek.DeepSeekModel
All Implemented Interfaces:
AutoCloseable

public final class DeepSeekModel extends Object implements AutoCloseable
DeepSeek-V4.1 text model for validation: a (possibly truncated) stack of DeepSeekBlocks over a hc-fold residual stream, single sequence, CPU-friendly, float32 weights. It reproduces the reference forward pass step by step and is checked against a pure-PyTorch port of it; it is not the serving implementation.
  • Method Details

    • newSession

      public DeepSeekModel.Session newSession()
      Allocates the state of an empty sequence (call outside any tensor scope).
      Returns:
      the new session state.
    • use

      public void use(DeepSeekModel.Session session)
      Makes session the sequence the next forward(int[], int, Map) calls continue.
      Parameters:
      session - the session state to activate.
    • forward

      public Tensor forward(int[] ids, int startPos, Map<String,Tensor> trace)
      Runs new tokens through the model.
      Parameters:
      ids - the new token ids.
      startPos - absolute position of the first new token (0 for prefill).
      trace - optional map receiving per-layer intermediates (L<i>.attn_out, ffn_out, engram_out, out), or null.
      Returns:
      the logits of the last new token [1, vocab] (float32).
    • forwardPrefillBatch

      public Tensor forwardPrefillBatch(int[][] prompts, DeepSeekModel.Session[] sessions)
      The prompts of several new sequences (each from position 0) in one pass over the layers.
      Parameters:
      prompts - the prompts.
      sessions - the sequences' states.
      Returns:
      the last position's logits of each prompt, [n, vocab] (float32).
    • forwardBatch

      public Tensor forwardBatch(int[] ids, int[] pos, DeepSeekModel.Session[] sessions)
      One decode token for each of several sequences (different positions), in a single pass over the layers.
      Parameters:
      ids - each sequence's new token.
      pos - each token's absolute position.
      sessions - the sequences' states (not interchangeable with use(DeepSeekModel.Session)).
      Returns:
      the logits [n, vocab] (float32).
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException