Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- chat_template.jinja +103 -0
- config.json +48 -0
- configuration_glm4_shared_moe.py +236 -0
- generation_config.json +10 -0
- model-00001-of-00179.safetensors +3 -0
- model-00002-of-00179.safetensors +3 -0
- model-00003-of-00179.safetensors +3 -0
- model-00004-of-00179.safetensors +3 -0
- model-00005-of-00179.safetensors +3 -0
- model-00006-of-00179.safetensors +3 -0
- model-00007-of-00179.safetensors +3 -0
- model-00008-of-00179.safetensors +3 -0
- model-00009-of-00179.safetensors +3 -0
- model-00010-of-00179.safetensors +3 -0
- model-00011-of-00179.safetensors +3 -0
- model-00012-of-00179.safetensors +3 -0
- model-00013-of-00179.safetensors +3 -0
- model-00014-of-00179.safetensors +3 -0
- model-00015-of-00179.safetensors +3 -0
- model-00016-of-00179.safetensors +3 -0
- model-00017-of-00179.safetensors +3 -0
- model-00018-of-00179.safetensors +3 -0
- model-00019-of-00179.safetensors +3 -0
- model-00020-of-00179.safetensors +3 -0
- model-00021-of-00179.safetensors +3 -0
- model-00022-of-00179.safetensors +3 -0
- model-00023-of-00179.safetensors +3 -0
- model-00024-of-00179.safetensors +3 -0
- model-00025-of-00179.safetensors +3 -0
- model-00026-of-00179.safetensors +3 -0
- model-00027-of-00179.safetensors +3 -0
- model-00028-of-00179.safetensors +3 -0
- model-00029-of-00179.safetensors +3 -0
- model-00030-of-00179.safetensors +3 -0
- model-00031-of-00179.safetensors +3 -0
- model-00032-of-00179.safetensors +3 -0
- model-00033-of-00179.safetensors +3 -0
- model-00034-of-00179.safetensors +3 -0
- model-00035-of-00179.safetensors +3 -0
- model-00036-of-00179.safetensors +3 -0
- model-00037-of-00179.safetensors +3 -0
- model-00038-of-00179.safetensors +3 -0
- model-00039-of-00179.safetensors +3 -0
- model-00040-of-00179.safetensors +3 -0
- model-00041-of-00179.safetensors +3 -0
- model-00042-of-00179.safetensors +3 -0
- model-00043-of-00179.safetensors +3 -0
- model-00044-of-00179.safetensors +3 -0
- model-00045-of-00179.safetensors +3 -0
.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
|
chat_template.jinja
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[gMASK]<sop>
|
2 |
+
{%- if tools -%}
|
3 |
+
<|system|>
|
4 |
+
# Tools
|
5 |
+
|
6 |
+
You may call one or more functions to assist with the user query.
|
7 |
+
|
8 |
+
You are provided with function signatures within <tools></tools> XML tags:
|
9 |
+
<tools>
|
10 |
+
{% for tool in tools %}
|
11 |
+
{{ tool | tojson(ensure_ascii=False) }}
|
12 |
+
{% endfor %}
|
13 |
+
</tools>
|
14 |
+
|
15 |
+
For each function call, output the function name and arguments within the following XML format:
|
16 |
+
<tool_call>{function-name}
|
17 |
+
<arg_key>{arg-key-1}</arg_key>
|
18 |
+
<arg_value>{arg-value-1}</arg_value>
|
19 |
+
<arg_key>{arg-key-2}</arg_key>
|
20 |
+
<arg_value>{arg-value-2}</arg_value>
|
21 |
+
...
|
22 |
+
</tool_call>{%- endif -%}
|
23 |
+
{%- macro visible_text(content) -%}
|
24 |
+
{%- if content is string -%}
|
25 |
+
{{- content }}
|
26 |
+
{%- elif content is iterable and content is not mapping -%}
|
27 |
+
{%- for item in content -%}
|
28 |
+
{%- if item is mapping and item.type == 'text' -%}
|
29 |
+
{{- item.text }}
|
30 |
+
{%- elif item is string -%}
|
31 |
+
{{- item }}
|
32 |
+
{%- endif -%}
|
33 |
+
{%- endfor -%}
|
34 |
+
{%- else -%}
|
35 |
+
{{- content }}
|
36 |
+
{%- endif -%}
|
37 |
+
{%- endmacro -%}
|
38 |
+
{%- set ns = namespace(last_user_index=-1) %}
|
39 |
+
{%- for m in messages %}
|
40 |
+
{%- if m.role == 'user' %}
|
41 |
+
{% set ns.last_user_index = loop.index0 -%}
|
42 |
+
{%- endif %}
|
43 |
+
{%- endfor %}
|
44 |
+
{% for m in messages %}
|
45 |
+
{%- if m.role == 'user' -%}<|user|>
|
46 |
+
{{ visible_text(m.content) }}
|
47 |
+
{{- '/nothink' if (enable_thinking is defined and not enable_thinking and not visible_text(m.content).endswith("/nothink")) else '' -}}
|
48 |
+
{%- elif m.role == 'assistant' -%}
|
49 |
+
<|assistant|>
|
50 |
+
{%- set reasoning_content = '' %}
|
51 |
+
{%- set content = visible_text(m.content) %}
|
52 |
+
{%- if m.reasoning_content is string %}
|
53 |
+
{%- set reasoning_content = m.reasoning_content %}
|
54 |
+
{%- else %}
|
55 |
+
{%- if '</think>' in content %}
|
56 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
57 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
58 |
+
{%- endif %}
|
59 |
+
{%- endif %}
|
60 |
+
{%- if loop.index0 > ns.last_user_index and reasoning_content -%}
|
61 |
+
{{ '\n<think>' + reasoning_content.strip() + '</think>'}}
|
62 |
+
{%- else -%}
|
63 |
+
{{ '\n<think></think>' }}
|
64 |
+
{%- endif -%}
|
65 |
+
{%- if content.strip() -%}
|
66 |
+
{{ '\n' + content.strip() }}
|
67 |
+
{%- endif -%}
|
68 |
+
{% if m.tool_calls %}
|
69 |
+
{% for tc in m.tool_calls %}
|
70 |
+
{%- if tc.function %}
|
71 |
+
{%- set tc = tc.function %}
|
72 |
+
{%- endif %}
|
73 |
+
{{ '\n<tool_call>' + tc.name }}
|
74 |
+
{% set _args = tc.arguments %}
|
75 |
+
{% for k, v in _args.items() %}
|
76 |
+
<arg_key>{{ k }}</arg_key>
|
77 |
+
<arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>
|
78 |
+
{% endfor %}
|
79 |
+
</tool_call>{% endfor %}
|
80 |
+
{% endif %}
|
81 |
+
{%- elif m.role == 'tool' -%}
|
82 |
+
{%- if m.content is string -%}
|
83 |
+
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
84 |
+
{{- '<|observation|>' }}
|
85 |
+
{%- endif %}
|
86 |
+
{{- '\n<tool_response>\n' }}
|
87 |
+
{{- m.content }}
|
88 |
+
{{- '\n</tool_response>' }}
|
89 |
+
{%- else -%}
|
90 |
+
<|observation|>{% for tr in m.content %}
|
91 |
+
|
92 |
+
<tool_response>
|
93 |
+
{{ tr.output if tr.output is defined else tr }}
|
94 |
+
</tool_response>{% endfor -%}
|
95 |
+
{% endif -%}
|
96 |
+
{%- elif m.role == 'system' -%}
|
97 |
+
<|system|>
|
98 |
+
{{ visible_text(m.content) }}
|
99 |
+
{%- endif -%}
|
100 |
+
{%- endfor -%}
|
101 |
+
{%- if add_generation_prompt -%}
|
102 |
+
<|assistant|>{{- '\n<think></think>' if (enable_thinking is defined and not enable_thinking) else '' -}}
|
103 |
+
{%- endif -%}
|
config.json
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"Glm4SharedMoeForCausalLM"
|
4 |
+
],
|
5 |
+
"attention_bias": true,
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"auto_map": {
|
8 |
+
"AutoConfig": "configuration_glm4_shared_moe.Glm4SharedMoeConfig",
|
9 |
+
"AutoModel": "modeling_glm4_shared_moe.Glm4SharedMoeModel",
|
10 |
+
"AutoModelForCausalLM": "modeling_glm4_shared_moe.Glm4SharedMoeForCausalLM"
|
11 |
+
},
|
12 |
+
"eos_token_id": [
|
13 |
+
151329,
|
14 |
+
151336,
|
15 |
+
151338
|
16 |
+
],
|
17 |
+
"first_k_dense_replace": 3,
|
18 |
+
"head_dim": 128,
|
19 |
+
"hidden_act": "silu",
|
20 |
+
"hidden_size": 5120,
|
21 |
+
"initializer_range": 0.02,
|
22 |
+
"intermediate_size": 12288,
|
23 |
+
"max_position_embeddings": 131072,
|
24 |
+
"model_type": "glm4_shared_moe",
|
25 |
+
"moe_intermediate_size": 1536,
|
26 |
+
"n_group": 1,
|
27 |
+
"n_routed_experts": 160,
|
28 |
+
"n_shared_experts": 1,
|
29 |
+
"norm_topk_prob": true,
|
30 |
+
"num_attention_heads": 96,
|
31 |
+
"num_experts_per_tok": 8,
|
32 |
+
"num_hidden_layers": 92,
|
33 |
+
"num_key_value_heads": 8,
|
34 |
+
"num_nextn_predict_layers": 1,
|
35 |
+
"pad_token_id": 151329,
|
36 |
+
"partial_rotary_factor": 0.5,
|
37 |
+
"rms_norm_eps": 1e-05,
|
38 |
+
"rope_scaling": null,
|
39 |
+
"rope_theta": 1000000,
|
40 |
+
"routed_scaling_factor": 2.5,
|
41 |
+
"tie_word_embeddings": false,
|
42 |
+
"topk_group": 1,
|
43 |
+
"torch_dtype": "bfloat16",
|
44 |
+
"transformers_version": "4.55.2",
|
45 |
+
"use_cache": true,
|
46 |
+
"use_qk_norm": true,
|
47 |
+
"vocab_size": 151552
|
48 |
+
}
|
configuration_glm4_shared_moe.py
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2025 The ZhipuAI Inc. team and HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
from transformers.configuration_utils import PretrainedConfig
|
17 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
18 |
+
|
19 |
+
|
20 |
+
class Glm4SharedMoeConfig(PretrainedConfig):
|
21 |
+
r"""
|
22 |
+
This is the configuration class to store the configuration of a [`Glm4MoeModel`]. It is used to instantiate a
|
23 |
+
Glm4Moe model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
24 |
+
with the defaults will yield a similar configuration to that of [THUDM/GLM-4-100B-A10B](https://huggingface.co/THUDM/GLM-4-100B-A10B).
|
25 |
+
|
26 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
27 |
+
documentation from [`PretrainedConfig`] for more information.
|
28 |
+
|
29 |
+
|
30 |
+
Args:
|
31 |
+
vocab_size (`int`, *optional*, defaults to 151552):
|
32 |
+
Vocabulary size of the Glm4Moe model. Defines the number of different tokens that can be represented by the
|
33 |
+
`inputs_ids` passed when calling [`Glm4MoeModel`]
|
34 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
35 |
+
Dimension of the hidden representations.
|
36 |
+
intermediate_size (`int`, *optional*, defaults to 10944):
|
37 |
+
Dimension of the MLP representations.
|
38 |
+
num_hidden_layers (`int`, *optional*, defaults to 46):
|
39 |
+
Number of hidden layers in the Transformer encoder.
|
40 |
+
num_attention_heads (`int`, *optional*, defaults to 96):
|
41 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
42 |
+
partial_rotary_factor (`float`, *optional*, defaults to 0.5):
|
43 |
+
The factor of the partial rotary position.
|
44 |
+
num_key_value_heads (`int`, *optional*, defaults to 8):
|
45 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
46 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
47 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
48 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
49 |
+
by meanpooling all the original heads within that group. For more details, check out [this
|
50 |
+
paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `32`.
|
51 |
+
|
52 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
53 |
+
The non-linear activation function (function or string) in the decoder.
|
54 |
+
max_position_embeddings (`int`, *optional*, defaults to 131072):
|
55 |
+
The maximum sequence length that this model might ever be used with.
|
56 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
57 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
58 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
59 |
+
The epsilon used by the rms normalization layers.
|
60 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
61 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
62 |
+
relevant if `config.is_decoder=True`.
|
63 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
64 |
+
Whether the model's input and output word embeddings should be tied.
|
65 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
66 |
+
The base period of the RoPE embeddings.
|
67 |
+
rope_scaling (`Dict`, *optional*):
|
68 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
69 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
70 |
+
accordingly.
|
71 |
+
Expected contents:
|
72 |
+
`rope_type` (`str`):
|
73 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
74 |
+
'llama3'], with 'default' being the original RoPE implementation.
|
75 |
+
`factor` (`float`, *optional*):
|
76 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
77 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
78 |
+
original maximum pre-trained length.
|
79 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
80 |
+
Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
|
81 |
+
pretraining.
|
82 |
+
`attention_factor` (`float`, *optional*):
|
83 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
84 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
85 |
+
`factor` field to infer the suggested value.
|
86 |
+
`beta_fast` (`float`, *optional*):
|
87 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
88 |
+
ramp function. If unspecified, it defaults to 32.
|
89 |
+
`beta_slow` (`float`, *optional*):
|
90 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
91 |
+
ramp function. If unspecified, it defaults to 1.
|
92 |
+
`short_factor` (`list[float]`, *optional*):
|
93 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
94 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
95 |
+
size divided by the number of attention heads divided by 2
|
96 |
+
`long_factor` (`list[float]`, *optional*):
|
97 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
98 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
99 |
+
size divided by the number of attention heads divided by 2
|
100 |
+
`low_freq_factor` (`float`, *optional*):
|
101 |
+
Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
|
102 |
+
`high_freq_factor` (`float`, *optional*):
|
103 |
+
Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
|
104 |
+
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
105 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
106 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
107 |
+
The dropout ratio for the attention probabilities.
|
108 |
+
moe_intermediate_size (`int`, *optional*, defaults to 1408):
|
109 |
+
Intermediate size of the routed expert.
|
110 |
+
num_experts_per_tok (`int`, *optional*, defaults to 8):
|
111 |
+
number of experts per token.
|
112 |
+
n_shared_experts (`int`, *optional*, defaults to 1):
|
113 |
+
Number of shared experts.
|
114 |
+
n_routed_experts (`int`, *optional*, defaults to 128):
|
115 |
+
Number of routed experts.
|
116 |
+
routed_scaling_factor (`float`, *optional*, defaults to 1.0):
|
117 |
+
Scaling factor or routed experts.
|
118 |
+
n_group (`int`, *optional*, defaults to 1):
|
119 |
+
Number of groups for routed experts.
|
120 |
+
topk_group (`int`, *optional*, defaults to 1):
|
121 |
+
Number of selected groups for each token(for each token, ensuring the selected experts is only within `topk_group` groups).
|
122 |
+
first_k_dense_replace (`int`, *optional*, defaults to 1):
|
123 |
+
Number of dense layers in shallow layers(embed->dense->dense->...->dense->moe->moe...->lm_head).
|
124 |
+
\--k dense layers--/
|
125 |
+
norm_topk_prob (`bool`, *optional*, defaults to `True`):
|
126 |
+
Whether to normalize the topk probabilities.
|
127 |
+
use_qk_norm (`bool`, *optional*, defaults to `False`):
|
128 |
+
Whether to use query-key normalization in the attention
|
129 |
+
```python
|
130 |
+
>>> from transformers import Glm4MoeModel, Glm4MoeConfig
|
131 |
+
|
132 |
+
>>> # Initializing a Glm4Moe style configuration
|
133 |
+
>>> configuration = Glm4MoeConfig()
|
134 |
+
|
135 |
+
>>> # Initializing a model from the GLM-4-MOE-100B-A10B style configuration
|
136 |
+
>>> model = Glm4MoeModel(configuration)
|
137 |
+
|
138 |
+
>>> # Accessing the model configuration
|
139 |
+
>>> configuration = model.config
|
140 |
+
```"""
|
141 |
+
|
142 |
+
model_type = "glm4_shared_moe"
|
143 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
144 |
+
|
145 |
+
# Default tensor parallel plan for base model `Glm4Moe`
|
146 |
+
base_model_tp_plan = {
|
147 |
+
"layers.*.self_attn.q_proj": "colwise",
|
148 |
+
"layers.*.self_attn.k_proj": "colwise",
|
149 |
+
"layers.*.self_attn.v_proj": "colwise",
|
150 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
151 |
+
"layers.*.mlp.experts.*.gate_proj": "colwise",
|
152 |
+
"layers.*.mlp.experts.*.up_proj": "colwise",
|
153 |
+
"layers.*.mlp.experts.*.down_proj": "rowwise",
|
154 |
+
"layers.*.mlp.gate_proj": "colwise",
|
155 |
+
"layers.*.mlp.up_proj": "colwise",
|
156 |
+
"layers.*.mlp.down_proj": "rowwise",
|
157 |
+
}
|
158 |
+
base_model_pp_plan = {
|
159 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
160 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
161 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
162 |
+
}
|
163 |
+
|
164 |
+
def __init__(
|
165 |
+
self,
|
166 |
+
vocab_size=151552,
|
167 |
+
hidden_size=4096,
|
168 |
+
intermediate_size=10944,
|
169 |
+
num_hidden_layers=46,
|
170 |
+
num_attention_heads=96,
|
171 |
+
partial_rotary_factor=0.5,
|
172 |
+
num_key_value_heads=8,
|
173 |
+
hidden_act="silu",
|
174 |
+
max_position_embeddings=131072,
|
175 |
+
initializer_range=0.02,
|
176 |
+
rms_norm_eps=1e-5,
|
177 |
+
use_cache=True,
|
178 |
+
tie_word_embeddings=False,
|
179 |
+
rope_theta=10000.0,
|
180 |
+
rope_scaling=None,
|
181 |
+
attention_bias=False,
|
182 |
+
attention_dropout=0.0,
|
183 |
+
moe_intermediate_size=1408,
|
184 |
+
num_experts_per_tok=8,
|
185 |
+
n_shared_experts=1,
|
186 |
+
n_routed_experts=128,
|
187 |
+
routed_scaling_factor=1.0,
|
188 |
+
n_group=1,
|
189 |
+
topk_group=1,
|
190 |
+
first_k_dense_replace=1,
|
191 |
+
norm_topk_prob=True,
|
192 |
+
use_qk_norm=False,
|
193 |
+
**kwargs,
|
194 |
+
):
|
195 |
+
self.vocab_size = vocab_size
|
196 |
+
self.max_position_embeddings = max_position_embeddings
|
197 |
+
self.hidden_size = hidden_size
|
198 |
+
self.intermediate_size = intermediate_size
|
199 |
+
self.num_hidden_layers = num_hidden_layers
|
200 |
+
self.num_attention_heads = num_attention_heads
|
201 |
+
self.partial_rotary_factor = partial_rotary_factor
|
202 |
+
|
203 |
+
self.num_key_value_heads = num_key_value_heads
|
204 |
+
self.hidden_act = hidden_act
|
205 |
+
self.initializer_range = initializer_range
|
206 |
+
self.rms_norm_eps = rms_norm_eps
|
207 |
+
self.use_cache = use_cache
|
208 |
+
self.rope_theta = rope_theta
|
209 |
+
self.rope_scaling = rope_scaling
|
210 |
+
self.attention_bias = attention_bias
|
211 |
+
self.attention_dropout = attention_dropout
|
212 |
+
# Validate the correctness of rotary position embeddings parameters
|
213 |
+
# BC: if there is a 'type' field, move it to 'rope_type'.
|
214 |
+
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
215 |
+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
216 |
+
rope_config_validation(self)
|
217 |
+
|
218 |
+
# MoE arguments
|
219 |
+
self.moe_intermediate_size = moe_intermediate_size
|
220 |
+
self.num_experts_per_tok = num_experts_per_tok
|
221 |
+
self.n_group = n_group
|
222 |
+
self.topk_group = topk_group
|
223 |
+
self.n_shared_experts = n_shared_experts
|
224 |
+
self.n_routed_experts = n_routed_experts
|
225 |
+
self.routed_scaling_factor = routed_scaling_factor
|
226 |
+
self.first_k_dense_replace = first_k_dense_replace
|
227 |
+
self.norm_topk_prob = norm_topk_prob
|
228 |
+
self.use_qk_norm = use_qk_norm
|
229 |
+
|
230 |
+
super().__init__(
|
231 |
+
tie_word_embeddings=tie_word_embeddings,
|
232 |
+
**kwargs,
|
233 |
+
)
|
234 |
+
|
235 |
+
|
236 |
+
__all__ = ["Glm4SharedMoeConfig"]
|
generation_config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"eos_token_id": [
|
4 |
+
151329,
|
5 |
+
151336,
|
6 |
+
151338
|
7 |
+
],
|
8 |
+
"pad_token_id": 151329,
|
9 |
+
"transformers_version": "4.55.2"
|
10 |
+
}
|
model-00001-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:342c1f2d267f073e34ebbf09b7aba09266b874fa762995d0b393e0550c851e97
|
3 |
+
size 5033164960
|
model-00002-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d34e655aef934f37bce12187fb973d90d655a6f135eddbf71e3d503d22f8bef
|
3 |
+
size 3775057728
|
model-00003-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f48b6aa05cb17f13981845f088c8e2e6b6daa89e345078cf30fbb5905e5b2456
|
3 |
+
size 5033164960
|
model-00004-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b5b44902125fa0294aaa35905832ac4decbaa116898133c80e9b1f87caa1c3ad
|
3 |
+
size 2838088784
|
model-00005-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d78d534b34a2ef488302e9b91e6f8cdc6e2f96dcb3b2dfd050ddf7d3e587a9c
|
3 |
+
size 5033164960
|
model-00006-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0a28a0a80c918b089ae5e4873102d97682d90c779f39c9fdbf8433c3f8991e88
|
3 |
+
size 2838088784
|
model-00007-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f48963fecb1cded9bd1023247a6b48551885bc50853af9a1f0e6ea91b59597e3
|
3 |
+
size 5033164960
|
model-00008-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8c85509b5f3bdf6993d933b6304d0b0c94fc7ddc9d27655f59fcd95e8a5241fc
|
3 |
+
size 2838088784
|
model-00009-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a4ad233d52314a4c8b254a1c4147029c46fc027bc337c82e69f8affa6b4a931f
|
3 |
+
size 5033164960
|
model-00010-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d18544ef286c16b2e4a48d1a6ec19f98629b7e081cb50097d7911f1221440d14
|
3 |
+
size 2838088784
|
model-00011-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:def92abe9e6b8476a1ecf925d31667ca88b0380d3c4f346c1d3dfbbebc17a6c3
|
3 |
+
size 5033164960
|
model-00012-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b9acfd8bbb947385c869106c35979e6a4836130586a80c3cb56450da79d25490
|
3 |
+
size 2838088784
|
model-00013-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a906b5acd2be14b538376d409b41985a5622afd4721b164b66df788d56c5d4b6
|
3 |
+
size 5033164960
|
model-00014-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9d2acf8f5ff4906da6ed1fe151b40245402fce23391aee75a2b5c222b1367a95
|
3 |
+
size 2838088784
|
model-00015-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e96ff7e7d03e4eed163c41fb8150ce7d8f246893bd17d1130b8569a6f1fe733d
|
3 |
+
size 5033164960
|
model-00016-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b6a00e5528cbed1ec503c948a5c7e23ab78e04a05f0c8be211654bb5568cc9e4
|
3 |
+
size 2838088768
|
model-00017-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6a52b193546cacdd4aee9305b94f3aeabc0555997840afaf4e94ca8d0f388333
|
3 |
+
size 5033164960
|
model-00018-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:42f13a6bca1095ab22bc9ee7f93355f7bf5dc5a1b759ff1c9019a7152d82a406
|
3 |
+
size 2838088800
|
model-00019-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a05b71e3293d5295f65a04ee45e6651d42dad82b6c483455c818834c117d8a4c
|
3 |
+
size 5033164960
|
model-00020-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2851d8eecfc487e90f83edf3ead87cb516eee5a605e8934995c432657126ab34
|
3 |
+
size 2838088800
|
model-00021-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:09a10f3b0533a607eda2505d0746da51ad5d7c22a01c5da483bdd0964acdc1c1
|
3 |
+
size 5033164960
|
model-00022-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3bdfcbc2894acc38ea7d1de7caa6bbdb69e7536ad53e21f5f54925090c8093e
|
3 |
+
size 2838088800
|
model-00023-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bd4b52077979cc5e7c9f2cadfd97ddc96e524bbc587e81a4ee3952ce88b1bee7
|
3 |
+
size 5033164960
|
model-00024-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:717dc4b7873bb50dd157c50ab9342919b465db35d8a5257f49565d74d76d7476
|
3 |
+
size 2838088800
|
model-00025-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7de8206df555915203d5482c5cd3dec81024710f8a5444df1ff5d0cc4e1a2d68
|
3 |
+
size 5033164960
|
model-00026-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:71a355a140b2be0deb38c80c6fc6cf70b2e546af709b42cc6d30c311c4bb657b
|
3 |
+
size 2838088800
|
model-00027-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b2c835ff3acf37e41e609f10f1b79cb4d97b0847c956bc41aae3009f208bb02f
|
3 |
+
size 5033164960
|
model-00028-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c92f61a7dc39a9e54361daa9fd96cc6edc87cf079b28f410f9a90c3fc361a852
|
3 |
+
size 2838088800
|
model-00029-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aeec0f43399352e8266f80fcc295f80dd10f8eab73682cc711b002c78193df5b
|
3 |
+
size 5033164960
|
model-00030-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:55aabbc5ed5fc460a60d7d37588381ea99e74a371ad15b685d253986725f69e1
|
3 |
+
size 2838088800
|
model-00031-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:79e155356a500bbdfaf1790305ca471e31a9ab9d4ece9b2c6b50158d47d67797
|
3 |
+
size 5033164960
|
model-00032-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:98732295e88022f13a42698b347e1a254fd6791d838bf1a4229506163486490d
|
3 |
+
size 2838088800
|
model-00033-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:41b53f771c9351a628502f635d20c08725734758ab06703da6991b065e3576ac
|
3 |
+
size 5033164960
|
model-00034-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c43103ebd7877d8752ac42c585712904d19ecdb74b7ee363f4f9dbbfdc957388
|
3 |
+
size 2838088800
|
model-00035-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0f3fc22f152ca7393ef6d45e25052638baf0fda4134eec342ace8a6a65de8cb8
|
3 |
+
size 5033164960
|
model-00036-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:57c1de44fe42779ddf79a2a24ca91373610a7a8e6ab96527d00f13ddf95657a1
|
3 |
+
size 2838088800
|
model-00037-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4f2801226d0fc28026e053e0aea3c2dc2c199c0aad15528f9a5c37762cbaa95a
|
3 |
+
size 5033164960
|
model-00038-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:28be52e6665fb5fd9913bffa54ad4b8af05a4cb503fdc076a29eacd25979faad
|
3 |
+
size 2838088800
|
model-00039-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1c2cbb9f9cddd9e22b284ee670f58510809b0be528a3e709b9b65cef4a23b0c2
|
3 |
+
size 5033164960
|
model-00040-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ccd9031b29a6c7f320369203728eda17b9a8f706f03cde60a31ffcbacc73e8f9
|
3 |
+
size 2838088800
|
model-00041-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d339c1177b1ee3e609f2537cf86e71f7499f06c0a1846c7a821c3ccc50fe6500
|
3 |
+
size 5033164960
|
model-00042-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b157d807302adc3b82e71703a143885af70c6e66b8dc2c752d772714a2adaad8
|
3 |
+
size 2838088800
|
model-00043-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1ff5e89421ec82f7fff115eea0c8b21209d28dc0e8b04356254ef3a99f2ad766
|
3 |
+
size 5033164960
|
model-00044-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:582cd7cbf32daba2d55cc1d50811c8c56f229eac0745503fa5291fbf75a6010c
|
3 |
+
size 2838088800
|
model-00045-of-00179.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f16a2a6936976c2b95409a8829f9ccab45057f142bac0c184c66ceb4e50b69f9
|
3 |
+
size 5033164960
|