mindformers.models.DeepseekV4Config

class mindformers.models.DeepseekV4Config(vocab_size=129280, hidden_size=7168, moe_intermediate_size=3072, num_hidden_layers=61, num_nextn_predict_layers=1, num_attention_heads=128, num_key_value_heads=1, n_shared_experts=1, n_routed_experts=384, routed_scaling_factor=2.5, topk_method='noaux_tc', num_experts_per_tok=6, norm_topk_prob=True, scoring_func='sqrtsoftplus', head_dim=512, q_lora_rank=1536, qk_rope_head_dim=64, o_lora_rank=1024, o_groups=16, index_n_heads=64, index_head_dim=128, index_topk=1024, num_hash_layers=3, compress_ratios=None, compress_rope_theta=160000, sliding_window=128, swiglu_limit=10.0, expert_dtype='fp4', hc_eps=1e-06, hc_mult=4, hc_sinkhorn_iters=20, hidden_act='silu', max_position_embeddings=1048576, initializer_range=0.02, rms_norm_eps=1e-6, use_cache=True, pad_token_id=None, bos_token_id=0, eos_token_id=1, tie_word_embeddings=False, rope_theta=10000.0, rope_scaling=None, attention_bias=False, attention_dropout=0.0, experimental_attention_variant='dsv4_hybrid', enable_hyper_connections=True, n_group=0, **kwargs)[源代码]

This is the configuration class to store the configuration of a [DeepseekV4Model]. It is used to instantiate an DeepSeek-V4 model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the DeepSeek-V4.

Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the documentation from [PretrainedConfig] for more information.

参数:
  • vocab_size (int, optional, defaults to 129280) – Vocabulary size of the Deep model.

  • hidden_size (int, optional, defaults to 7168) – Dimension of the hidden representations.

  • moe_intermediate_size (int, optional, defaults to 3072) – Dimension of the MoE representations.

  • num_hidden_layers (int, optional, defaults to 61) – Number of hidden layers in the Transformer decoder.

  • num_nextn_predict_layers (int, optional, defaults to 1) – Number of nextn predict layers.

  • num_attention_heads (int, optional, defaults to 128) – Number of attention heads for each attention layer.

  • n_shared_experts (int, optional, defaults to 1) – Number of shared experts.

  • n_routed_experts (int, optional, defaults to 384) – Number of routed experts.

  • routed_scaling_factor (float, optional, defaults to 2.5) – Scaling factor for routed experts.

  • topk_method (str, optional, defaults to noaux_tc) – Topk method used in routed gate.

  • num_experts_per_tok (int, optional, defaults to 6) – Number of selected experts per token.

  • norm_topk_prob (bool, optional, defaults to True) – Whether to normalize the weights of the routed experts.

  • scoring_func (str, optional, defaults to 'sqrtsoftplus') – Method of computing expert weights.

  • num_key_value_heads (int, optional, defaults to 1) – Number of key_value heads for Grouped Query Attention.

  • head_dim (int, optional, defaults to 512) – Dimension of each attention head.

  • q_lora_rank (int, optional, defaults to 1536) – Rank of the Q LoRA projections.

  • qk_rope_head_dim (int, optional, defaults to 64) – Dimension of the RoPE head for QK projections.

  • o_lora_rank (int, optional, defaults to 1024) – Rank of the O LoRA projections.

  • o_groups (int, optional, defaults to 16) – Number of groups for O projections.

  • index_n_heads (int, optional, defaults to 64) – Number of index heads for hash attention.

  • index_head_dim (int, optional, defaults to 128) – Dimension of index heads.

  • index_topk (int, optional, defaults to 1024) – Number of topk indices for hash attention.

  • num_hash_layers (int, optional, defaults to 3) – Number of hash layers.

  • compress_ratios (list, optional) – Compression ratios for each layer.

  • compress_rope_theta (int, optional, defaults to 160000) – Theta for compressed RoPE.

  • sliding_window (int, optional, defaults to 128) – Sliding window size for attention.

  • swiglu_limit (float, optional, defaults to 10.0) – Limit for SwiGLU activation.

  • expert_dtype (str, optional, defaults to "fp4") – Data type for experts.

  • hc_eps (float, optional, defaults to 1e-06) – Epsilon for hyper-connection.

  • hc_mult (int, optional, defaults to 4) – Multiplier for hyper-connection.

  • hc_sinkhorn_iters (int, optional, defaults to 20) – Number of Sinkhorn iterations for hyper-connection.

  • hidden_act (str, optional, defaults to "silu") – The non-linear activation function.

  • max_position_embeddings (int, optional, defaults to 1048576) – The maximum sequence length.

  • initializer_range (float, optional, defaults to 0.02) – The standard deviation for initializing weight matrices.

  • rms_norm_eps (float, optional, defaults to 1e-06) – The epsilon used by the rms normalization layers.

  • use_cache (bool, optional, defaults to True) – Whether to use cache.

  • pad_token_id (int, optional) – Padding token id.

  • bos_token_id (int, optional, defaults to 0) – Beginning of stream token id.

  • eos_token_id (int, optional, defaults to 1) – End of stream token id.

  • tie_word_embeddings (bool, optional, defaults to False) – Whether to tie weight embeddings.

  • rope_theta (float, optional, defaults to 10000.0) – The base period of the RoPE embeddings.

  • rope_scaling (Dict, optional) – Dictionary containing the scaling configuration for the RoPE embeddings.

  • attention_bias (bool, optional, defaults to False) – Whether to use bias in attention projections.

  • attention_dropout (float, optional, defaults to 0.0) – The dropout ratio for attention probabilities.

