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.dspark_gemma4
The native DSpark draft for Gemma4 targets.
DSparkGemma4
class max.pipelines.architectures.dspark_gemma4.DSparkGemma4(config, *, kv_params, devices, dtype)
Bases: Module
DSpark draft transformer for a Gemma4 target.
-
Parameters:
-
- config (DSparkGemma4DraftConfig)
- kv_params (KVCacheParams)
- devices (list[DeviceRef])
- dtype (DType)
forward_block()
forward_block(input_embeds, kv_collection, input_row_offsets)
-
Parameters:
-
- input_embeds (TensorValue)
- kv_collection (KVCacheInputsPerDevice[TensorValue, BufferValue])
- input_row_offsets (TensorValue)
-
Return type:
materialize_kv()
materialize_kv(ctx_hidden, input_row_offsets, kv_collection)
-
Parameters:
-
- ctx_hidden (TensorValue)
- input_row_offsets (TensorValue)
- kv_collection (KVCacheInputsPerDevice[TensorValue, BufferValue])
-
Return type:
-
None
project_target_hidden()
project_target_hidden(target_hs_concat)
-
Parameters:
-
target_hs_concat (TensorValue)
-
Return type:
DSparkGemma4DraftConfig
class max.pipelines.architectures.dspark_gemma4.DSparkGemma4DraftConfig(hidden_size, intermediate_size, num_hidden_layers, num_attention_heads, num_key_value_heads, head_dim, rms_norm_eps, vocab_size, hidden_activation, final_logit_softcapping, rope_theta, partial_rotary_factor, max_seq_len, block_size, mask_token_id, target_layer_ids, markov_rank, markov_head_type)
Bases: object
DSpark drafter hyperparameters from the draft HF checkpoint config.
The checkpoint config (such as deepseek-ai/dspark_gemma4_12b_block7) is
a gemma4_text-style config extended with the DSpark fields
(block_size, mask_token_id, target_layer_ids,
markov_rank, …). Only full-attention (k_eq_v) draft layers are
supported, matching the reference drafter.
-
Parameters:
-
- hidden_size (int)
- intermediate_size (int)
- num_hidden_layers (int)
- num_attention_heads (int)
- num_key_value_heads (int)
- head_dim (int)
- rms_norm_eps (float)
- vocab_size (int)
- hidden_activation (str)
- final_logit_softcapping (float | None)
- rope_theta (float)
- partial_rotary_factor (float)
- max_seq_len (int)
- block_size (int)
- mask_token_id (int)
- target_layer_ids (tuple[int, ...])
- markov_rank (int)
- markov_head_type (str)
block_size
block_size: int
final_logit_softcapping
from_huggingface_config()
classmethod from_huggingface_config(huggingface_config, *, max_seq_len=None)
Parses the DSpark draft checkpoint config (object or dict).
-
Parameters:
-
Return type:
head_dim
head_dim: int
Global head dim (global_head_dim in the HF config).
hidden_activation
hidden_activation: str
hidden_size
hidden_size: int
intermediate_size
intermediate_size: int
markov_head_type
markov_head_type: str
markov_rank
markov_rank: int
mask_token_id
mask_token_id: int
max_seq_len
max_seq_len: int
num_attention_heads
num_attention_heads: int
num_context_features
property num_context_features: int
num_hidden_layers
num_hidden_layers: int
num_key_value_heads
num_key_value_heads: int
Global (k_eq_v) key/value head count; every draft layer is global.
partial_rotary_factor
partial_rotary_factor: float
rms_norm_eps
rms_norm_eps: float
rope_theta
rope_theta: float
target_layer_ids
vocab_size
vocab_size: int