Class MiniMaxModel
java.lang.Object
smile.deep.layer.LayerBlock
smile.llm.model.minimax.MiniMaxModel
MiniMax-M3 text model: embeddings, decoder blocks, final norm and LM head.
Construct on CPU, load weights, call to(Device) to place parameters and the RoPE
tables, then install the KV pool with setKvCachePool(KvCachePool, boolean). This first version is the
eager reference path (dense attention, host-routed MoE): no CUDA graphs, no tensor parallelism.
-
Field Summary
Fields inherited from class LayerBlock
device, dtype, module -
Constructor Summary
ConstructorsConstructorDescriptionMiniMaxModel(MiniMaxModelArgs args) Constructs the module graph on CPU.MiniMaxModel(MiniMaxModelArgs args, MiniMaxShard shard, TensorParallelGroup group) Expert-parallel constructor: one model replica per rank, each owning a slice of the experts. -
Method Summary
Modifier and TypeMethodDescriptionvoidFrees every captured graph (the KV pool or the weights changed under them).decodeGraph(long[] realTokens, int[] realPositions) Single-token decode through a captured CUDA graph.Forward propagation (or forward pass) through the layer.Single-token decode with per-row absolute positions.Prefill / multi-token window forward at a uniform cache position.Prefill window whose embeddings are partly replaced, for multimodal prompts: rows of the token embeddings atrowsare overwritten byreplacement(vision embeddings) before the first layer.voidMerges each layer's attention projections into one GEMM where the weights allow it; call after loading.Returns the installed KV pool.layers()Returns the decoder blocks.params()Returns the hyperparameters.Returns the FP8-resident (Marlin) linear layers by their SMILE weight names, e.g.voidsetKvCachePool(KvCachePool pool, boolean closePrevious) Installs the KV pool in every attention layer.shard()Returns this rank's expert slice.Moves the layer block to a device.to(Device device, ScalarType dtype) Moves the layer block to a device.Methods inherited from class LayerBlock
add, add, device, dtype, eval, isTraining, load, loadStateDict, module, save, setRequiresGrad, toString, train
-
Constructor Details
-
MiniMaxModel
Constructs the module graph on CPU.- Parameters:
args- hyperparameters.
-
MiniMaxModel
Expert-parallel constructor: one model replica per rank, each owning a slice of the experts.- Parameters:
args- hyperparameters.shard- this rank's expert slice (its expert weights are allocated onshard.device()).group- all-reduce group, ornullfor a single rank.
-
-
Method Details
-
params
-
shard
-
quantLinears
Returns the FP8-resident (Marlin) linear layers by their SMILE weight names, e.g.layers.3.self_attn.q_proj.weight; empty unless the model was built in an MXFP8 weight mode. Routed experts are loaded throughMiniMaxMoEinstead.- Returns:
- name to layer map.
-
layers
-
kvCachePool
Returns the installed KV pool.- Returns:
- KV pool, or
nullbeforesetKvCachePool(KvCachePool, boolean).
-
to
Description copied from interface:LayerMoves the layer block to a device.- Specified by:
toin interfaceLayer- Overrides:
toin classLayerBlock- Parameters:
device- the compute device.- Returns:
- this layer.
-
to
Description copied from interface:LayerMoves the layer block to a device.- Specified by:
toin interfaceLayer- Overrides:
toin classLayerBlock- Parameters:
device- the compute device.dtype- the data type.- Returns:
- this layer.
-
fuseProjections
public void fuseProjections()Merges each layer's attention projections into one GEMM where the weights allow it; call after loading. -
setKvCachePool
Installs the KV pool in every attention layer.- Parameters:
pool- new KV pool (must not benull).closePrevious-trueto close the previous pool when replaced.
-
forward
Prefill / multi-token window forward at a uniform cache position.- Parameters:
tokens- token ids[B, S].startPos- cache start position.allTokenLogits- score every position whentrue, otherwise only the last.- Returns:
- float32 logits.
-
forward
public Tensor forward(Tensor tokens, int startPos, boolean allTokenLogits, long[] rows, Tensor replacement) Prefill window whose embeddings are partly replaced, for multimodal prompts: rows of the token embeddings atrowsare overwritten byreplacement(vision embeddings) before the first layer.- Parameters:
tokens- token ids[1, S].startPos- cache start position.allTokenLogits- score every position whentrue, otherwise only the last.rows- window positions to overwrite, ornull.replacement-[rows.length, hidden]embeddings in the compute dtype, on this device.- Returns:
- float32 logits.
-
forward
-
closeGraphs
public void closeGraphs()Frees every captured graph (the KV pool or the weights changed under them). -
decodeGraph
Single-token decode through a captured CUDA graph.The first step of a (batch, window) shape runs eagerly twice (library handles and kernel attributes must exist before capture), then captures the whole forward pass and replays it; later steps only refill the static metadata buffer and replay. Nothing is built on the host while capturing: slots, positions and the attention mask come from the static buffers (see
MiniMaxStep.External).- Parameters:
realTokens- last token of each row.realPositions- KV write position of each row.- Returns:
- float32 logits
[B, V](a fresh tensor), ornullwhen graphs are off or not applicable and the caller must run the eager path.
-
forward
-