__init__(vocab_size=129280, hidden_size=7168, moe_intermediate_size=3072, num_hidden_layers=61, num_nextn_predict_layers=1, num_attention_heads=128, num_key_value_heads=1, n_shared_experts=1, n_routed_experts=384, routed_scaling_factor=2.5, topk_method='noaux_tc', num_experts_per_tok=6, norm_topk_prob=True, scoring_func='sqrtsoftplus', head_dim=512, q_lora_rank=1536, qk_rope_head_dim=64, o_lora_rank=1024, o_groups=16, index_n_heads=64, index_head_dim=128, index_topk=1024, num_hash_layers=3, compress_ratios=None, compress_rope_theta=160000, sliding_window=128, swiglu_limit=10.0, expert_dtype='fp4', hc_eps=1e-06, hc_mult=4, hc_sinkhorn_iters=20, hidden_act='silu', max_position_embeddings=1048576, initializer_range=0.02, rms_norm_eps=1e-6, use_cache=True, pad_token_id=None, bos_token_id=0, eos_token_id=1, tie_word_embeddings=False, rope_theta=10000.0, rope_scaling=None, attention_bias=False, attention_dropout=0.0, experimental_attention_variant='dsv4_hybrid', enable_hyper_connections=True, n_group=0, **kwargs)[源代码]

Deepseek V4 Config

Methods

__init__([vocab_size, hidden_size, ...])

Deepseek V4 Config

convert_to_transformer_config([is_mla_model])

Convert DeepseekV4Config to TransformerConfig.

delete_from_dict(config_dict)

Deletes keys from the nested dictionary config_dict based on the blacklist.

dict_ms_dtype_to_str(d)

Checks whether the passed dictionary and its nested dicts have a ms_dtype key and if it's not None, converts ms.dtype to a string of just the type.

from_dict(config_dict, **kwargs)

Instantiates a PretrainedConfig from a Python dictionary of parameters.

from_json_file(json_file)

Instantiates a PretrainedConfig from the path to a JSON file of parameters.

from_pretrained(yaml_name_or_path, **kwargs)

From pretrain method, which instantiates a config by yaml name or path.

get_config_dict(...)

From a pretrained_model_name_or_path, resolve to a dictionary of parameters, to be used for instantiating a PretrainedConfig using mindformers.models.PretrainedConfig.from_dict().

get_config_experimental_mode(cls, *args, ...)

get_config_origin_mode(yaml_name_or_path, ...)

Get config object by from_pretrained with original mode

get_support_list()

get support list method

inverse_parse_config()

push_to_hub(...)

Upload the {object_files} to the OpenMind Model Hub.

register_for_auto_class([auto_class])

Register this class with a given auto class.

remove_type()

remove type caused by save’

save_config_experimental_mode(cls, *args, ...)

save_config_origin_mode(save_directory, ...)

Save config to local directory with yaml format in original mode

save_pretrained([save_directory, save_name])

Saves the pre-trained configuration to the specified directory

show_support_list()

show support list method

to_dict()

Serializes this instance to a Python dictionary.

to_diff_dict()

Removes all attributes from config which correspond to the default config attributes for better readability and serializes to a Python dictionary.

to_json_file(json_file_path[, use_diff])

Save this instance to a JSON file.

to_json_string([use_diff])

Serializes this instance to a JSON string.

Attributes

attribute_map

is_composition

keys_to_ignore_at_inference

model_type

name_or_path