prince-canuma commited on
Commit
52095df
·
verified ·
1 Parent(s): 151f980

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: mlx
4
+ tags:
5
+ - dllm
6
+ - diffusion
7
+ - llm
8
+ - text_generation
9
+ - mlx
10
+ pipeline_tag: image-text-to-text
11
+ base_model: inclusionAI/LLaDA2.1-mini
12
+ ---
13
+
14
+ # mlx-community/LLaDA2.1-mini-bf16
15
+
16
+ This model was converted to MLX format from [`inclusionAI/LLaDA2.1-mini`](https://huggingface.co/inclusionAI/LLaDA2.1-mini)
17
+ using mlx-vlm version **0.5.0**.
18
+ Refer to the [original model card](https://huggingface.co/inclusionAI/LLaDA2.1-mini) for more details on the model.
19
+
20
+ ## Use with mlx
21
+
22
+ ```bash
23
+ pip install -U mlx-vlm
24
+ ```
25
+
26
+ ```bash
27
+ python -m mlx_vlm.generate --model mlx-community/LLaDA2.1-mini-bf16 --max-tokens 100 --temperature 0.0 --prompt "Describe this image." --image <path_to_image>
28
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% set thinking_option = 'off' %}
2
+ {{- '<role>SYSTEM</role>' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n' }}
5
+ {%- endif %}
6
+ {%- if tools %}
7
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
8
+ {%- for tool in tools %}
9
+ {{- "\n" }}
10
+ {{- tool | tojson }}
11
+ {%- endfor %}
12
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call>\n" }}
13
+ {%- endif %}
14
+ {{- 'detailed thinking ' + thinking_option + '<|role_end|>' }}
15
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
16
+ {%- for message in messages[::-1] %}
17
+ {%- set index = (messages|length - 1) - loop.index0 %}
18
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
19
+ {%- set ns.multi_step_tool = false %}
20
+ {%- set ns.last_query_index = index %}
21
+ {%- endif %}
22
+ {%- endfor %}
23
+ {%- for message in messages %}
24
+ {%- if message.content is string %}
25
+ {%- set content = message.content %}
26
+ {%- else %}
27
+ {%- set content = '' %}
28
+ {%- endif %}
29
+ {%- if message.role == "user" %}
30
+ {{- '<role>HUMAN</role>' + message.content + '<|role_end|>' }}
31
+ {%- elif message.role == "system" and not loop.first %}
32
+ {{- '<role>SYSTEM</role>' + message.content + '<|role_end|>' }}
33
+ {%- elif message.role == "assistant" %}
34
+ {%- set reasoning_content = '' %}
35
+ {%- if message.reasoning_content is string %}
36
+ {%- set reasoning_content = message.reasoning_content %}
37
+ {%- else %}
38
+ {%- if '</think>' in content %}
39
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+ {%- if loop.index0 > ns.last_query_index %}
44
+ {%- if reasoning_content %}
45
+ {{- '<role>ASSISTANT</role>' + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
46
+ {%- else %}
47
+ {{- '<role>ASSISTANT</role>' + content }}
48
+ {%- endif %}
49
+ {%- else %}
50
+ {{- '<role>ASSISTANT</role>' + content }}
51
+ {%- endif %}
52
+ {%- if message.tool_calls %}
53
+ {%- for tool_call in message.tool_calls %}
54
+ {%- if (loop.first and content) or (not loop.first) %}
55
+ {{- '\n' }}
56
+ {%- endif %}
57
+ {%- if tool_call.function %}
58
+ {%- set tool_call = tool_call.function %}
59
+ {%- endif %}
60
+ {{- '<tool_call>\n{"name": "' }}
61
+ {{- tool_call.name }}
62
+ {{- '", "arguments": ' }}
63
+ {%- if tool_call.arguments is string %}
64
+ {{- tool_call.arguments }}
65
+ {%- else %}
66
+ {{- tool_call.arguments | tojson }}
67
+ {%- endif %}
68
+ {{- '}\n</tool_call>' }}
69
+ {%- endfor %}
70
+ {%- endif %}
71
+ {{- '<|role_end|>' }}
72
+ {%- elif message.role == "tool" %}
73
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
+ {{- '<role>OBSERVATION</role>' }}
75
+ {%- endif %}
76
+ {{- '\n<tool_response>\n' }}
77
+ {{- content }}
78
+ {{- '\n</tool_response>' }}
79
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
+ {{- '<|role_end|>' }}
81
+ {%- endif %}
82
+ {%- endif %}
83
+ {%- endfor %}
84
+ {%- if add_generation_prompt %}
85
+ {{- '<role>ASSISTANT</role>' }}
86
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LLaDA2MoeModelLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_llada2_moe.LLaDA2MoeConfig",
8
+ "AutoModel": "modeling_llada2_moe.LLaDA2MoeModel",
9
+ "AutoModelForCausalLM": "modeling_llada2_moe.LLaDA2MoeModelLM"
10
+ },
11
+ "dtype": "bfloat16",
12
+ "embedding_dropout": 0.0,
13
+ "first_k_dense_replace": 1,
14
+ "head_dim": 128,
15
+ "hidden_act": "silu",
16
+ "hidden_size": 2048,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 5120,
19
+ "max_position_embeddings": 32768,
20
+ "max_window_layers": 28,
21
+ "model_type": "llada2_moe",
22
+ "moe_intermediate_size": 512,
23
+ "moe_router_enable_expert_bias": true,
24
+ "n_group": 8,
25
+ "norm_head": false,
26
+ "norm_softmax": false,
27
+ "norm_topk_prob": true,
28
+ "num_attention_heads": 16,
29
+ "num_experts": 256,
30
+ "num_experts_per_tok": 8,
31
+ "num_hidden_layers": 20,
32
+ "num_key_value_heads": 4,
33
+ "num_shared_experts": 1,
34
+ "output_dropout": 0.0,
35
+ "output_router_logits": false,
36
+ "pad_token_id": 156892,
37
+ "partial_rotary_factor": 0.5,
38
+ "rms_norm_eps": 1e-06,
39
+ "rope_scaling": null,
40
+ "rope_theta": 600000,
41
+ "rotary_dim": 64,
42
+ "routed_scaling_factor": 2.5,
43
+ "router_dtype": "fp32",
44
+ "score_function": "sigmoid",
45
+ "sliding_window": 4096,
46
+ "tie_word_embeddings": false,
47
+ "topk_group": 4,
48
+ "transformers_version": "4.57.1",
49
+ "use_bias": false,
50
+ "use_cache": false,
51
+ "use_qkv_bias": false,
52
+ "use_rmsnorm": true,
53
+ "use_sliding_window": false,
54
+ "using_split_qkv_in_self_attention": false,
55
+ "vocab_size": 157184
56
+ }
configuration_llada2_moe.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LLaDA2 MoE model configuration"""
2
+
3
+ from transformers.configuration_utils import PretrainedConfig
4
+
5
+
6
+ class LLaDA2MoeConfig(PretrainedConfig):
7
+ model_type = "llada2_moe"
8
+
9
+ def __init__(
10
+ self,
11
+ vocab_size=30592,
12
+ hidden_size=1024,
13
+ intermediate_size=None,
14
+ num_hidden_layers=24,
15
+ num_attention_heads=16,
16
+ num_key_value_heads=0,
17
+ hidden_act="silu",
18
+ use_qkv_bias=False, # llada2 only
19
+ use_qk_norm=True,
20
+ use_bias=True, # llada2 only
21
+ rms_norm_eps=1e-05,
22
+ norm_head=False, # llada2 only
23
+ tie_word_embeddings=False, # PretrainedConfig key, here change default value.
24
+ embedding_dropout=0.1,
25
+ attention_dropout=0.1,
26
+ output_dropout=0.1,
27
+ initializer_range=0.02,
28
+ max_position_embeddings=16384,
29
+ rope_theta=10000.0,
30
+ use_cache=True,
31
+ use_sliding_window=False,
32
+ sliding_window=4096,
33
+ max_window_layers=28,
34
+ rope_scaling=None,
35
+ pad_token_id=126081,
36
+ num_experts=16,
37
+ num_shared_experts=0,
38
+ num_experts_per_tok=2,
39
+ n_group=8,
40
+ topk_group=4,
41
+ routed_scaling_factor=2.5,
42
+ moe_intermediate_size=None,
43
+ first_k_dense_replace=0,
44
+ head_dim=None,
45
+ output_router_logits=False,
46
+ partial_rotary_factor=0.5,
47
+ **kwargs,
48
+ ):
49
+ self.num_hidden_layers = num_hidden_layers
50
+ self.vocab_size = vocab_size
51
+ self.hidden_size = hidden_size
52
+ self.intermediate_size = intermediate_size
53
+ self.num_attention_heads = num_attention_heads
54
+ self.num_key_value_heads = num_key_value_heads
55
+ self.hidden_act = hidden_act
56
+ self.use_qkv_bias = use_qkv_bias
57
+ self.use_qk_norm = use_qk_norm
58
+ self.use_bias = use_bias
59
+ self.norm_head = norm_head
60
+ self.rms_norm_eps = rms_norm_eps
61
+ self.embedding_dropout = embedding_dropout
62
+ self.attention_dropout = attention_dropout
63
+ self.output_dropout = output_dropout
64
+ self.initializer_range = initializer_range
65
+ self.max_position_embeddings = max_position_embeddings
66
+ self.rope_theta = rope_theta
67
+ self.use_cache = use_cache
68
+ self.use_sliding_window = use_sliding_window
69
+ self.sliding_window = sliding_window
70
+ self.max_window_layers = max_window_layers
71
+ self.head_dim = head_dim or self.hidden_size // self.num_attention_heads
72
+ self.rope_scaling = rope_scaling
73
+
74
+ # MoE configs
75
+ self.num_experts = num_experts
76
+ self.num_shared_experts = num_shared_experts
77
+ self.num_experts_per_tok = num_experts_per_tok
78
+ self.n_group = n_group
79
+ self.topk_group = topk_group
80
+ self.moe_intermediate_size = moe_intermediate_size
81
+ self.first_k_dense_replace = first_k_dense_replace
82
+ self.output_router_logits = output_router_logits
83
+ self.routed_scaling_factor = routed_scaling_factor
84
+ self.partial_rotary_factor = partial_rotary_factor
85
+
86
+ super().__init__(
87
+ pad_token_id=pad_token_id, tie_word_embeddings=tie_word_embeddings, **kwargs
88
+ )
model-00001-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7edffdd3250525755c83f3d077b5a40dcaa334cdb1b3a97e1917f950ac36af4
3
+ size 5101358123
model-00002-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69066d94bd59c59e20c6097506606b0115e384d85f3563822f2e838048581c07
3
+ size 4916807732
model-00003-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:647566728b497ff6814f0aeaf02942c88a94ecdb1909f2331fe90b6abe3baf80
3
+ size 4916807764
model-00004-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5602a45b544d784cc648059f9309b1e04ec6685094bed583f9c1dcb31161aa6
3
+ size 4916807792
model-00005-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5cfafd2faf20ce945b0c6a344077a331625fd21bba13579b74023f45b3d059e8
3
+ size 4916807778
model-00006-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:460da7281094f14779a82d40cbe8782aecb311fcd5be091359a0d6af71d4b46f
3
+ size 4916807778
model-00007-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ae4e3575d13a2457fdeff7a44fab04ba6789c8b97cba3f1fab121c000bd375e
3
+ size 2825937321
model.safetensors.index.json ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 32511296512
4
+ },
5
+ "weight_map": {
6
+ "language_model.lm_head.weight": "model-00007-of-00007.safetensors",
7
+ "language_model.model.layers.0.attention.dense.weight": "model-00001-of-00007.safetensors",
8
+ "language_model.model.layers.0.attention.key_layernorm.weight": "model-00001-of-00007.safetensors",
9
+ "language_model.model.layers.0.attention.query_key_value.weight": "model-00001-of-00007.safetensors",
10
+ "language_model.model.layers.0.attention.query_layernorm.weight": "model-00001-of-00007.safetensors",
11
+ "language_model.model.layers.0.input_layernorm.weight": "model-00001-of-00007.safetensors",
12
+ "language_model.model.layers.0.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
13
+ "language_model.model.layers.0.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
14
+ "language_model.model.layers.0.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
15
+ "language_model.model.layers.0.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
16
+ "language_model.model.layers.1.attention.dense.weight": "model-00001-of-00007.safetensors",
17
+ "language_model.model.layers.1.attention.key_layernorm.weight": "model-00001-of-00007.safetensors",
18
+ "language_model.model.layers.1.attention.query_key_value.weight": "model-00001-of-00007.safetensors",
19
+ "language_model.model.layers.1.attention.query_layernorm.weight": "model-00001-of-00007.safetensors",
20
+ "language_model.model.layers.1.input_layernorm.weight": "model-00001-of-00007.safetensors",
21
+ "language_model.model.layers.1.mlp.gate.expert_bias": "model-00001-of-00007.safetensors",
22
+ "language_model.model.layers.1.mlp.gate.weight": "model-00001-of-00007.safetensors",
23
+ "language_model.model.layers.1.mlp.shared_experts.down_proj.weight": "model-00001-of-00007.safetensors",
24
+ "language_model.model.layers.1.mlp.shared_experts.gate_proj.weight": "model-00001-of-00007.safetensors",
25
+ "language_model.model.layers.1.mlp.shared_experts.up_proj.weight": "model-00001-of-00007.safetensors",
26
+ "language_model.model.layers.1.mlp.switch_mlp.down_proj.weight": "model-00001-of-00007.safetensors",
27
+ "language_model.model.layers.1.mlp.switch_mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
28
+ "language_model.model.layers.1.mlp.switch_mlp.up_proj.weight": "model-00001-of-00007.safetensors",
29
+ "language_model.model.layers.1.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
30
+ "language_model.model.layers.10.attention.dense.weight": "model-00004-of-00007.safetensors",
31
+ "language_model.model.layers.10.attention.key_layernorm.weight": "model-00004-of-00007.safetensors",
32
+ "language_model.model.layers.10.attention.query_key_value.weight": "model-00004-of-00007.safetensors",
33
+ "language_model.model.layers.10.attention.query_layernorm.weight": "model-00004-of-00007.safetensors",
34
+ "language_model.model.layers.10.input_layernorm.weight": "model-00004-of-00007.safetensors",
35
+ "language_model.model.layers.10.mlp.gate.expert_bias": "model-00004-of-00007.safetensors",
36
+ "language_model.model.layers.10.mlp.gate.weight": "model-00004-of-00007.safetensors",
37
+ "language_model.model.layers.10.mlp.shared_experts.down_proj.weight": "model-00004-of-00007.safetensors",
38
+ "language_model.model.layers.10.mlp.shared_experts.gate_proj.weight": "model-00004-of-00007.safetensors",
39
+ "language_model.model.layers.10.mlp.shared_experts.up_proj.weight": "model-00004-of-00007.safetensors",
40
+ "language_model.model.layers.10.mlp.switch_mlp.down_proj.weight": "model-00004-of-00007.safetensors",
41
+ "language_model.model.layers.10.mlp.switch_mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
42
+ "language_model.model.layers.10.mlp.switch_mlp.up_proj.weight": "model-00004-of-00007.safetensors",
43
+ "language_model.model.layers.10.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
44
+ "language_model.model.layers.11.attention.dense.weight": "model-00004-of-00007.safetensors",
45
+ "language_model.model.layers.11.attention.key_layernorm.weight": "model-00004-of-00007.safetensors",
46
+ "language_model.model.layers.11.attention.query_key_value.weight": "model-00004-of-00007.safetensors",
47
+ "language_model.model.layers.11.attention.query_layernorm.weight": "model-00004-of-00007.safetensors",
48
+ "language_model.model.layers.11.input_layernorm.weight": "model-00004-of-00007.safetensors",
49
+ "language_model.model.layers.11.mlp.gate.expert_bias": "model-00004-of-00007.safetensors",
50
+ "language_model.model.layers.11.mlp.gate.weight": "model-00004-of-00007.safetensors",
51
+ "language_model.model.layers.11.mlp.shared_experts.down_proj.weight": "model-00004-of-00007.safetensors",
52
+ "language_model.model.layers.11.mlp.shared_experts.gate_proj.weight": "model-00004-of-00007.safetensors",
53
+ "language_model.model.layers.11.mlp.shared_experts.up_proj.weight": "model-00004-of-00007.safetensors",
54
+ "language_model.model.layers.11.mlp.switch_mlp.down_proj.weight": "model-00004-of-00007.safetensors",
55
+ "language_model.model.layers.11.mlp.switch_mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
56
+ "language_model.model.layers.11.mlp.switch_mlp.up_proj.weight": "model-00004-of-00007.safetensors",
57
+ "language_model.model.layers.11.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
58
+ "language_model.model.layers.12.attention.dense.weight": "model-00004-of-00007.safetensors",
59
+ "language_model.model.layers.12.attention.key_layernorm.weight": "model-00004-of-00007.safetensors",
60
+ "language_model.model.layers.12.attention.query_key_value.weight": "model-00004-of-00007.safetensors",
61
+ "language_model.model.layers.12.attention.query_layernorm.weight": "model-00004-of-00007.safetensors",
62
+ "language_model.model.layers.12.input_layernorm.weight": "model-00005-of-00007.safetensors",
63
+ "language_model.model.layers.12.mlp.gate.expert_bias": "model-00004-of-00007.safetensors",
64
+ "language_model.model.layers.12.mlp.gate.weight": "model-00004-of-00007.safetensors",
65
+ "language_model.model.layers.12.mlp.shared_experts.down_proj.weight": "model-00005-of-00007.safetensors",
66
+ "language_model.model.layers.12.mlp.shared_experts.gate_proj.weight": "model-00005-of-00007.safetensors",
67
+ "language_model.model.layers.12.mlp.shared_experts.up_proj.weight": "model-00005-of-00007.safetensors",
68
+ "language_model.model.layers.12.mlp.switch_mlp.down_proj.weight": "model-00005-of-00007.safetensors",
69
+ "language_model.model.layers.12.mlp.switch_mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
70
+ "language_model.model.layers.12.mlp.switch_mlp.up_proj.weight": "model-00004-of-00007.safetensors",
71
+ "language_model.model.layers.12.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
72
+ "language_model.model.layers.13.attention.dense.weight": "model-00005-of-00007.safetensors",
73
+ "language_model.model.layers.13.attention.key_layernorm.weight": "model-00005-of-00007.safetensors",
74
+ "language_model.model.layers.13.attention.query_key_value.weight": "model-00005-of-00007.safetensors",
75
+ "language_model.model.layers.13.attention.query_layernorm.weight": "model-00005-of-00007.safetensors",
76
+ "language_model.model.layers.13.input_layernorm.weight": "model-00005-of-00007.safetensors",
77
+ "language_model.model.layers.13.mlp.gate.expert_bias": "model-00005-of-00007.safetensors",
78
+ "language_model.model.layers.13.mlp.gate.weight": "model-00005-of-00007.safetensors",
79
+ "language_model.model.layers.13.mlp.shared_experts.down_proj.weight": "model-00005-of-00007.safetensors",
80
+ "language_model.model.layers.13.mlp.shared_experts.gate_proj.weight": "model-00005-of-00007.safetensors",
81
+ "language_model.model.layers.13.mlp.shared_experts.up_proj.weight": "model-00005-of-00007.safetensors",
82
+ "language_model.model.layers.13.mlp.switch_mlp.down_proj.weight": "model-00005-of-00007.safetensors",
83
+ "language_model.model.layers.13.mlp.switch_mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
84
+ "language_model.model.layers.13.mlp.switch_mlp.up_proj.weight": "model-00005-of-00007.safetensors",
85
+ "language_model.model.layers.13.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
86
+ "language_model.model.layers.14.attention.dense.weight": "model-00005-of-00007.safetensors",
87
+ "language_model.model.layers.14.attention.key_layernorm.weight": "model-00005-of-00007.safetensors",
88
+ "language_model.model.layers.14.attention.query_key_value.weight": "model-00005-of-00007.safetensors",
89
+ "language_model.model.layers.14.attention.query_layernorm.weight": "model-00005-of-00007.safetensors",
90
+ "language_model.model.layers.14.input_layernorm.weight": "model-00005-of-00007.safetensors",
91
+ "language_model.model.layers.14.mlp.gate.expert_bias": "model-00005-of-00007.safetensors",
92
+ "language_model.model.layers.14.mlp.gate.weight": "model-00005-of-00007.safetensors",
93
+ "language_model.model.layers.14.mlp.shared_experts.down_proj.weight": "model-00005-of-00007.safetensors",
94
+ "language_model.model.layers.14.mlp.shared_experts.gate_proj.weight": "model-00005-of-00007.safetensors",
95
+ "language_model.model.layers.14.mlp.shared_experts.up_proj.weight": "model-00005-of-00007.safetensors",
96
+ "language_model.model.layers.14.mlp.switch_mlp.down_proj.weight": "model-00005-of-00007.safetensors",
97
+ "language_model.model.layers.14.mlp.switch_mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
98
+ "language_model.model.layers.14.mlp.switch_mlp.up_proj.weight": "model-00005-of-00007.safetensors",
99
+ "language_model.model.layers.14.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
100
+ "language_model.model.layers.15.attention.dense.weight": "model-00005-of-00007.safetensors",
101
+ "language_model.model.layers.15.attention.key_layernorm.weight": "model-00005-of-00007.safetensors",
102
+ "language_model.model.layers.15.attention.query_key_value.weight": "model-00005-of-00007.safetensors",
103
+ "language_model.model.layers.15.attention.query_layernorm.weight": "model-00005-of-00007.safetensors",
104
+ "language_model.model.layers.15.input_layernorm.weight": "model-00006-of-00007.safetensors",
105
+ "language_model.model.layers.15.mlp.gate.expert_bias": "model-00005-of-00007.safetensors",
106
+ "language_model.model.layers.15.mlp.gate.weight": "model-00005-of-00007.safetensors",
107
+ "language_model.model.layers.15.mlp.shared_experts.down_proj.weight": "model-00006-of-00007.safetensors",
108
+ "language_model.model.layers.15.mlp.shared_experts.gate_proj.weight": "model-00006-of-00007.safetensors",
109
+ "language_model.model.layers.15.mlp.shared_experts.up_proj.weight": "model-00006-of-00007.safetensors",
110
+ "language_model.model.layers.15.mlp.switch_mlp.down_proj.weight": "model-00006-of-00007.safetensors",
111
+ "language_model.model.layers.15.mlp.switch_mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
112
+ "language_model.model.layers.15.mlp.switch_mlp.up_proj.weight": "model-00005-of-00007.safetensors",
113
+ "language_model.model.layers.15.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
114
+ "language_model.model.layers.16.attention.dense.weight": "model-00006-of-00007.safetensors",
115
+ "language_model.model.layers.16.attention.key_layernorm.weight": "model-00006-of-00007.safetensors",
116
+ "language_model.model.layers.16.attention.query_key_value.weight": "model-00006-of-00007.safetensors",
117
+ "language_model.model.layers.16.attention.query_layernorm.weight": "model-00006-of-00007.safetensors",
118
+ "language_model.model.layers.16.input_layernorm.weight": "model-00006-of-00007.safetensors",
119
+ "language_model.model.layers.16.mlp.gate.expert_bias": "model-00006-of-00007.safetensors",
120
+ "language_model.model.layers.16.mlp.gate.weight": "model-00006-of-00007.safetensors",
121
+ "language_model.model.layers.16.mlp.shared_experts.down_proj.weight": "model-00006-of-00007.safetensors",
122
+ "language_model.model.layers.16.mlp.shared_experts.gate_proj.weight": "model-00006-of-00007.safetensors",
123
+ "language_model.model.layers.16.mlp.shared_experts.up_proj.weight": "model-00006-of-00007.safetensors",
124
+ "language_model.model.layers.16.mlp.switch_mlp.down_proj.weight": "model-00006-of-00007.safetensors",
125
+ "language_model.model.layers.16.mlp.switch_mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
126
+ "language_model.model.layers.16.mlp.switch_mlp.up_proj.weight": "model-00006-of-00007.safetensors",
127
+ "language_model.model.layers.16.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
128
+ "language_model.model.layers.17.attention.dense.weight": "model-00006-of-00007.safetensors",
129
+ "language_model.model.layers.17.attention.key_layernorm.weight": "model-00006-of-00007.safetensors",
130
+ "language_model.model.layers.17.attention.query_key_value.weight": "model-00006-of-00007.safetensors",
131
+ "language_model.model.layers.17.attention.query_layernorm.weight": "model-00006-of-00007.safetensors",
132
+ "language_model.model.layers.17.input_layernorm.weight": "model-00006-of-00007.safetensors",
133
+ "language_model.model.layers.17.mlp.gate.expert_bias": "model-00006-of-00007.safetensors",
134
+ "language_model.model.layers.17.mlp.gate.weight": "model-00006-of-00007.safetensors",
135
+ "language_model.model.layers.17.mlp.shared_experts.down_proj.weight": "model-00006-of-00007.safetensors",
136
+ "language_model.model.layers.17.mlp.shared_experts.gate_proj.weight": "model-00006-of-00007.safetensors",
137
+ "language_model.model.layers.17.mlp.shared_experts.up_proj.weight": "model-00006-of-00007.safetensors",
138
+ "language_model.model.layers.17.mlp.switch_mlp.down_proj.weight": "model-00006-of-00007.safetensors",
139
+ "language_model.model.layers.17.mlp.switch_mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
140
+ "language_model.model.layers.17.mlp.switch_mlp.up_proj.weight": "model-00006-of-00007.safetensors",
141
+ "language_model.model.layers.17.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
142
+ "language_model.model.layers.18.attention.dense.weight": "model-00006-of-00007.safetensors",
143
+ "language_model.model.layers.18.attention.key_layernorm.weight": "model-00006-of-00007.safetensors",
144
+ "language_model.model.layers.18.attention.query_key_value.weight": "model-00006-of-00007.safetensors",
145
+ "language_model.model.layers.18.attention.query_layernorm.weight": "model-00006-of-00007.safetensors",
146
+ "language_model.model.layers.18.input_layernorm.weight": "model-00007-of-00007.safetensors",
147
+ "language_model.model.layers.18.mlp.gate.expert_bias": "model-00006-of-00007.safetensors",
148
+ "language_model.model.layers.18.mlp.gate.weight": "model-00006-of-00007.safetensors",
149
+ "language_model.model.layers.18.mlp.shared_experts.down_proj.weight": "model-00007-of-00007.safetensors",
150
+ "language_model.model.layers.18.mlp.shared_experts.gate_proj.weight": "model-00007-of-00007.safetensors",
151
+ "language_model.model.layers.18.mlp.shared_experts.up_proj.weight": "model-00007-of-00007.safetensors",
152
+ "language_model.model.layers.18.mlp.switch_mlp.down_proj.weight": "model-00007-of-00007.safetensors",
153
+ "language_model.model.layers.18.mlp.switch_mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
154
+ "language_model.model.layers.18.mlp.switch_mlp.up_proj.weight": "model-00006-of-00007.safetensors",
155
+ "language_model.model.layers.18.post_attention_layernorm.weight": "model-00007-of-00007.safetensors",
156
+ "language_model.model.layers.19.attention.dense.weight": "model-00007-of-00007.safetensors",
157
+ "language_model.model.layers.19.attention.key_layernorm.weight": "model-00007-of-00007.safetensors",
158
+ "language_model.model.layers.19.attention.query_key_value.weight": "model-00007-of-00007.safetensors",
159
+ "language_model.model.layers.19.attention.query_layernorm.weight": "model-00007-of-00007.safetensors",
160
+ "language_model.model.layers.19.input_layernorm.weight": "model-00007-of-00007.safetensors",
161
+ "language_model.model.layers.19.mlp.gate.expert_bias": "model-00007-of-00007.safetensors",
162
+ "language_model.model.layers.19.mlp.gate.weight": "model-00007-of-00007.safetensors",
163
+ "language_model.model.layers.19.mlp.shared_experts.down_proj.weight": "model-00007-of-00007.safetensors",
164
+ "language_model.model.layers.19.mlp.shared_experts.gate_proj.weight": "model-00007-of-00007.safetensors",
165
+ "language_model.model.layers.19.mlp.shared_experts.up_proj.weight": "model-00007-of-00007.safetensors",
166
+ "language_model.model.layers.19.mlp.switch_mlp.down_proj.weight": "model-00007-of-00007.safetensors",
167
+ "language_model.model.layers.19.mlp.switch_mlp.gate_proj.weight": "model-00007-of-00007.safetensors",
168
+ "language_model.model.layers.19.mlp.switch_mlp.up_proj.weight": "model-00007-of-00007.safetensors",
169
+ "language_model.model.layers.19.post_attention_layernorm.weight": "model-00007-of-00007.safetensors",
170
+ "language_model.model.layers.2.attention.dense.weight": "model-00001-of-00007.safetensors",
171
+ "language_model.model.layers.2.attention.key_layernorm.weight": "model-00001-of-00007.safetensors",
172
+ "language_model.model.layers.2.attention.query_key_value.weight": "model-00001-of-00007.safetensors",
173
+ "language_model.model.layers.2.attention.query_layernorm.weight": "model-00001-of-00007.safetensors",
174
+ "language_model.model.layers.2.input_layernorm.weight": "model-00001-of-00007.safetensors",
175
+ "language_model.model.layers.2.mlp.gate.expert_bias": "model-00001-of-00007.safetensors",
176
+ "language_model.model.layers.2.mlp.gate.weight": "model-00001-of-00007.safetensors",
177
+ "language_model.model.layers.2.mlp.shared_experts.down_proj.weight": "model-00001-of-00007.safetensors",
178
+ "language_model.model.layers.2.mlp.shared_experts.gate_proj.weight": "model-00001-of-00007.safetensors",
179
+ "language_model.model.layers.2.mlp.shared_experts.up_proj.weight": "model-00001-of-00007.safetensors",
180
+ "language_model.model.layers.2.mlp.switch_mlp.down_proj.weight": "model-00001-of-00007.safetensors",
181
+ "language_model.model.layers.2.mlp.switch_mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
182
+ "language_model.model.layers.2.mlp.switch_mlp.up_proj.weight": "model-00001-of-00007.safetensors",
183
+ "language_model.model.layers.2.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
184
+ "language_model.model.layers.3.attention.dense.weight": "model-00001-of-00007.safetensors",
185
+ "language_model.model.layers.3.attention.key_layernorm.weight": "model-00001-of-00007.safetensors",
186
+ "language_model.model.layers.3.attention.query_key_value.weight": "model-00001-of-00007.safetensors",
187
+ "language_model.model.layers.3.attention.query_layernorm.weight": "model-00001-of-00007.safetensors",
188
+ "language_model.model.layers.3.input_layernorm.weight": "model-00002-of-00007.safetensors",
189
+ "language_model.model.layers.3.mlp.gate.expert_bias": "model-00001-of-00007.safetensors",
190
+ "language_model.model.layers.3.mlp.gate.weight": "model-00001-of-00007.safetensors",
191
+ "language_model.model.layers.3.mlp.shared_experts.down_proj.weight": "model-00002-of-00007.safetensors",
192
+ "language_model.model.layers.3.mlp.shared_experts.gate_proj.weight": "model-00002-of-00007.safetensors",
193
+ "language_model.model.layers.3.mlp.shared_experts.up_proj.weight": "model-00002-of-00007.safetensors",
194
+ "language_model.model.layers.3.mlp.switch_mlp.down_proj.weight": "model-00002-of-00007.safetensors",
195
+ "language_model.model.layers.3.mlp.switch_mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
196
+ "language_model.model.layers.3.mlp.switch_mlp.up_proj.weight": "model-00001-of-00007.safetensors",
197
+ "language_model.model.layers.3.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
198
+ "language_model.model.layers.4.attention.dense.weight": "model-00002-of-00007.safetensors",
199
+ "language_model.model.layers.4.attention.key_layernorm.weight": "model-00002-of-00007.safetensors",
200
+ "language_model.model.layers.4.attention.query_key_value.weight": "model-00002-of-00007.safetensors",
201
+ "language_model.model.layers.4.attention.query_layernorm.weight": "model-00002-of-00007.safetensors",
202
+ "language_model.model.layers.4.input_layernorm.weight": "model-00002-of-00007.safetensors",
203
+ "language_model.model.layers.4.mlp.gate.expert_bias": "model-00002-of-00007.safetensors",
204
+ "language_model.model.layers.4.mlp.gate.weight": "model-00002-of-00007.safetensors",
205
+ "language_model.model.layers.4.mlp.shared_experts.down_proj.weight": "model-00002-of-00007.safetensors",
206
+ "language_model.model.layers.4.mlp.shared_experts.gate_proj.weight": "model-00002-of-00007.safetensors",
207
+ "language_model.model.layers.4.mlp.shared_experts.up_proj.weight": "model-00002-of-00007.safetensors",
208
+ "language_model.model.layers.4.mlp.switch_mlp.down_proj.weight": "model-00002-of-00007.safetensors",
209
+ "language_model.model.layers.4.mlp.switch_mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
210
+ "language_model.model.layers.4.mlp.switch_mlp.up_proj.weight": "model-00002-of-00007.safetensors",
211
+ "language_model.model.layers.4.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
212
+ "language_model.model.layers.5.attention.dense.weight": "model-00002-of-00007.safetensors",
213
+ "language_model.model.layers.5.attention.key_layernorm.weight": "model-00002-of-00007.safetensors",
214
+ "language_model.model.layers.5.attention.query_key_value.weight": "model-00002-of-00007.safetensors",
215
+ "language_model.model.layers.5.attention.query_layernorm.weight": "model-00002-of-00007.safetensors",
216
+ "language_model.model.layers.5.input_layernorm.weight": "model-00002-of-00007.safetensors",
217
+ "language_model.model.layers.5.mlp.gate.expert_bias": "model-00002-of-00007.safetensors",
218
+ "language_model.model.layers.5.mlp.gate.weight": "model-00002-of-00007.safetensors",
219
+ "language_model.model.layers.5.mlp.shared_experts.down_proj.weight": "model-00002-of-00007.safetensors",
220
+ "language_model.model.layers.5.mlp.shared_experts.gate_proj.weight": "model-00002-of-00007.safetensors",
221
+ "language_model.model.layers.5.mlp.shared_experts.up_proj.weight": "model-00002-of-00007.safetensors",
222
+ "language_model.model.layers.5.mlp.switch_mlp.down_proj.weight": "model-00002-of-00007.safetensors",
223
+ "language_model.model.layers.5.mlp.switch_mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
224
+ "language_model.model.layers.5.mlp.switch_mlp.up_proj.weight": "model-00002-of-00007.safetensors",
225
+ "language_model.model.layers.5.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
226
+ "language_model.model.layers.6.attention.dense.weight": "model-00002-of-00007.safetensors",
227
+ "language_model.model.layers.6.attention.key_layernorm.weight": "model-00002-of-00007.safetensors",
228
+ "language_model.model.layers.6.attention.query_key_value.weight": "model-00002-of-00007.safetensors",
229
+ "language_model.model.layers.6.attention.query_layernorm.weight": "model-00002-of-00007.safetensors",
230
+ "language_model.model.layers.6.input_layernorm.weight": "model-00003-of-00007.safetensors",
231
+ "language_model.model.layers.6.mlp.gate.expert_bias": "model-00002-of-00007.safetensors",
232
+ "language_model.model.layers.6.mlp.gate.weight": "model-00002-of-00007.safetensors",
233
+ "language_model.model.layers.6.mlp.shared_experts.down_proj.weight": "model-00003-of-00007.safetensors",
234
+ "language_model.model.layers.6.mlp.shared_experts.gate_proj.weight": "model-00003-of-00007.safetensors",
235
+ "language_model.model.layers.6.mlp.shared_experts.up_proj.weight": "model-00003-of-00007.safetensors",
236
+ "language_model.model.layers.6.mlp.switch_mlp.down_proj.weight": "model-00003-of-00007.safetensors",
237
+ "language_model.model.layers.6.mlp.switch_mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
238
+ "language_model.model.layers.6.mlp.switch_mlp.up_proj.weight": "model-00002-of-00007.safetensors",
239
+ "language_model.model.layers.6.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
240
+ "language_model.model.layers.7.attention.dense.weight": "model-00003-of-00007.safetensors",
241
+ "language_model.model.layers.7.attention.key_layernorm.weight": "model-00003-of-00007.safetensors",
242
+ "language_model.model.layers.7.attention.query_key_value.weight": "model-00003-of-00007.safetensors",
243
+ "language_model.model.layers.7.attention.query_layernorm.weight": "model-00003-of-00007.safetensors",
244
+ "language_model.model.layers.7.input_layernorm.weight": "model-00003-of-00007.safetensors",
245
+ "language_model.model.layers.7.mlp.gate.expert_bias": "model-00003-of-00007.safetensors",
246
+ "language_model.model.layers.7.mlp.gate.weight": "model-00003-of-00007.safetensors",
247
+ "language_model.model.layers.7.mlp.shared_experts.down_proj.weight": "model-00003-of-00007.safetensors",
248
+ "language_model.model.layers.7.mlp.shared_experts.gate_proj.weight": "model-00003-of-00007.safetensors",
249
+ "language_model.model.layers.7.mlp.shared_experts.up_proj.weight": "model-00003-of-00007.safetensors",
250
+ "language_model.model.layers.7.mlp.switch_mlp.down_proj.weight": "model-00003-of-00007.safetensors",
251
+ "language_model.model.layers.7.mlp.switch_mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
252
+ "language_model.model.layers.7.mlp.switch_mlp.up_proj.weight": "model-00003-of-00007.safetensors",
253
+ "language_model.model.layers.7.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
254
+ "language_model.model.layers.8.attention.dense.weight": "model-00003-of-00007.safetensors",
255
+ "language_model.model.layers.8.attention.key_layernorm.weight": "model-00003-of-00007.safetensors",
256
+ "language_model.model.layers.8.attention.query_key_value.weight": "model-00003-of-00007.safetensors",
257
+ "language_model.model.layers.8.attention.query_layernorm.weight": "model-00003-of-00007.safetensors",
258
+ "language_model.model.layers.8.input_layernorm.weight": "model-00003-of-00007.safetensors",
259
+ "language_model.model.layers.8.mlp.gate.expert_bias": "model-00003-of-00007.safetensors",
260
+ "language_model.model.layers.8.mlp.gate.weight": "model-00003-of-00007.safetensors",
261
+ "language_model.model.layers.8.mlp.shared_experts.down_proj.weight": "model-00003-of-00007.safetensors",
262
+ "language_model.model.layers.8.mlp.shared_experts.gate_proj.weight": "model-00003-of-00007.safetensors",
263
+ "language_model.model.layers.8.mlp.shared_experts.up_proj.weight": "model-00003-of-00007.safetensors",
264
+ "language_model.model.layers.8.mlp.switch_mlp.down_proj.weight": "model-00003-of-00007.safetensors",
265
+ "language_model.model.layers.8.mlp.switch_mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
266
+ "language_model.model.layers.8.mlp.switch_mlp.up_proj.weight": "model-00003-of-00007.safetensors",
267
+ "language_model.model.layers.8.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
268
+ "language_model.model.layers.9.attention.dense.weight": "model-00003-of-00007.safetensors",
269
+ "language_model.model.layers.9.attention.key_layernorm.weight": "model-00003-of-00007.safetensors",
270
+ "language_model.model.layers.9.attention.query_key_value.weight": "model-00003-of-00007.safetensors",
271
+ "language_model.model.layers.9.attention.query_layernorm.weight": "model-00003-of-00007.safetensors",
272
+ "language_model.model.layers.9.input_layernorm.weight": "model-00004-of-00007.safetensors",
273
+ "language_model.model.layers.9.mlp.gate.expert_bias": "model-00003-of-00007.safetensors",
274
+ "language_model.model.layers.9.mlp.gate.weight": "model-00003-of-00007.safetensors",
275
+ "language_model.model.layers.9.mlp.shared_experts.down_proj.weight": "model-00004-of-00007.safetensors",
276
+ "language_model.model.layers.9.mlp.shared_experts.gate_proj.weight": "model-00004-of-00007.safetensors",
277
+ "language_model.model.layers.9.mlp.shared_experts.up_proj.weight": "model-00004-of-00007.safetensors",
278
+ "language_model.model.layers.9.mlp.switch_mlp.down_proj.weight": "model-00004-of-00007.safetensors",
279
+ "language_model.model.layers.9.mlp.switch_mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
280
+ "language_model.model.layers.9.mlp.switch_mlp.up_proj.weight": "model-00003-of-00007.safetensors",
281
+ "language_model.model.layers.9.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
282
+ "language_model.model.norm.weight": "model-00007-of-00007.safetensors",
283
+ "language_model.model.word_embeddings.weight": "model-00001-of-00007.safetensors"
284
+ }
285
+ }
modeling_llada2_moe.py ADDED
@@ -0,0 +1,1439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2025 Antgroup and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
4
+ # and OPT implementations in this library. It has been modified from its
5
+ # original forms to accommodate minor architectural differences compared
6
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ """PyTorch LLaDA2MoE model."""
20
+
21
+ import math
22
+ from typing import List, Callable, Optional, Tuple, Union
23
+
24
+ import torch
25
+ import torch.nn.functional as F
26
+ from torch import nn
27
+ from torch.nn import CrossEntropyLoss
28
+
29
+ from transformers.activations import ACT2FN
30
+ from transformers.cache_utils import Cache, DynamicCache
31
+ from transformers.masking_utils import create_bidirectional_mask
32
+ from transformers.modeling_outputs import (
33
+ MoeModelOutputWithPast,
34
+ MoeCausalLMOutputWithPast,
35
+ )
36
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
37
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
38
+ from transformers.processing_utils import Unpack
39
+ from transformers.pytorch_utils import (
40
+ ALL_LAYERNORM_LAYERS,
41
+ )
42
+ from transformers.utils import (
43
+ TransformersKwargs,
44
+ add_start_docstrings,
45
+ add_start_docstrings_to_model_forward,
46
+ logging,
47
+ replace_return_docstrings,
48
+ )
49
+ from .configuration_llada2_moe import LLaDA2MoeConfig
50
+ from transformers.generation.utils import GenerationMixin
51
+
52
+
53
+ logger = logging.get_logger(__name__)
54
+
55
+ _CONFIG_FOR_DOC = "LLaDA2MoeConfig"
56
+
57
+
58
+ def _get_unpad_data(attention_mask):
59
+ seqlens_in_batch = attention_mask.sum(dim=-1, dtype=torch.int32)
60
+ indices = torch.nonzero(attention_mask.flatten(), as_tuple=False).flatten()
61
+ max_seqlen_in_batch = seqlens_in_batch.max().item()
62
+ cu_seqlens = F.pad(
63
+ torch.cumsum(seqlens_in_batch, dim=0, dtype=torch.torch.int32), (1, 0)
64
+ )
65
+ return (
66
+ indices,
67
+ cu_seqlens,
68
+ max_seqlen_in_batch,
69
+ )
70
+
71
+
72
+ class LLaDA2MoeRMSNorm(nn.Module):
73
+ def __init__(self, hidden_size, eps=1e-6):
74
+ """
75
+ LLaDA2MoeRMSNorm is equivalent to T5LayerNorm
76
+ """
77
+ super().__init__()
78
+ self.weight = nn.Parameter(torch.ones(hidden_size))
79
+ self.variance_epsilon = eps
80
+
81
+ def forward(self, hidden_states):
82
+ input_dtype = hidden_states.dtype
83
+ hidden_states = hidden_states.to(torch.float32)
84
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
85
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
86
+ return self.weight * hidden_states.to(input_dtype)
87
+
88
+
89
+ ALL_LAYERNORM_LAYERS.append(LLaDA2MoeRMSNorm)
90
+
91
+
92
+ class LLaDA2MoeRotaryEmbedding(nn.Module):
93
+ inv_freq: torch.Tensor # fix linting for register_buffer
94
+
95
+ def __init__(self, config: LLaDA2MoeConfig, device=None):
96
+ super().__init__()
97
+ self.max_seq_len_cached = config.max_position_embeddings
98
+ self.original_max_seq_len = config.max_position_embeddings
99
+
100
+ self.config = config
101
+
102
+ self.rope_type = self.config.rope_parameters["rope_type"]
103
+ rope_init_fn: Callable = self.compute_default_rope_parameters
104
+ if self.rope_type != "default":
105
+ rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
106
+ inv_freq, self.attention_scaling = rope_init_fn(self.config, device)
107
+
108
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
109
+ self.register_buffer("original_inv_freq", inv_freq.clone(), persistent=False)
110
+
111
+ @staticmethod
112
+ def compute_default_rope_parameters(
113
+ config: LLaDA2MoeConfig = None,
114
+ device=None,
115
+ seq_len: int = None,
116
+ ):
117
+ base = config.rope_parameters["rope_theta"]
118
+ partial_rotary_factor = config.rope_parameters.get("partial_rotary_factor", 1.0)
119
+ head_dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
120
+ dim = int(head_dim * partial_rotary_factor)
121
+
122
+ attention_factor = 1.0 # Unused in this type of RoPE
123
+
124
+ inv_freq = 1.0 / (
125
+ base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
126
+ )
127
+ return inv_freq, attention_factor
128
+
129
+ @torch.no_grad()
130
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
131
+ def forward(self, x, position_ids):
132
+ inv_freq_expanded = (
133
+ self.inv_freq[None, :, None]
134
+ .float()
135
+ .expand(position_ids.shape[0], -1, 1)
136
+ .to(x.device)
137
+ )
138
+ position_ids_expanded = position_ids[:, None, :].float()
139
+
140
+ device_type = (
141
+ x.device.type
142
+ if isinstance(x.device.type, str) and x.device.type != "mps"
143
+ else "cpu"
144
+ )
145
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
146
+ freqs = (
147
+ inv_freq_expanded.float() @ position_ids_expanded.float()
148
+ ).transpose(1, 2)
149
+ emb = torch.cat((freqs, freqs), dim=-1)
150
+ cos = emb.cos() * self.attention_scaling
151
+ sin = emb.sin() * self.attention_scaling
152
+
153
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
154
+
155
+
156
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
157
+ def rotate_half(x):
158
+ """Rotates half the hidden dims of the input."""
159
+ x1 = x[..., : x.shape[-1] // 2]
160
+ x2 = x[..., x.shape[-1] // 2 :]
161
+ return torch.cat((-x2, x1), dim=-1)
162
+
163
+
164
+ # Copied from transformers.models.llama.modeling_llama.apply_rotary_pos_emb
165
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
166
+ """Applies Rotary Position Embedding to the query and key tensors.
167
+
168
+ Args:
169
+ q (`torch.Tensor`): The query tensor.
170
+ k (`torch.Tensor`): The key tensor.
171
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
172
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
173
+ position_ids (`torch.Tensor`):
174
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
175
+ used to pass offsetted position ids when working with a KV-cache.
176
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
177
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
178
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
179
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
180
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
181
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
182
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
183
+ Returns:
184
+ `tuple(torch.Tensor)` comprising the query and key tensors rotated using the Rotary Position Embedding.
185
+ """
186
+ cos = cos.unsqueeze(unsqueeze_dim)
187
+ sin = sin.unsqueeze(unsqueeze_dim)
188
+
189
+ # Keep half or full tensor for later concatenation
190
+ rotary_dim = cos.shape[-1]
191
+ q_rot, q_pass = q[..., :rotary_dim], q[..., rotary_dim:]
192
+ k_rot, k_pass = k[..., :rotary_dim], k[..., rotary_dim:]
193
+
194
+ # Apply rotary embeddings on the first half or full tensor
195
+ q_embed = (q_rot * cos) + (rotate_half(q_rot) * sin)
196
+ k_embed = (k_rot * cos) + (rotate_half(k_rot) * sin)
197
+
198
+ # Concatenate back to full shape
199
+ q_embed = torch.cat([q_embed, q_pass], dim=-1)
200
+ k_embed = torch.cat([k_embed, k_pass], dim=-1)
201
+ return q_embed, k_embed
202
+
203
+
204
+ class LLaDA2MoeMLP(nn.Module):
205
+ def __init__(self, config: LLaDA2MoeConfig, intermediate_size: int):
206
+ super().__init__()
207
+ self.config = config
208
+ self.hidden_size = config.hidden_size
209
+ self.intermediate_size = intermediate_size
210
+
211
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
212
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
213
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
214
+ self.act_fn = ACT2FN[config.hidden_act]
215
+
216
+ def forward(self, x):
217
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
218
+
219
+
220
+ class LLaDA2MoeGate(nn.Module):
221
+ def __init__(self, config):
222
+ super().__init__()
223
+ self.config = config
224
+ self.top_k = config.num_experts_per_tok
225
+ self.num_experts = config.num_experts
226
+
227
+ self.n_group = config.n_group
228
+ self.topk_group = config.topk_group
229
+
230
+ # topk selection algorithm
231
+ self.gating_dim = config.hidden_size
232
+ self.weight = nn.Parameter(torch.empty((self.num_experts, self.gating_dim)))
233
+ self.routed_scaling_factor = config.routed_scaling_factor
234
+
235
+ self.register_buffer("expert_bias", torch.zeros(self.num_experts))
236
+ self.reset_parameters()
237
+
238
+ def reset_parameters(self) -> None:
239
+ import torch.nn.init as init
240
+
241
+ init.kaiming_uniform_(self.weight, a=math.sqrt(5))
242
+
243
+ def group_limited_topk(
244
+ self,
245
+ scores: torch.Tensor,
246
+ ):
247
+ num_tokens, _ = scores.size()
248
+ # Organize the experts into groups
249
+ group_scores = (
250
+ scores.view(num_tokens, self.n_group, -1).topk(2, dim=-1)[0].sum(dim=-1)
251
+ )
252
+ group_idx = torch.topk(group_scores, k=self.topk_group, dim=-1, sorted=False)[1]
253
+ group_mask = torch.zeros_like(group_scores)
254
+ group_mask.scatter_(1, group_idx, 1)
255
+
256
+ # Mask the experts based on selection groups
257
+ score_mask = (
258
+ group_mask.unsqueeze(-1)
259
+ .expand(num_tokens, self.n_group, self.num_experts // self.n_group)
260
+ .reshape(num_tokens, -1)
261
+ )
262
+
263
+ masked_scores = scores.masked_fill(~score_mask.bool(), float("-inf"))
264
+ probs, top_indices = torch.topk(masked_scores, k=self.top_k, dim=-1)
265
+
266
+ return probs, top_indices
267
+
268
+ def forward(self, hidden_states):
269
+ # compute gating score
270
+ hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
271
+ logits = F.linear(
272
+ hidden_states.type(torch.float32), self.weight.type(torch.float32)
273
+ )
274
+
275
+ scores = torch.sigmoid(logits.float()).type_as(logits)
276
+
277
+ scores_for_routing = scores + self.expert_bias
278
+ _, topk_idx = self.group_limited_topk(scores_for_routing)
279
+
280
+ scores = torch.gather(scores, dim=1, index=topk_idx).type_as(logits)
281
+
282
+ topk_weight = (
283
+ scores / (scores.sum(dim=-1, keepdim=True) + 1e-20)
284
+ if self.top_k > 1
285
+ else scores
286
+ )
287
+ topk_weight = topk_weight * self.routed_scaling_factor
288
+
289
+ return topk_idx, topk_weight, logits
290
+
291
+
292
+ class LLaDA2MoeSparseMoeBlock(nn.Module):
293
+ """
294
+ A mixed expert module containing shared experts.
295
+ """
296
+
297
+ def __init__(self, config: LLaDA2MoeConfig):
298
+ super().__init__()
299
+ self.config = config
300
+ self.num_experts_per_tok = config.num_experts_per_tok
301
+ self._setup_experts()
302
+ self.gate = LLaDA2MoeGate(config)
303
+ if config.num_shared_experts is not None:
304
+ self.shared_experts = LLaDA2MoeMLP(
305
+ config=config,
306
+ intermediate_size=config.moe_intermediate_size
307
+ * config.num_shared_experts,
308
+ )
309
+
310
+ def _setup_experts(self):
311
+ self.experts = nn.ModuleList(
312
+ [
313
+ LLaDA2MoeMLP(
314
+ config=self.config,
315
+ intermediate_size=self.config.moe_intermediate_size,
316
+ )
317
+ for _ in range(self.config.num_experts)
318
+ ]
319
+ )
320
+
321
+ def forward(self, hidden_states):
322
+ identity = hidden_states
323
+ bsz, seq_len, h = hidden_states.shape
324
+ topk_idx, topk_weight, router_logits = self.gate(hidden_states)
325
+ hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
326
+ flat_topk_idx = topk_idx.view(-1)
327
+ if self.training:
328
+ hidden_states = hidden_states.repeat_interleave(
329
+ self.num_experts_per_tok, dim=0
330
+ )
331
+ y = torch.empty_like(hidden_states)
332
+ for i, expert in enumerate(self.experts):
333
+ y[flat_topk_idx == i] = expert(hidden_states[flat_topk_idx == i])
334
+ y = (y.view(*topk_weight.shape, -1) * topk_weight.unsqueeze(-1)).sum(dim=1)
335
+ y = y.to(hidden_states.dtype).view(bsz, seq_len, h)
336
+ else:
337
+ y = self.moe_infer(hidden_states, topk_idx, topk_weight).view(
338
+ bsz, seq_len, h
339
+ )
340
+ if self.config.num_shared_experts is not None:
341
+ y = y + self.shared_experts(identity)
342
+ return y, (
343
+ router_logits.view(bsz, seq_len, -1),
344
+ topk_idx.view(bsz, seq_len, -1),
345
+ )
346
+
347
+ @torch.no_grad()
348
+ def moe_infer(self, x, topk_ids, topk_weight):
349
+ cnts = topk_ids.new_zeros((topk_ids.shape[0], len(self.experts)))
350
+ cnts.scatter_(1, topk_ids, 1)
351
+ tokens_per_expert = cnts.sum(dim=0)
352
+ idxs = topk_ids.view(-1).argsort()
353
+ sorted_tokens = x[idxs // topk_ids.shape[1]]
354
+ tokens_per_expert = tokens_per_expert.cpu().numpy()
355
+ outputs = []
356
+ start_idx = 0
357
+ for i, num_tokens_tensor in enumerate(tokens_per_expert):
358
+ num_tokens = num_tokens_tensor.item()
359
+ if num_tokens == 0:
360
+ continue
361
+ end_idx = start_idx + num_tokens
362
+ expert = self.experts[i]
363
+ tokens_for_this_expert = sorted_tokens[start_idx:end_idx]
364
+ expert_out = expert(tokens_for_this_expert)
365
+ outputs.append(expert_out.to(x.device))
366
+ start_idx = end_idx
367
+
368
+ outs = torch.cat(outputs, dim=0) if len(outputs) else sorted_tokens.new_empty(0)
369
+ new_x = torch.empty_like(outs)
370
+ new_x[idxs] = outs
371
+ final_out = (
372
+ new_x.view(*topk_ids.shape, -1)
373
+ .type(topk_weight.dtype)
374
+ .mul_(topk_weight.unsqueeze(dim=-1))
375
+ .sum(dim=1)
376
+ .type(new_x.dtype)
377
+ )
378
+ return final_out
379
+
380
+
381
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv
382
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
383
+ """
384
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
385
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
386
+ """
387
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
388
+ if n_rep == 1:
389
+ return hidden_states
390
+ hidden_states = hidden_states[:, :, None, :, :].expand(
391
+ batch, num_key_value_heads, n_rep, slen, head_dim
392
+ )
393
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
394
+
395
+
396
+ def eager_attention_forward(
397
+ module: nn.Module,
398
+ query: torch.Tensor,
399
+ key: torch.Tensor,
400
+ value: torch.Tensor,
401
+ attention_mask: Optional[torch.Tensor],
402
+ scaling: float,
403
+ dropout: float = 0.0,
404
+ **kwargs: Unpack[TransformersKwargs],
405
+ ):
406
+ key_states = repeat_kv(key, module.num_key_value_groups)
407
+ value_states = repeat_kv(value, module.num_key_value_groups)
408
+
409
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
410
+ if attention_mask is not None:
411
+ attn_weights = attn_weights + attention_mask[:, :, :, : key_states.shape[-2]]
412
+
413
+ # upcast attention to fp32
414
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(
415
+ query.dtype
416
+ )
417
+ attn_weights = nn.functional.dropout(
418
+ attn_weights, p=dropout, training=module.training
419
+ )
420
+ attn_output = torch.matmul(attn_weights, value_states)
421
+ attn_output = attn_output.transpose(1, 2).contiguous()
422
+
423
+ return attn_output, attn_weights
424
+
425
+
426
+ # Copied from transformers.models.llama.modeling_llama.LlamaAttention with Llama->LLaDA2Moe
427
+ class LLaDA2MoeAttention(nn.Module):
428
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
429
+
430
+ def __init__(self, config: LLaDA2MoeConfig, layer_idx: Optional[int] = None):
431
+ super().__init__()
432
+ self.config = config
433
+ self.layer_idx = layer_idx
434
+ if layer_idx is None:
435
+ logger.warning_once(
436
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
437
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
438
+ "when creating this class."
439
+ )
440
+ self.attention_dropout = config.attention_dropout
441
+ self.hidden_size = config.hidden_size
442
+ self.num_heads = config.num_attention_heads
443
+ self.head_dim = config.head_dim or self.hidden_size // self.num_heads
444
+ partial_rotary_factor = (
445
+ config.partial_rotary_factor
446
+ if hasattr(config, "partial_rotary_factor")
447
+ else 1.0
448
+ )
449
+ self.rope_dim = int(self.head_dim * partial_rotary_factor)
450
+ self.num_key_value_heads = config.num_key_value_heads
451
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
452
+ self.max_position_embeddings = config.max_position_embeddings
453
+ self.rope_theta = config.rope_theta
454
+ self.scaling = self.head_dim**-0.5
455
+ self.is_causal = False
456
+
457
+ self.query_key_value = nn.Linear(
458
+ self.hidden_size,
459
+ (self.num_heads + 2 * self.num_key_value_heads) * self.head_dim,
460
+ bias=config.use_qkv_bias,
461
+ )
462
+
463
+ if self.config.use_qk_norm:
464
+ self.query_layernorm = LLaDA2MoeRMSNorm(
465
+ self.head_dim, eps=config.rms_norm_eps
466
+ )
467
+ self.key_layernorm = LLaDA2MoeRMSNorm(
468
+ self.head_dim, eps=config.rms_norm_eps
469
+ )
470
+ self.dense = nn.Linear(
471
+ self.num_heads * self.head_dim, self.hidden_size, bias=config.use_bias
472
+ )
473
+ self.sliding_window = getattr(config, "sliding_window", None)
474
+
475
+ def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
476
+ return (
477
+ tensor.view(bsz, seq_len, self.num_heads, self.head_dim)
478
+ .transpose(1, 2)
479
+ .contiguous()
480
+ )
481
+
482
+ def forward(
483
+ self,
484
+ hidden_states: torch.Tensor,
485
+ attention_mask: Optional[torch.Tensor] = None,
486
+ position_ids: Optional[torch.LongTensor] = None,
487
+ past_key_value: Optional[Cache] = None,
488
+ output_attentions: bool = False,
489
+ use_cache: bool = False,
490
+ position_embeddings: Optional[
491
+ Tuple[torch.Tensor, torch.Tensor]
492
+ ] = None, # necessary, but kept here for BC
493
+ **kwargs,
494
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
495
+ input_shape = hidden_states.shape[:-1]
496
+
497
+ bsz, q_len, _ = hidden_states.size()
498
+
499
+ qkv = self.query_key_value(hidden_states)
500
+ qkv = qkv.view(
501
+ bsz, q_len, self.num_heads + 2 * self.num_key_value_heads, self.head_dim
502
+ )
503
+
504
+ query_states, key_states, value_states = qkv.split(
505
+ [self.num_heads, self.num_key_value_heads, self.num_key_value_heads], dim=-2
506
+ )
507
+ query_states = query_states.transpose(1, 2)
508
+ key_states = key_states.transpose(1, 2)
509
+ value_states = value_states.transpose(1, 2)
510
+
511
+ if self.config.use_qk_norm:
512
+ query_states = self.query_layernorm(query_states)
513
+ key_states = self.key_layernorm(key_states)
514
+
515
+ cos, sin = position_embeddings
516
+ query_states, key_states = apply_rotary_pos_emb(
517
+ query_states, key_states, cos, sin
518
+ )
519
+
520
+ if past_key_value is not None:
521
+ if self.layer_idx is None:
522
+ raise ValueError(
523
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
524
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
525
+ "with a layer index."
526
+ )
527
+ cache_kwargs = {"sin": sin, "cos": cos}
528
+ key_states, value_states = past_key_value.update(
529
+ key_states, value_states, self.layer_idx, cache_kwargs
530
+ )
531
+
532
+ attention_interface: Callable = eager_attention_forward
533
+ if self.config._attn_implementation != "eager":
534
+ attention_interface = ALL_ATTENTION_FUNCTIONS[
535
+ self.config._attn_implementation
536
+ ]
537
+
538
+ attn_output, attn_weights = attention_interface(
539
+ self,
540
+ query_states,
541
+ key_states,
542
+ value_states,
543
+ attention_mask,
544
+ dropout=0.0 if not self.training else self.attention_dropout,
545
+ scaling=self.scaling,
546
+ sliding_window=self.sliding_window, # diff with Llama
547
+ **kwargs,
548
+ )
549
+
550
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
551
+ attn_output = self.dense(attn_output)
552
+
553
+ return attn_output, attn_weights, past_key_value
554
+
555
+
556
+ class LLaDA2MoeDecoderLayer(nn.Module):
557
+ def __init__(self, config: LLaDA2MoeConfig, layer_idx: int):
558
+ super().__init__()
559
+ self.hidden_size = config.hidden_size
560
+
561
+ self.attention = LLaDA2MoeAttention(config=config, layer_idx=layer_idx)
562
+
563
+ self.mlp = (
564
+ LLaDA2MoeSparseMoeBlock(config)
565
+ if (
566
+ config.num_experts is not None
567
+ and layer_idx >= config.first_k_dense_replace
568
+ )
569
+ else LLaDA2MoeMLP(config=config, intermediate_size=config.intermediate_size)
570
+ )
571
+ self.input_layernorm = LLaDA2MoeRMSNorm(
572
+ config.hidden_size, eps=config.rms_norm_eps
573
+ )
574
+ self.post_attention_layernorm = LLaDA2MoeRMSNorm(
575
+ config.hidden_size, eps=config.rms_norm_eps
576
+ )
577
+
578
+ def forward(
579
+ self,
580
+ hidden_states: torch.Tensor,
581
+ attention_mask: Optional[torch.Tensor] = None,
582
+ position_ids: Optional[torch.LongTensor] = None,
583
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
584
+ output_attentions: Optional[bool] = False,
585
+ output_router_logits: Optional[bool] = False,
586
+ use_cache: Optional[bool] = False,
587
+ position_embeddings: Optional[
588
+ Tuple[torch.Tensor, torch.Tensor]
589
+ ] = None, # necessary, but kept here for BC
590
+ **kwargs,
591
+ ) -> Tuple[
592
+ torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]
593
+ ]:
594
+ """
595
+ Args:
596
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
597
+ attention_mask (`torch.FloatTensor`, *optional*):
598
+ attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
599
+ query_sequence_length, key_sequence_length)` if default attention is used.
600
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
601
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
602
+ config.n_positions - 1]`.
603
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*):
604
+ cached past key and value projection states
605
+ output_attentions (`bool`, *optional*):
606
+ Whether to return the attentions tensors of all attention layers. See `attentions` under
607
+ returned tensors for more detail.
608
+ output_router_logits (`bool`, *optional*):
609
+ Whether or not to return the logits of all the routers. They are useful for computing the router loss,
610
+ and should not be returned during inference.
611
+ use_cache (`bool`, *optional*):
612
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
613
+ (see `past_key_values`).
614
+ """
615
+ residual = hidden_states
616
+
617
+ hidden_states = self.input_layernorm(hidden_states)
618
+
619
+ # Self Attention
620
+ hidden_states, self_attn_weights, present_key_value = self.attention(
621
+ hidden_states=hidden_states,
622
+ attention_mask=attention_mask,
623
+ position_ids=position_ids,
624
+ past_key_value=past_key_value,
625
+ output_attentions=output_attentions,
626
+ position_embeddings=position_embeddings,
627
+ use_cache=use_cache,
628
+ )
629
+ hidden_states = residual + hidden_states
630
+
631
+ # Fully Connected
632
+ residual = hidden_states
633
+ hidden_states = self.post_attention_layernorm(hidden_states)
634
+ hidden_states = self.mlp(hidden_states)
635
+ if isinstance(hidden_states, tuple):
636
+ hidden_states, router_logits = hidden_states
637
+ else:
638
+ router_logits = None
639
+ hidden_states = residual + hidden_states.to(residual.device)
640
+
641
+ outputs = (hidden_states,)
642
+
643
+ if output_attentions:
644
+ outputs += (self_attn_weights,)
645
+
646
+ if use_cache:
647
+ outputs += (present_key_value,)
648
+
649
+ if output_router_logits:
650
+ outputs += (router_logits,)
651
+
652
+ return outputs
653
+
654
+
655
+ LLADA2MOE_START_DOCSTRING = r"""
656
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
657
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
658
+ etc.)
659
+
660
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
661
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
662
+ and behavior.
663
+
664
+ Parameters:
665
+ config ([`LLaDA2MoeConfig`]):
666
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
667
+ load the weights associated with the model, only the configuration. Check out the
668
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
669
+ """
670
+
671
+
672
+ @add_start_docstrings(
673
+ "The bare LLaDA2Moe Model outputting raw hidden-states without any specific head on top.",
674
+ LLADA2MOE_START_DOCSTRING,
675
+ )
676
+ class LLaDA2MoePreTrainedModel(PreTrainedModel):
677
+ config_class = LLaDA2MoeConfig
678
+ base_model_prefix = "model"
679
+ supports_gradient_checkpointing = True
680
+ _no_split_modules = ["LLaDA2MoeDecoderLayer"]
681
+ _skip_keys_device_placement = ["past_key_values"]
682
+ _supports_flash_attn_2 = False
683
+ _supports_sdpa = True
684
+ _supports_flex_attn = True
685
+ _supports_cache_class = True
686
+
687
+ @torch.no_grad()
688
+ def _init_weights(self, module):
689
+ super()._init_weights(module)
690
+ std = self.config.initializer_range
691
+ if isinstance(module, LLaDA2MoeGate):
692
+ nn.init.normal_(module.weight, mean=0.0, std=std)
693
+
694
+
695
+ LLADA2MOE_INPUTS_DOCSTRING = r"""
696
+ Args:
697
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
698
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
699
+ it.
700
+
701
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
702
+ [`PreTrainedTokenizer.__call__`] for details.
703
+
704
+ [What are input IDs?](../glossary#input-ids)
705
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
706
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
707
+
708
+ - 1 for tokens that are **not masked**,
709
+ - 0 for tokens that are **masked**.
710
+
711
+ [What are attention masks?](../glossary#attention-mask)
712
+
713
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
714
+ [`PreTrainedTokenizer.__call__`] for details.
715
+
716
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
717
+ `past_key_values`).
718
+
719
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
720
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
721
+ information on the default strategy.
722
+
723
+ - 1 indicates the head is **not masked**,
724
+ - 0 indicates the head is **masked**.
725
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
726
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
727
+ config.n_positions - 1]`.
728
+
729
+ [What are position IDs?](../glossary#position-ids)
730
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
731
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
732
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
733
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
734
+
735
+ Two formats are allowed:
736
+ - a [`~cache_utils.Cache`] instance;
737
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
738
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
739
+ cache format.
740
+
741
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
742
+ legacy cache format will be returned.
743
+
744
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
745
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
746
+ of shape `(batch_size, sequence_length)`.
747
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
748
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
749
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
750
+ model's internal embedding lookup matrix.
751
+ use_cache (`bool`, *optional*):
752
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
753
+ `past_key_values`).
754
+ output_attentions (`bool`, *optional*):
755
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
756
+ tensors for more detail.
757
+ output_hidden_states (`bool`, *optional*):
758
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
759
+ more detail.
760
+ return_dict (`bool`, *optional*):
761
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
762
+ """
763
+
764
+
765
+ @add_start_docstrings(
766
+ "The bare LLaDA2Moe Model outputting raw hidden-states without any specific head on top.",
767
+ LLADA2MOE_START_DOCSTRING,
768
+ )
769
+ class LLaDA2MoeModel(LLaDA2MoePreTrainedModel):
770
+ """
771
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`LLaDA2MoeDecoderLayer`]
772
+
773
+ Args:
774
+ config: LLaDA2MoeConfig
775
+ """
776
+
777
+ def __init__(self, config: LLaDA2MoeConfig):
778
+ super().__init__(config)
779
+ self.padding_idx = config.pad_token_id
780
+ self.vocab_size = config.vocab_size
781
+
782
+ self.word_embeddings = nn.Embedding(
783
+ config.vocab_size, config.hidden_size, self.padding_idx
784
+ )
785
+ self.layers = nn.ModuleList(
786
+ [
787
+ LLaDA2MoeDecoderLayer(config, layer_idx)
788
+ for layer_idx in range(config.num_hidden_layers)
789
+ ]
790
+ )
791
+ self._use_sdpa = config._attn_implementation == "sdpa"
792
+ self._use_flex_attention = config._attn_implementation == "flex_attention"
793
+ self.norm = LLaDA2MoeRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
794
+ self.rotary_emb = LLaDA2MoeRotaryEmbedding(config=config)
795
+ self.gradient_checkpointing = False
796
+ # Initialize weights and apply final processing
797
+ self.post_init()
798
+
799
+ def get_input_embeddings(self):
800
+ return self.word_embeddings
801
+
802
+ def set_input_embeddings(self, value):
803
+ self.word_embeddings = value
804
+
805
+ @add_start_docstrings_to_model_forward(LLADA2MOE_INPUTS_DOCSTRING)
806
+ def forward(
807
+ self,
808
+ input_ids: torch.LongTensor = None,
809
+ attention_mask: Optional[torch.Tensor] = None,
810
+ position_ids: Optional[torch.LongTensor] = None,
811
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
812
+ inputs_embeds: Optional[torch.FloatTensor] = None,
813
+ use_cache: Optional[bool] = None,
814
+ output_attentions: Optional[bool] = None,
815
+ output_hidden_states: Optional[bool] = None,
816
+ output_router_logits: Optional[bool] = None,
817
+ return_dict: Optional[bool] = None,
818
+ **kwargs,
819
+ ) -> Union[Tuple, MoeModelOutputWithPast]:
820
+ output_attentions = (
821
+ output_attentions
822
+ if output_attentions is not None
823
+ else self.config.output_attentions
824
+ )
825
+ output_hidden_states = (
826
+ output_hidden_states
827
+ if output_hidden_states is not None
828
+ else self.config.output_hidden_states
829
+ )
830
+ output_router_logits = (
831
+ output_router_logits
832
+ if output_router_logits is not None
833
+ else self.config.output_router_logits
834
+ )
835
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
836
+
837
+ return_dict = (
838
+ return_dict if return_dict is not None else self.config.use_return_dict
839
+ )
840
+
841
+ # retrieve input_ids and inputs_embeds
842
+ if input_ids is not None and inputs_embeds is not None:
843
+ raise ValueError(
844
+ "You cannot specify both input_ids and inputs_embeds at the same time"
845
+ )
846
+ elif input_ids is not None:
847
+ batch_size, seq_length = input_ids.shape[:2]
848
+ elif inputs_embeds is not None:
849
+ batch_size, seq_length = inputs_embeds.shape[:2]
850
+ else:
851
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
852
+
853
+ if self.gradient_checkpointing and self.training:
854
+ if use_cache:
855
+ logger.warning_once(
856
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`transformers."
857
+ )
858
+ use_cache = False
859
+
860
+ if use_cache and past_key_values is None:
861
+ past_key_values = DynamicCache()
862
+
863
+ if inputs_embeds is None:
864
+ inputs_embeds = self.word_embeddings(input_ids)
865
+
866
+ past_seen_tokens = (
867
+ past_key_values.get_seq_length() if past_key_values is not None else 0
868
+ )
869
+
870
+ if position_ids is None:
871
+ position_ids = torch.arange(
872
+ past_seen_tokens,
873
+ past_seen_tokens + inputs_embeds.shape[1],
874
+ device=inputs_embeds.device,
875
+ )
876
+ position_ids = position_ids.unsqueeze(0)
877
+ attention_mask = create_bidirectional_mask(
878
+ config=self.config,
879
+ inputs_embeds=inputs_embeds,
880
+ attention_mask=attention_mask,
881
+ )
882
+ # embed positions
883
+ hidden_states = inputs_embeds
884
+
885
+ # create position embeddings to be shared across the decoder layers
886
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
887
+
888
+ # decoder layers
889
+ all_hidden_states = () if output_hidden_states else None
890
+ all_self_attns = () if output_attentions else None
891
+ all_router_logits = () if output_router_logits else None
892
+ next_decoder_cache = None
893
+
894
+ for decoder_layer in self.layers:
895
+ if output_hidden_states:
896
+ all_hidden_states += (hidden_states,)
897
+
898
+ if self.gradient_checkpointing and self.training:
899
+ layer_outputs = self._gradient_checkpointing_func(
900
+ decoder_layer.__call__,
901
+ hidden_states,
902
+ attention_mask,
903
+ position_ids,
904
+ past_key_values,
905
+ output_attentions,
906
+ output_router_logits,
907
+ use_cache,
908
+ position_embeddings,
909
+ )
910
+ else:
911
+ layer_outputs = decoder_layer(
912
+ hidden_states,
913
+ attention_mask=attention_mask,
914
+ position_ids=position_ids,
915
+ past_key_value=past_key_values,
916
+ output_attentions=output_attentions,
917
+ output_router_logits=output_router_logits,
918
+ use_cache=use_cache,
919
+ position_embeddings=position_embeddings,
920
+ )
921
+ hidden_states = layer_outputs[0]
922
+
923
+ if use_cache:
924
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
925
+
926
+ if output_attentions:
927
+ all_self_attns += (layer_outputs[1],)
928
+
929
+ if output_router_logits and layer_outputs[-1] is not None:
930
+ all_router_logits += (layer_outputs[-1],)
931
+
932
+ hidden_states = self.norm(hidden_states)
933
+
934
+ # add hidden states from the last decoder layer
935
+ if output_hidden_states:
936
+ all_hidden_states += (hidden_states,)
937
+
938
+ next_cache = None
939
+ if use_cache:
940
+ next_cache = next_decoder_cache
941
+ if not return_dict:
942
+ return tuple(
943
+ v
944
+ for v in [
945
+ hidden_states,
946
+ next_cache,
947
+ all_hidden_states,
948
+ all_self_attns,
949
+ all_router_logits,
950
+ ]
951
+ if v is not None
952
+ )
953
+ return MoeModelOutputWithPast(
954
+ last_hidden_state=hidden_states,
955
+ past_key_values=next_cache,
956
+ hidden_states=all_hidden_states,
957
+ attentions=all_self_attns,
958
+ router_logits=all_router_logits,
959
+ )
960
+
961
+
962
+ class LLaDA2MoeModelLM(LLaDA2MoePreTrainedModel, GenerationMixin):
963
+ _tied_weights_keys = ["lm_head.weight"]
964
+
965
+ def __init__(self, config: LLaDA2MoeConfig):
966
+ super().__init__(config)
967
+ self.model = LLaDA2MoeModel(config)
968
+ self.vocab_size = config.vocab_size
969
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
970
+
971
+ # Initialize weights and apply final processing
972
+ self.post_init()
973
+
974
+ def get_input_embeddings(self):
975
+ return self.model.word_embeddings
976
+
977
+ def set_input_embeddings(self, value):
978
+ self.model.word_embeddings = value
979
+
980
+ def get_output_embeddings(self):
981
+ return self.lm_head
982
+
983
+ def set_output_embeddings(self, new_embeddings):
984
+ self.lm_head = new_embeddings
985
+
986
+ def set_decoder(self, decoder):
987
+ self.model = decoder
988
+
989
+ def get_decoder(self):
990
+ return self.model
991
+
992
+ @add_start_docstrings_to_model_forward(LLADA2MOE_INPUTS_DOCSTRING)
993
+ @replace_return_docstrings(
994
+ output_type=MoeCausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC
995
+ )
996
+ def forward(
997
+ self,
998
+ input_ids: torch.LongTensor = None,
999
+ attention_mask: Optional[torch.Tensor] = None,
1000
+ position_ids: Optional[torch.LongTensor] = None,
1001
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1002
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1003
+ labels: Optional[torch.LongTensor] = None,
1004
+ use_cache: Optional[bool] = None,
1005
+ output_attentions: Optional[bool] = None,
1006
+ output_hidden_states: Optional[bool] = None,
1007
+ output_router_logits: Optional[bool] = None,
1008
+ return_dict: Optional[bool] = None,
1009
+ **kwargs,
1010
+ ) -> Union[Tuple, MoeCausalLMOutputWithPast]:
1011
+ r"""
1012
+ Args:
1013
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1014
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1015
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1016
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1017
+
1018
+ Returns:
1019
+
1020
+ Example:
1021
+
1022
+ ```python
1023
+ >>> from transformers import AutoTokenizer
1024
+
1025
+ >>> model = LLaDA2MoeForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
1026
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
1027
+
1028
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1029
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1030
+
1031
+ >>> # Generate
1032
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1033
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1034
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1035
+ ```"""
1036
+ output_attentions = (
1037
+ output_attentions
1038
+ if output_attentions is not None
1039
+ else self.config.output_attentions
1040
+ )
1041
+ output_hidden_states = (
1042
+ output_hidden_states
1043
+ if output_hidden_states is not None
1044
+ else self.config.output_hidden_states
1045
+ )
1046
+ output_router_logits = (
1047
+ output_router_logits
1048
+ if output_router_logits is not None
1049
+ else self.config.output_router_logits
1050
+ )
1051
+ return_dict = (
1052
+ return_dict if return_dict is not None else self.config.use_return_dict
1053
+ )
1054
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1055
+ outputs = self.model(
1056
+ input_ids=input_ids,
1057
+ attention_mask=attention_mask,
1058
+ position_ids=position_ids,
1059
+ past_key_values=past_key_values,
1060
+ inputs_embeds=inputs_embeds,
1061
+ use_cache=use_cache,
1062
+ output_attentions=output_attentions,
1063
+ output_hidden_states=output_hidden_states,
1064
+ output_router_logits=output_router_logits,
1065
+ return_dict=return_dict,
1066
+ **kwargs,
1067
+ )
1068
+
1069
+ loss = None
1070
+ aux_loss = None
1071
+ hidden_states = outputs[0]
1072
+
1073
+ logits = self.lm_head(hidden_states)
1074
+ logits = logits.float()
1075
+
1076
+ if labels is not None:
1077
+ # LLaDA2.0 will use same label position logits
1078
+ shift_logits = logits
1079
+ shift_labels = labels
1080
+ # Flatten the tokens
1081
+ loss_fct = CrossEntropyLoss()
1082
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1083
+ shift_labels = shift_labels.view(-1)
1084
+ # Enable model parallelism
1085
+ shift_labels = shift_labels.to(shift_logits.device)
1086
+ loss = loss_fct(shift_logits, shift_labels)
1087
+
1088
+ if not return_dict:
1089
+ output = (logits,) + outputs[1:]
1090
+ if output_router_logits:
1091
+ output = (aux_loss,) + output
1092
+ return (loss,) + output if loss is not None else output
1093
+
1094
+ return MoeCausalLMOutputWithPast(
1095
+ loss=loss,
1096
+ aux_loss=aux_loss,
1097
+ logits=logits,
1098
+ past_key_values=outputs.past_key_values,
1099
+ hidden_states=outputs.hidden_states,
1100
+ attentions=outputs.attentions,
1101
+ router_logits=outputs.router_logits,
1102
+ )
1103
+
1104
+ def prepare_inputs_for_generation(
1105
+ self,
1106
+ input_ids,
1107
+ past_key_values=None,
1108
+ attention_mask=None,
1109
+ inputs_embeds=None,
1110
+ token_type_ids=None,
1111
+ **kwargs,
1112
+ ):
1113
+ if past_key_values is not None:
1114
+ if isinstance(past_key_values, Cache):
1115
+ cache_length = past_key_values.get_seq_length()
1116
+ past_length = past_key_values.seen_tokens
1117
+ max_cache_length = (
1118
+ past_key_values.get_max_length()
1119
+ if hasattr(past_key_values, "get_max_length")
1120
+ else past_key_values.get_max_cache_shape()
1121
+ )
1122
+ else:
1123
+ cache_length = past_length = past_key_values[0][0].shape[2]
1124
+ max_cache_length = None
1125
+
1126
+ # Keep only the unprocessed tokens:
1127
+ # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where
1128
+ # some of the inputs are exclusivelly passed as part of the cache (e.g. when passing input_embeds as input)
1129
+ if (
1130
+ attention_mask is not None
1131
+ and attention_mask.shape[1] > input_ids.shape[1]
1132
+ ):
1133
+ input_ids = input_ids[:, -(attention_mask.shape[1] - past_length) :]
1134
+ # 2 - If the past_length is smaller than input_ids', then input_ids holds all input tokens. We can discard
1135
+ # input_ids based on the past_length.
1136
+ elif past_length < input_ids.shape[1]:
1137
+ input_ids = input_ids[:, past_length:]
1138
+ # 3 - Otherwise (past_length >= input_ids.shape[1]), let's assume input_ids only has unprocessed tokens.
1139
+
1140
+ # If we are about to go beyond the maximum cache length, we need to crop the input attention mask.
1141
+ if (
1142
+ max_cache_length is not None
1143
+ and attention_mask is not None
1144
+ and cache_length + input_ids.shape[1] > max_cache_length
1145
+ ):
1146
+ attention_mask = attention_mask[:, -max_cache_length:]
1147
+
1148
+ position_ids = kwargs.get("position_ids", None)
1149
+ if attention_mask is not None and position_ids is None:
1150
+ # create position_ids on the fly for batch generation
1151
+ position_ids = attention_mask.long().cumsum(-1) - 1
1152
+ position_ids.masked_fill_(attention_mask == 0, 1)
1153
+ if past_key_values:
1154
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1155
+
1156
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1157
+ if inputs_embeds is not None and past_key_values is None:
1158
+ model_inputs = {"inputs_embeds": inputs_embeds}
1159
+ else:
1160
+ model_inputs = {"input_ids": input_ids}
1161
+
1162
+ model_inputs.update(
1163
+ {
1164
+ "position_ids": position_ids,
1165
+ "past_key_values": past_key_values,
1166
+ "use_cache": kwargs.get("use_cache"),
1167
+ "attention_mask": attention_mask,
1168
+ }
1169
+ )
1170
+ return model_inputs
1171
+
1172
+ @staticmethod
1173
+ def _reorder_cache(past_key_values, beam_idx):
1174
+ reordered_past = ()
1175
+ for layer_past in past_key_values:
1176
+ reordered_past += (
1177
+ tuple(
1178
+ past_state.index_select(0, beam_idx.to(past_state.device))
1179
+ for past_state in layer_past
1180
+ ),
1181
+ )
1182
+ return reordered_past
1183
+
1184
+ @staticmethod
1185
+ def _top_k_logits(logits, k):
1186
+ if k is None or k <= 0:
1187
+ return logits
1188
+ else:
1189
+ values, _ = torch.topk(logits, k)
1190
+ min_values = values[..., -1, None]
1191
+ return torch.where(
1192
+ logits < min_values, torch.full_like(logits, float("-inf")), logits
1193
+ )
1194
+
1195
+ @staticmethod
1196
+ def _top_p_logits(logits, p):
1197
+ if p is None or p >= 1.0:
1198
+ return logits
1199
+ sorted_logits, sorted_indices = torch.sort(logits, descending=True)
1200
+ cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
1201
+ sorted_mask = cumulative_probs > p
1202
+ sorted_mask[..., 1:] = sorted_mask[..., :-1].clone()
1203
+ sorted_mask[..., 0] = False
1204
+ mask_indices = torch.scatter(
1205
+ torch.full_like(logits, False, dtype=torch.bool),
1206
+ -1,
1207
+ sorted_indices,
1208
+ sorted_mask,
1209
+ )
1210
+ return logits.masked_fill(mask_indices, float("-inf"))
1211
+
1212
+ def _sample_with_temperature_topk_topp(
1213
+ self, logits, temperature=1.0, top_k=0, top_p=1.0
1214
+ ):
1215
+ orig_shape = logits.shape[:-1]
1216
+ vocab_size = logits.shape[-1]
1217
+ logits = logits.reshape(-1, vocab_size)
1218
+ if temperature == 0.0:
1219
+ token = torch.argmax(logits, dim=-1, keepdim=True)
1220
+ probs = F.softmax(logits, dim=-1)
1221
+ token_prob = torch.gather(probs, -1, token)
1222
+ return token.view(*orig_shape), token_prob.view(*orig_shape)
1223
+
1224
+ if temperature > 0 and temperature != 1.0:
1225
+ logits = logits / temperature
1226
+ logits = self._top_k_logits(logits, top_k)
1227
+ logits = self._top_p_logits(logits, top_p)
1228
+ probs = F.softmax(logits, dim=-1)
1229
+ token = torch.multinomial(probs, num_samples=1)
1230
+ token_prob = torch.gather(probs, -1, token)
1231
+ return token.view(*orig_shape), token_prob.view(*orig_shape)
1232
+
1233
+ @staticmethod
1234
+ def _get_num_transfer_tokens(block_length, steps):
1235
+ if steps == 0:
1236
+ return torch.tensor([], dtype=torch.int64)
1237
+ base = block_length // steps
1238
+ remainder = block_length % steps
1239
+ num_transfer_tokens = torch.full((steps,), base, dtype=torch.int64)
1240
+ num_transfer_tokens[:remainder] += 1
1241
+ return num_transfer_tokens
1242
+
1243
+ @torch.no_grad()
1244
+ def generate(
1245
+ self,
1246
+ inputs: Optional[torch.Tensor] = None,
1247
+ temperature: float = 0.0,
1248
+ block_length: int = 32,
1249
+ steps: int = 32,
1250
+ gen_length: int = 2048,
1251
+ top_p: Optional[float] = None,
1252
+ top_k: Optional[int] = None,
1253
+ eos_early_stop: bool = False,
1254
+ minimal_topk: int = 1,
1255
+ threshold: float = 0.95,
1256
+ editing_threshold: float = 0.9,
1257
+ max_post_steps: int = 16,
1258
+ eos_id: int = 156892,
1259
+ mask_id: int = 156895,
1260
+ num_to_transfer: int = 1,
1261
+ ):
1262
+ r"""
1263
+ Generates tokens using a block-wise, iterative refinement strategy.
1264
+ This method operates differently from standard autoregressive generation. It first creates a template of the
1265
+ full desired length, filled with a special `mask_id`. It then processes this template in segments (`blocks`)
1266
+ and iteratively "denoises" or "refines" the `mask_id` tokens into actual tokens over a series of `steps` for
1267
+ each block. A custom block-diagonal causal attention mask ensures that generation within a block can attend to
1268
+ all previous blocks but not future ones.
1269
+ <Tip warning={true}>
1270
+ This is a specialized generation method. The quality and speed of the output are highly dependent on the interplay
1271
+ between `block_length`, `steps`, and `threshold`. It aims to achieve faster generation through parallel
1272
+ decoding within blocks, which is a departure from the token-by-token generation of standard `.generate()` methods.
1273
+ </Tip>
1274
+ Parameters:
1275
+ inputs (`torch.Tensor`):
1276
+ The token sequence used as a prompt for the generation.
1277
+ temperature (`float`, *optional*, defaults to 0.0):
1278
+ The value used to module the next token probabilities. A value of 0.0 corresponds to greedy decoding.
1279
+ block_length (`int`, *optional*, defaults to 32):
1280
+ The size of each generation block. The model generates text in parallel within these blocks. This is a
1281
+ key parameter for controlling the granularity of the generation process.
1282
+ steps (`int`, *optional*, defaults to 32):
1283
+ The number of iterative refinement (or "denoising") steps to perform for each block. Within each block,
1284
+ the model will try to replace `mask_id` tokens with real tokens for this many iterations.
1285
+ gen_length (`int`, *optional*, defaults to 2048):
1286
+ The maximum number of tokens to generate, excluding the prompt.
1287
+ top_p (`float`, *optional*):
1288
+ If set to a float value between 0 and 1, only the most probable tokens with probabilities that add up to
1289
+ `top_p` or higher are kept for generation (nucleus sampling).
1290
+ top_k (`int`, *optional*):
1291
+ The number of highest probability vocabulary tokens to keep for top-k-filtering.
1292
+ eos_early_stop (`bool`, *optional*, defaults to `False`):
1293
+ If `True`, generation will stop as soon as a valid End-Of-Sequence token is generated and confirmed,
1294
+ even if `gen_length` has not been reached.
1295
+ minimal_topk (`int`, *optional*, defaults to 1):
1296
+ A parameter used to dynamically adjust the number of refinement `steps`. The effective number of steps
1297
+ is capped at `gen_length // minimal_topk`.
1298
+ threshold (`float`, *optional*, defaults to 0.95):
1299
+ The confidence probability threshold for accepting a sampled token. During each refinement step, a
1300
+ sampled token is only kept if its probability is above this threshold. If not enough tokens meet the
1301
+ threshold, the ones with the highest confidence are chosen.
1302
+ editing_threshold (`float`, *optional*, defaults to 0.5):
1303
+ The confidence threshold for **editing**. Existing tokens (non-masked) are replaced by newly
1304
+ sampled tokens if the model's confidence in the new token exceeds this threshold and the token has changed.
1305
+ max_post_steps (`int`, *optional*, defaults to 16):
1306
+ Number of global refinement iterations after all mask tokens are resolved.
1307
+ eos_id (`int`, *optional*, defaults to 156892):
1308
+ The token ID for the end-of-sequence token. Used for `eos_early_stop`.
1309
+ mask_id (`int`, *optional*, defaults to 156895):
1310
+ The token ID used as a placeholder for tokens that are yet to be generated. This is central to the
1311
+ iterative refinement algorithm.
1312
+ Return:
1313
+ `torch.Tensor`: A string containing the generated token IDs, starting
1314
+ after the prompt and stopping at the first `eos_id` or `gen_length`.
1315
+ """
1316
+
1317
+ steps = min(steps, gen_length // minimal_topk)
1318
+ input_ids = inputs.to(self.device)
1319
+
1320
+ prompt_length = input_ids.shape[1]
1321
+ num_blocks = (prompt_length + gen_length + block_length - 1) // block_length
1322
+ total_length = num_blocks * block_length
1323
+
1324
+ block_mask = torch.tril(torch.ones(num_blocks, num_blocks, device=self.device))
1325
+ block_diffusion_attention_mask = (
1326
+ block_mask.repeat_interleave(block_length, dim=0)
1327
+ .repeat_interleave(block_length, dim=1)
1328
+ .unsqueeze(0)
1329
+ .unsqueeze(0)
1330
+ ).to(torch.bfloat16)
1331
+
1332
+ position_ids = torch.arange(total_length, device=self.device).unsqueeze(0)
1333
+ x = torch.full((1, total_length), mask_id, dtype=torch.long, device=self.device)
1334
+ x[:, :prompt_length] = input_ids.clone()
1335
+
1336
+ prompt_index_full = torch.zeros_like(x, dtype=torch.bool)
1337
+ prompt_index_full[:, :prompt_length] = True
1338
+
1339
+ prefill_blocks = prompt_length // block_length
1340
+
1341
+ for num_block in range(prefill_blocks, num_blocks):
1342
+ current_window_end = (num_block + 1) * block_length
1343
+ cur_x = x[:, :current_window_end]
1344
+ cur_attn_mask = block_diffusion_attention_mask[
1345
+ :, :, :current_window_end, :current_window_end
1346
+ ]
1347
+ cur_position_ids = position_ids[:, :current_window_end]
1348
+
1349
+ block_start_pos = num_block * block_length
1350
+
1351
+ post_steps = 0
1352
+ while True:
1353
+ old_block_tokens = cur_x[:, -block_length:].clone()
1354
+ active_block_mask = cur_x[:, -block_length:] == mask_id
1355
+ if torch.any(active_block_mask) == False:
1356
+ post_steps += 1
1357
+ if post_steps > max_post_steps:
1358
+ break
1359
+ prompt_mask_in_block = torch.zeros(
1360
+ block_length, dtype=torch.bool, device=self.device
1361
+ )
1362
+ if block_start_pos < prompt_length:
1363
+ prompt_end_in_block = min(
1364
+ prompt_length - block_start_pos, block_length
1365
+ )
1366
+ prompt_mask_in_block[:prompt_end_in_block] = True
1367
+
1368
+ outputs = self.forward(
1369
+ cur_x,
1370
+ attention_mask=cur_attn_mask,
1371
+ position_ids=cur_position_ids,
1372
+ output_attentions=True,
1373
+ )
1374
+ logits = outputs.logits
1375
+
1376
+ active_logits = logits[:, -block_length:, :]
1377
+ x0, x0_p = self._sample_with_temperature_topk_topp(
1378
+ active_logits, temperature=temperature, top_k=top_k, top_p=top_p
1379
+ )
1380
+ mask_transfer_index = torch.zeros_like(x0, dtype=torch.bool)
1381
+ if active_block_mask.sum() > 0:
1382
+ mask_confidence = torch.where(active_block_mask, x0_p, -torch.inf)
1383
+ high_conf_mask = (
1384
+ mask_confidence[0] > threshold
1385
+ ) & active_block_mask[0]
1386
+ num_high_confidence = high_conf_mask.sum().item()
1387
+
1388
+ if num_high_confidence >= num_to_transfer:
1389
+ mask_transfer_index[0] = high_conf_mask
1390
+ else:
1391
+ num_available = active_block_mask.sum().item()
1392
+ if num_available > 0:
1393
+ _, idx = torch.topk(
1394
+ mask_confidence[0],
1395
+ k=min(num_to_transfer, num_available),
1396
+ )
1397
+ mask_transfer_index[0, idx] = True
1398
+
1399
+ editing_transfer_index = torch.zeros_like(x0, dtype=torch.bool)
1400
+ non_mask_positions = ~active_block_mask
1401
+ non_prompt_positions = ~prompt_mask_in_block
1402
+ editable_positions = non_mask_positions & non_prompt_positions[None, :]
1403
+ editing_confidence = torch.where(editable_positions, x0_p, -torch.inf)
1404
+ high_conf_editing = (
1405
+ editing_confidence[0] > editing_threshold
1406
+ ) & editable_positions[0]
1407
+
1408
+ token_changed = x0[0] != old_block_tokens[0]
1409
+ editing_transfer_index[0] = high_conf_editing & token_changed
1410
+ final_transfer_index = mask_transfer_index | editing_transfer_index
1411
+
1412
+ if final_transfer_index.any():
1413
+ cur_x[:, -block_length:][final_transfer_index] = x0[
1414
+ final_transfer_index
1415
+ ]
1416
+
1417
+ if active_block_mask.sum() == 0 and not editing_transfer_index.any():
1418
+ break
1419
+
1420
+ x[:, :current_window_end] = cur_x
1421
+ if eos_early_stop:
1422
+ generated_part = x[0, prompt_length:current_window_end]
1423
+ if (generated_part == mask_id).sum() == 0:
1424
+ eos_positions = (generated_part == eos_id).nonzero(as_tuple=True)[0]
1425
+ if len(eos_positions) > 0:
1426
+ break
1427
+
1428
+ generated_answer = x[:, : prompt_length + gen_length]
1429
+ mask_positions = (generated_answer[0][input_ids.shape[1] :] == eos_id).nonzero(
1430
+ as_tuple=True
1431
+ )[0]
1432
+ if len(mask_positions) > 0:
1433
+ first_mask_position = mask_positions[0].item()
1434
+ else:
1435
+ first_mask_position = gen_length
1436
+
1437
+ return generated_answer[
1438
+ :, input_ids.shape[1] : input_ids.shape[1] + first_mask_position + 1
1439
+ ]
special_tokens_map.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|startoftext|>",
3
+ "cls_token": "[CLS]",
4
+ "eos_token": "<|endoftext|>",
5
+ "gmask_token": "[gMASK]",
6
+ "pad_token": "<|endoftext|>",
7
+ "mask_token": "<|mask|>"
8
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:878eb900ea4a42da7e54bc18ad38352bec005bbfd81bdf76a5ecf1aad1093a6c
3
+ size 12205801
tokenizer_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|startoftext|>",
4
+ "clean_up_tokenization_spaces": false,
5
+ "cls_token": "[CLS]",
6
+ "eos_token": "<|endoftext|>",
7
+ "fast_tokenizer": true,
8
+ "gmask_token": "[gMASK]",
9
+ "is_local": true,
10
+ "local_files_only": false,
11
+ "mask_token": "<|mask|>",
12
+ "merges_file": null,
13
+ "model_max_length": 32768,
14
+ "model_specific_special_tokens": {
15
+ "gmask_token": "[gMASK]"
16
+ },
17
+ "pad_token": "<|endoftext|>",
18
+ "tokenizer_class": "TokenizersBackend"
19
+ }