For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Python module
max.pipelines.architectures.deepseekV2
DeepSeek-V2 mixture-of-experts architecture for text generation.
DeepseekV2Configβ
class max.pipelines.architectures.deepseekV2.DeepseekV2Config(*, dtype, kv_params, devices, vocab_size=102400, hidden_size=4096, intermediate_size=11008, moe_intermediate_size=1407, num_hidden_layers=30, num_attention_heads=32, num_key_value_heads=32, n_shared_experts=0, n_routed_experts=0, ep_size=1, routed_scaling_factor=1.0, kv_lora_rank=512, q_lora_rank=1536, qk_rope_head_dim=64, v_head_dim=128, qk_nope_head_dim=128, topk_method='greedy', n_group=0, topk_group=0, num_experts_per_tok=0, moe_layer_freq=1, first_k_dense_replace=0, norm_topk_prob=False, scoring_func='softmax', aux_loss_alpha=0.001, seq_aux=True, hidden_act='silu', max_position_embeddings=2048, initializer_range=0.02, rms_norm_eps=1e-06, use_cache=True, pad_token_id=None, bos_token_id=100000, eos_token_id=100001, pretraining_tp=1, tie_word_embeddings=False, rope_theta=10000.0, rope_scaling=None, attention_bias=False, attention_dropout=0.0, max_batch_context_length=131072, graph_mode='auto')
Bases: ArchConfigWithKVCache
Configuration for DeepseekV2 models.
-
Parameters:
-
- dtype (DType)
- kv_params (KVCacheParams)
- devices (list[DeviceRef])
- vocab_size (int)
- hidden_size (int)
- intermediate_size (int)
- moe_intermediate_size (int)
- num_hidden_layers (int)
- num_attention_heads (int)
- num_key_value_heads (int)
- n_shared_experts (int)
- n_routed_experts (int)
- ep_size (int)
- routed_scaling_factor (float)
- kv_lora_rank (int)
- q_lora_rank (int | None)
- qk_rope_head_dim (int)
- v_head_dim (int)
- qk_nope_head_dim (int)
- topk_method (str)
- n_group (int)
- topk_group (int)
- num_experts_per_tok (int)
- moe_layer_freq (int)
- first_k_dense_replace (int)
- norm_topk_prob (bool)
- scoring_func (str)
- aux_loss_alpha (float)
- seq_aux (bool)
- hidden_act (str)
- max_position_embeddings (int)
- initializer_range (float)
- rms_norm_eps (float)
- use_cache (bool)
- pad_token_id (int | None)
- bos_token_id (int)
- eos_token_id (int)
- pretraining_tp (int)
- tie_word_embeddings (bool)
- rope_theta (float)
- rope_scaling (dict[str, Any] | None)
- attention_bias (bool)
- attention_dropout (float)
- max_batch_context_length (int)
- graph_mode (str)
attention_biasβ
attention_bias: bool = False
attention_dropoutβ
attention_dropout: float = 0.0
aux_loss_alphaβ
aux_loss_alpha: float = 0.001
bos_token_idβ
bos_token_id: int = 100000
construct_kv_params()β
static construct_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype)
-
Parameters:
-
- huggingface_config (AutoConfig)
- pipeline_config (PipelineConfig)
- devices (list[DeviceRef])
- kv_cache_config (KVCacheConfig)
- cache_dtype (DType)
-
Return type:
devicesβ
dtypeβ
dtype: DType
eos_token_idβ
eos_token_id: int = 100001
ep_sizeβ
ep_size: int = 1
first_k_dense_replaceβ
first_k_dense_replace: int = 0
get_kv_params()β
get_kv_params()
KV cache parameters to use when running the model.
-
Return type:
get_max_seq_len()β
get_max_seq_len()
Returns the default maximum sequence length for the model.
Subclasses should determine whether this value can be overridden by
setting the --max-length (pipeline_config.model.max_length) flag.
-
Return type:
get_num_layers()β
static get_num_layers(huggingface_config)
-
Parameters:
-
huggingface_config (AutoConfig)
-
Return type:
graph_modeβ
graph_mode: str = 'auto'
hidden_actβ
hidden_act: str = 'silu'
hidden_sizeβ
hidden_size: int = 4096
initialize()β
classmethod initialize(pipeline_config, model_config=None)
Initialize the config from a PipelineConfig.
-
Parameters:
-
- pipeline_config (PipelineConfig) β The pipeline configuration.
- model_config (MAXModelConfig | None) β The model configuration to read from. When
None(the default),pipeline_config.modelis used. Pass an explicit config (e.g.pipeline_config.draft_model) to initialize the arch config for a different model.
-
Return type:
initializer_rangeβ
initializer_range: float = 0.02
intermediate_sizeβ
intermediate_size: int = 11008
kv_lora_rankβ
kv_lora_rank: int = 512
kv_paramsβ
kv_params: KVCacheParams
max_batch_context_lengthβ
max_batch_context_length: int = 131072
max_position_embeddingsβ
max_position_embeddings: int = 2048
moe_intermediate_sizeβ
moe_intermediate_size: int = 1407
moe_layer_freqβ
moe_layer_freq: int = 1
n_groupβ
n_group: int = 0
n_routed_expertsβ
n_routed_experts: int = 0
n_shared_expertsβ
n_shared_experts: int = 0
norm_topk_probβ
norm_topk_prob: bool = False
num_attention_headsβ
num_attention_heads: int = 32
num_experts_per_tokβ
num_experts_per_tok: int = 0
num_hidden_layersβ
num_hidden_layers: int = 30
num_key_value_headsβ
num_key_value_heads: int = 32
pad_token_idβ
pretraining_tpβ
pretraining_tp: int = 1
q_lora_rankβ
qk_nope_head_dimβ
qk_nope_head_dim: int = 128
qk_rope_head_dimβ
qk_rope_head_dim: int = 64
rms_norm_epsβ
rms_norm_eps: float = 1e-06
rope_scalingβ
rope_thetaβ
rope_theta: float = 10000.0
routed_scaling_factorβ
routed_scaling_factor: float = 1.0
scoring_funcβ
scoring_func: str = 'softmax'
seq_auxβ
seq_aux: bool = True
tie_word_embeddingsβ
tie_word_embeddings: bool = False
topk_groupβ
topk_group: int = 0
topk_methodβ
topk_method: str = 'greedy'
use_cacheβ
use_cache: bool = True
v_head_dimβ
v_head_dim: int = 128
vocab_sizeβ
vocab_size: int = 102400
DeepseekV2Inputsβ
class max.pipelines.architectures.deepseekV2.DeepseekV2Inputs(tokens, input_row_offsets, signal_buffers, *, kv_cache_inputs=None, lora=None, hidden_states=None, return_n_logits)
Bases: ModelInputs
A class representing inputs for the DeepseekV2 model.
This class encapsulates the input tensors required for the DeepseekV2 model execution:
- tokens: A tensor containing the input token IDs
- input_row_offsets: A tensor containing the offsets for each row in the ragged input sequence
- return_n_logits: A tensor containing the number of logits to return
-
Parameters:
input_row_offsetsβ
input_row_offsets: Buffer
return_n_logitsβ
return_n_logits: Buffer
signal_buffersβ
Device buffers used for synchronization in communication collectives.
tokensβ
tokens: Buffer
DeepseekV2Modelβ
class max.pipelines.architectures.deepseekV2.DeepseekV2Model(pipeline_config, session, devices, kv_cache_config, weights, adapter=None, return_logits=ReturnLogits.ALL, return_hidden_states=ReturnHiddenStates.NONE, max_batch_size=1)
Bases: LogProbabilitiesMixin, GraphPipelineModelWithKVCache[TextContext]
-
Parameters:
-
- pipeline_config (PipelineConfig)
- session (InferenceSession)
- devices (list[Device])
- kv_cache_config (KVCacheConfig)
- weights (Weights)
- adapter (WeightsAdapter | None)
- return_logits (ReturnLogits)
- return_hidden_states (ReturnHiddenStates)
- max_batch_size (int)
batch_processor_clsβ
batch_processor_cls
alias of DeepseekV2BatchProcessor
execute()β
execute(model_inputs)
Executes the graph with the given inputs.
-
Parameters:
-
model_inputs (ModelInputs) β The model inputs to execute, containing tensors and any other required data for model execution.
-
Returns:
-
ModelOutputs containing the pipelineβs output tensors.
-
Return type:
This is an abstract method that must be implemented by concrete PipelineModels to define their specific execution logic.
graph_inputs()β
graph_inputs()
-
Return type:
-
tuple[TensorType | BufferType, β¦]
modelβ
model: Model
model_config_clsβ
model_config_cls
alias of DeepseekV2Config
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!