Class DeepSeekModel
java.lang.Object
smile.llm.model.deepseek.DeepSeekModel
- All Implemented Interfaces:
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAll mutable per-sequence state of the model (each layer's caches and the engram token history). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Runs new tokens through the model.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.forwardPrefillBatch(int[][] prompts, DeepSeekModel.Session[] sessions) The prompts of several new sequences (each from position 0) in one pass over the layers.Allocates the state of an empty sequence (call outside any tensor scope).voiduse(DeepSeekModel.Session session) Makessessionthe sequence the nextforward(int[], int, Map)calls continue.
-
Method Details
-
newSession
Allocates the state of an empty sequence (call outside any tensor scope).- Returns:
- the new session state.
-
use
Makessessionthe sequence the nextforward(int[], int, Map)calls continue.- Parameters:
session- the session state to activate.
-
forward
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), ornull.- Returns:
- the logits of the last new token
[1, vocab](float32).
-
forwardPrefillBatch
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
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 withuse(DeepSeekModel.Session)).- Returns:
- the logits
[n, vocab](float32).
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-