For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python module
max.pipelines.architectures.unified_dspark_deepseekV41
DeepSeek-V4.1-Flash speculative decoding with its built-in DSpark drafter.
UnifiedDSparkDeepseekV41
class max.pipelines.architectures.unified_dspark_deepseekV41.UnifiedDSparkDeepseekV41(config, speculative_config, specs, *, model, trailing_input_types=(), enable_structured_output=False)
Bases: BlockDriver[tuple[list[TensorValue], list[V41RaggedRows]], TensorValue]
Verifies drafts with the target model and drafts blocks with DSpark.
Target and draft are one DeepseekV41WithDSpark; draft names
its drafter so the driver’s module tree has both roles, but the weights
are loaded and registered through target alone. On more than one
device both roles run on the target’s per-device copies (shard()):
tensor-parallel, or data-parallel with expert-parallel MoE when the
config’s data-parallel degree is the device count.
The model takes graph values at construction (its Engram tables are graph
inputs), so the graph’s signature has to exist before it does: built with
model=None, this driver only answers input_types() (and
decode_inputs()), from the same spec a model-carrying one uses.
trailing_input_types are this model’s own graph inputs, appended
after the driver’s standard inputs, in order: the Engram lookback window
(when the config has Engram), then the pinned Engram tables, one
weight/scale pair per device and Engram layer.
-
Parameters:
-
- config (DeepseekV41Config)
- speculative_config (SpeculativeConfig)
- specs (Sequence[V41KVLeafSpec])
- model (DeepseekV41WithDSpark | None)
- trailing_input_types (Sequence[TensorType | BufferType])
- enable_structured_output (bool)
shard()
shard(devices, engram_host_tables)
Runs both roles on per-device copies of target.
Call it once, after the weights are loaded into target, which
stays the module the weights registry is built from. Returns the
per-device copies, one per device.
UnifiedDSparkDeepseekV41BatchProcessor
class max.pipelines.architectures.unified_dspark_deepseekV41.UnifiedDSparkDeepseekV41BatchProcessor(config, runtime)
Bases: UnifiedSpecDecodeBatchProcessor[UnifiedDSparkDeepseekV41Inputs, DeepseekV41Config]
Ragged batching with the sampling seed and the Engram lookback window.
-
Parameters:
-
- config (DeepseekV41Config)
- runtime (BatchProcessorRuntime)
bind_ep_buffers()
bind_ep_buffers(buffers)
Binds the expert-parallel buffers created at model load.
prepare_initial_token_inputs()
prepare_initial_token_inputs(replica_batches, kv_cache_inputs=None, return_n_logits=1)
Prepares ragged token inputs with persistent buffers and a per-step seed.
-
Parameters:
-
- replica_batches (Sequence[Sequence[TextContext]])
- kv_cache_inputs (KVCacheInputs[Buffer, Buffer] | None)
- return_n_logits (int)
-
Return type:
UnifiedDSparkDeepseekV41Inputs
class max.pipelines.architectures.unified_dspark_deepseekV41.UnifiedDSparkDeepseekV41Inputs(tokens, input_row_offsets, return_n_logits, signal_buffers, host_input_row_offsets=None, data_parallel_splits=None, batch_context_lengths=<factory>, ep_buffers=(), engram_lookback_ids=None, engram_lookback_source=None, engram_lookback_history=None, engram_host_buffers=(), *, kv_cache_inputs=None, lora_buffers=(), vision_embeddings=<factory>, vision_scatter_indices=<factory>, hidden_states=None, draft_tokens=None, draft_probs_full=None, seed=None, temperature=None, top_k=None, max_k=None, top_p=None, min_top_p=None, in_thinking_phase=None, draft_slot_ids=None, draft_block_offsets=None, pinned_bitmask=None, wait_payload=None, device_bitmask_scratch=None, structured_output=False)
Bases: UnifiedSpecDecodeInputs
Graph inputs for one step of target-plus-drafter decoding.
buffers lists them in graph-input order: the ragged tokens; the
per-device image span rows and their token rows (set by the pipeline’s
vision encoder cache, zero rows on a step without images); the row
offsets (and, under data parallelism, their host copy) and logit count;
under data parallelism the replica splits; the signal buffers (only with
more than one device); the KV cache buffers; under data parallelism each
device’s context length and the expert-parallel buffers; the
speculative-decoding inputs; the Engram lookback window, its per-row
source, the lookback history and the pinned Engram tables (only when the
model has Engram); and last, a placeholder buffer whose length sets
MERGED_ROWS_DIM.
-
Parameters:
-
- tokens (Buffer)
- input_row_offsets (Buffer)
- return_n_logits (Buffer)
- signal_buffers (list[Buffer])
- host_input_row_offsets (Buffer | None)
- data_parallel_splits (Buffer | None)
- batch_context_lengths (list[Buffer])
- ep_buffers (Sequence[Buffer])
- engram_lookback_ids (Buffer | None)
- engram_lookback_source (Buffer | None)
- engram_lookback_history (Buffer | None)
- engram_host_buffers (Sequence[Buffer])
- kv_cache_inputs (KVCacheInputs[Buffer, Buffer] | None)
- lora_buffers (tuple[Buffer, ...])
- vision_embeddings (list[Buffer])
- vision_scatter_indices (list[Buffer])
- hidden_states (Buffer | list[Buffer] | None)
- draft_tokens (Buffer | None)
- draft_probs_full (Buffer | None)
- seed (Buffer | None)
- temperature (Buffer | None)
- top_k (Buffer | None)
- max_k (Buffer | None)
- top_p (Buffer | None)
- min_top_p (Buffer | None)
- in_thinking_phase (Buffer | None)
- draft_slot_ids (Buffer | None)
- draft_block_offsets (Buffer | None)
- pinned_bitmask (Buffer | None)
- wait_payload (Buffer | None)
- device_bitmask_scratch (Buffer | None)
- structured_output (bool)
batch_context_lengths
Per device, its replica’s summed context length, int32 [1] on CPU.
Only under data parallelism.
buffers
Returns positional Buffer inputs for model ABI calls.
data_parallel_splits
Int64 [replicas + 1] request boundaries of each replica, on CPU.
Only under data parallelism, where the batch is replica-major.
engram_host_buffers
The pinned host Engram tables, the graph’s last inputs but one.
Held here so buffers is the complete input list, which device
graph capture needs.
engram_lookback_history
[rows, max_ngram_size - 1] device-0 windows the previous step
recorded for this one, one row per row of the previous batch.
Rows follow the replica-major batch, as the lookback window does, so one buffer serves every data-parallel replica.
engram_lookback_ids
[batch, max_ngram_size - 1] int64 token ids before each chunk.
Each request’s raw token ids just before its chunk, on device 0.
engram_lookback_source
[batch] int64 row of engram_lookback_history to read.
-1 reads engram_lookback_ids instead.
ep_buffers
The routed experts’ expert-parallel communication buffers; only under data parallelism.
host_input_row_offsets
CPU copy of input_row_offsets; only under data parallelism.
input_row_offsets
input_row_offsets: Buffer
return_n_logits
return_n_logits: Buffer
signal_buffers
tokens
tokens: Buffer
UnifiedDSparkDeepseekV41Model
class max.pipelines.architectures.unified_dspark_deepseekV41.UnifiedDSparkDeepseekV41Model(*args, **kwargs)
Bases: _UnifiedSpecDecodeModelMixin, DeepseekV41Model
DeepSeek-V4.1 that verifies and drafts tokens in one graph per step.
The drafter’s stages store their context KV in the target model’s
sliding-window cache, as layers numbered from num_hidden_layers up,
so there is no separate draft cache to size or feed.
batch_processor_cls
batch_processor_cls
execute()
execute(model_inputs)
Runs one step, binding the pinned Engram tables as graph inputs.
The tables follow the batch’s own inputs, in the graph’s input order.
-
Parameters:
-
model_inputs (ModelInputs)
-
Return type: