Class DeepSeekCheckpoint
java.lang.Object
smile.llm.model.deepseek.DeepSeekCheckpoint
- All Implemented Interfaces:
AutoCloseable
Reads tensors of a DeepSeek-V4.1 checkpoint (sharded safetensors) one at a time, so a slice of the model can be
loaded without touching the other shards.
Dtypes: BF16, F32, I8 (packed fp4 experts) and F8_E4M3 load as such; F8_E8M0 scales load as raw
uint8 exponent bytes (see DeepSeekOps.e8m0ToFloat(Tensor)). Tensors that live in a huge shard but were
range-fetched into engram_small.safetensors (the engram projection, not its table) are found there.
-
Constructor Summary
ConstructorsConstructorDescriptionDeepSeekCheckpoint(Path dir) Opens a checkpoint directory containingmodel.safetensors.index.json. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Loads a tensor to the model's device (Dsv.device()).Loads a tensor to CPU.getAs(String name, ScalarType dtype) Loads a tensor reinterpreted without conversion (view(dtype)), e.g.booleanWhether a tensor is available locally.booleanWhether a tensor is stored as int8 (packed fp4 pairs), from the shard header.longFaults a tensor's whole mapping into the process (page-table entries), so that random row reads are plain memory accesses instead of one page fault each.longReads a tensor's bytes sequentially so that the operating system caches the whole of it.Reads rows of a 2-D tensor straight from its shard file (for the huge engram tables).long[]Shape of a tensor, from the shard header (nothing is read).
-
Constructor Details
-
DeepSeekCheckpoint
Opens a checkpoint directory containingmodel.safetensors.index.json.- Parameters:
dir- the checkpoint directory.- Throws:
IOException- if the index cannot be read.
-
-
Method Details
-
has
Whether a tensor is available locally.- Parameters:
name- the tensor name.- Returns:
trueif the index lists it and its shard file exists.
-
get
-
shape
Shape of a tensor, from the shard header (nothing is read).- Parameters:
name- the tensor name.- Returns:
- the shape.
-
isInt8
Whether a tensor is stored as int8 (packed fp4 pairs), from the shard header.- Parameters:
name- the tensor name.- Returns:
truefor I8.
-
readRows
-
prefetch
Reads a tensor's bytes sequentially so that the operating system caches the whole of it. Engram tables are read at random (one row per hashed n-gram), and every first touch of a page on a network file system costs a round trip; one sequential pass at start-up turns that into memory copies.- Parameters:
name- the tensor name.- Returns:
- the number of bytes read.
-
populate
Faults a tensor's whole mapping into the process (page-table entries), so that random row reads are plain memory accesses instead of one page fault each. Run afterprefetch(String)has put the pages in the page cache.- Parameters:
name- the tensor name.- Returns:
- the number of bytes mapped, 0 if the tensor cannot be mapped.
-
dev
-
getAs
Loads a tensor reinterpreted without conversion (view(dtype)), e.g. int8 bytes as fp4 pairs.- Parameters:
name- the tensor name.dtype- the dtype to view the bytes as.- Returns:
- the viewed tensor.
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-