Auraithm commited on
Commit
a1dec5b
·
verified ·
1 Parent(s): 6f7fb93

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,3 +1,98 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ license: apache-2.0
6
+ tags:
7
+ - math
8
+ - reasoning
9
+ - diffusion
10
+ base_model: JetLM/SDAR-8B-Chat
11
+ model_type: sdar
12
+ ---
13
+
14
+ <h1 align="center">DiRL-8B-Instruct</h1>
15
+
16
+ <p align="center">
17
+ <a href="https://github.com/OpenMOSS/DiRL">💻Github Repo</a>
18
+ </p>
19
+
20
+ ## Introduction
21
+
22
+ **DiRL-8B-Instruct** is an 8B parameter diffusion language model specialized for mathematical reasoning. It is trained using the [DiRL](https://github.com/OpenMOSS/DiRL) framework based on [SDAR-8B-Chat](https://huggingface.co/JetLM/SDAR-8B-Chat). Through two-stage training (SFT + RL), DiRL-8B-Instruct achieves state-of-the-art results at the 8B scale on mathematical reasoning benchmarks, even outperforming 32B models on most tasks.
23
+
24
+ > **Highlights**
25
+ >
26
+ > * **SOTA Performance:** Achieves **83.05%** on MATH500, **20.63%** on AIME2024, and **20.83%** on AIME2025, surpassing all 8B baselines.
27
+ > * **Training Framework:** Trained with [DiRL](https://github.com/OpenMOSS/DiRL), an efficient training framework for diffusion language models.
28
+ > * **Strong Baseline:** Built on [SDAR-8B-Chat](https://huggingface.co/JetLM/SDAR-8B-Chat), gaining **+11.20%** on MATH500 and **+11.46%** on AIME2024.
29
+
30
+ ## Inference
31
+
32
+ ### Using LMDeploy
33
+
34
+ ```python
35
+ from lmdeploy import pipeline, PytorchEngineConfig, GenerationConfig
36
+ from transformers import AutoTokenizer
37
+
38
+ model_path = "OpenMOSS-Team/DiRL-8B-Instruct"
39
+
40
+ # Load tokenizer
41
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
42
+
43
+ # Prepare prompts
44
+ prompts = [
45
+ [{"role": "user", "content": "Solve: If x + 5 = 12, what is x?"}],
46
+ ]
47
+ prompts = tokenizer.apply_chat_template(prompts, tokenize=False, add_generation_prompt=True)
48
+
49
+ # Configure backend for DLLM inference
50
+ backend_config = PytorchEngineConfig(
51
+ dtype="float16",
52
+ max_prefill_token_num=8192,
53
+ cache_max_entry_count=0.8,
54
+ dllm_block_length=4,
55
+ dllm_denoising_steps=4,
56
+ dllm_unmasking_strategy="low_confidence_dynamic",
57
+ dllm_confidence_threshold=0.9,
58
+ )
59
+
60
+ # Create inference pipeline
61
+ with pipeline(model_path, backend_config=backend_config) as pipe:
62
+ gen_config = GenerationConfig(
63
+ top_p=1.0,
64
+ top_k=50,
65
+ temperature=1.0,
66
+ do_sample=False, # greedy decoding
67
+ max_new_tokens=8192,
68
+ )
69
+
70
+ outputs = pipe(prompts, gen_config=gen_config)
71
+
72
+ for output in outputs:
73
+ print(output.text)
74
+ ```
75
+
76
+ ## Performance
77
+
78
+ | Model | MATH500 | GSM8K | AIME2024 | AIME2025 | OlympiadBench | Average |
79
+ |-------|---------|-------|----------|----------|---------------|---------|
80
+ | Qwen2.5-7B-Instruct | 73.78 | 89.78 | 8.96 | 5.63 | 36.58 | 42.95 |
81
+ | Qwen2.5-32B-Instruct | 81.13 | **94.03** | 12.92 | 11.88 | 45.65 | 49.12 |
82
+ | SDAR-8B-Chat | 71.85 | 89.87 | 9.17 | 9.38 | 36.03 | 43.26 |
83
+ | Trado-8B-Instruct | 75.59 | 91.06 | 11.67 | 15.00 | 40.32 | 46.73 |
84
+ | **DiRL-8B-Instruct** | **83.05** | 93.03 | **20.63** | **20.83** | **46.40** | **52.79** |
85
+
86
+ ## Citation
87
+
88
+ If you use this model in your research, please cite:
89
+
90
+ ```bibtex
91
+ @misc{zhu2025dirl,
92
+ title={DiRL: An Efficient Training Framework for Diffusion Language Models},
93
+ author={Zhu, Ying and Wan, Jiaxin and Liang, Tianyi and Guo, Xu and Liu, Xiaoran and Huang, Zengfeng and He, Ziwei and Qiu, Xipeng},
94
+ year={2025},
95
+ institution={Fudan University, Shanghai Innovation Institute},
96
+ url={https://github.com/OpenMOSS/DiRL}
97
+ }
98
+ ```
added_tokens.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|MASK|>": 151669,
9
+ "<|box_end|>": 151649,
10
+ "<|box_start|>": 151648,
11
+ "<|endoftext|>": 151643,
12
+ "<|file_sep|>": 151664,
13
+ "<|fim_middle|>": 151660,
14
+ "<|fim_pad|>": 151662,
15
+ "<|fim_prefix|>": 151659,
16
+ "<|fim_suffix|>": 151661,
17
+ "<|im_end|>": 151645,
18
+ "<|im_start|>": 151644,
19
+ "<|image_pad|>": 151655,
20
+ "<|object_ref_end|>": 151647,
21
+ "<|object_ref_start|>": 151646,
22
+ "<|quad_end|>": 151651,
23
+ "<|quad_start|>": 151650,
24
+ "<|repo_name|>": 151663,
25
+ "<|video_pad|>": 151656,
26
+ "<|vision_end|>": 151653,
27
+ "<|vision_pad|>": 151654,
28
+ "<|vision_start|>": 151652
29
+ }
chat_template.jinja ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# 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>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\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><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
27
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
28
+ {%- elif message.role == "assistant" %}
29
+ {%- set content = message.content %}
30
+ {%- set reasoning_content = '' %}
31
+ {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
32
+ {%- set reasoning_content = message.reasoning_content %}
33
+ {%- else %}
34
+ {%- if '</think>' in message.content %}
35
+ {%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
36
+ {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
37
+ {%- endif %}
38
+ {%- endif %}
39
+ {%- if loop.index0 > ns.last_query_index %}
40
+ {%- if loop.last or (not loop.last and reasoning_content) %}
41
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
42
+ {%- else %}
43
+ {{- '<|im_start|>' + message.role + '\n' + content }}
44
+ {%- endif %}
45
+ {%- else %}
46
+ {{- '<|im_start|>' + message.role + '\n' + content }}
47
+ {%- endif %}
48
+ {%- if message.tool_calls %}
49
+ {%- for tool_call in message.tool_calls %}
50
+ {%- if (loop.first and content) or (not loop.first) %}
51
+ {{- '\n' }}
52
+ {%- endif %}
53
+ {%- if tool_call.function %}
54
+ {%- set tool_call = tool_call.function %}
55
+ {%- endif %}
56
+ {{- '<tool_call>\n{"name": "' }}
57
+ {{- tool_call.name }}
58
+ {{- '", "arguments": ' }}
59
+ {%- if tool_call.arguments is string %}
60
+ {{- tool_call.arguments }}
61
+ {%- else %}
62
+ {{- tool_call.arguments | tojson }}
63
+ {%- endif %}
64
+ {{- '}\n</tool_call>' }}
65
+ {%- endfor %}
66
+ {%- endif %}
67
+ {{- '<|im_end|>\n' }}
68
+ {%- elif message.role == "tool" %}
69
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
70
+ {{- '<|im_start|>user' }}
71
+ {%- endif %}
72
+ {{- '\n<tool_response>\n' }}
73
+ {{- message.content }}
74
+ {{- '\n</tool_response>' }}
75
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
76
+ {{- '<|im_end|>\n' }}
77
+ {%- endif %}
78
+ {%- endif %}
79
+ {%- endfor %}
80
+ {%- if add_generation_prompt %}
81
+ {{- '<|im_start|>assistant\n' }}
82
+ {%- if enable_thinking is defined and enable_thinking is false %}
83
+ {{- '<think>\n\n</think>\n\n' }}
84
+ {%- endif %}
85
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SDARForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_sdar.SDARConfig",
9
+ "AutoModel": "modeling_sdar.SDARModel",
10
+ "AutoModelForCausalLM": "modeling_sdar.SDARForCausalLM",
11
+ "AutoTokenizer": "tokenization_qwen2.Qwen2Tokenizer"
12
+ },
13
+ "bos_token_id": 151643,
14
+ "debug": false,
15
+ "eos_token_id": 151643,
16
+ "ep_size": 1,
17
+ "fuse_cross_entropy": false,
18
+ "head_dim": 128,
19
+ "hidden_act": "silu",
20
+ "hidden_size": 4096,
21
+ "initializer_range": 0.02,
22
+ "intermediate_size": 12288,
23
+ "max_position_embeddings": 32768,
24
+ "max_window_layers": 36,
25
+ "micro_forward": false,
26
+ "model_type": "sdar",
27
+ "num_attention_heads": 32,
28
+ "num_hidden_layers": 36,
29
+ "num_key_value_heads": 8,
30
+ "rms_norm_eps": 1e-06,
31
+ "rope_scaling": null,
32
+ "rope_theta": 1000000,
33
+ "skip_checkpoint": false,
34
+ "sliding_window": null,
35
+ "tie_word_embeddings": false,
36
+ "torch_dtype": "bfloat16",
37
+ "transformers_version": "4.52.4",
38
+ "use_cache": false,
39
+ "use_deepep": false,
40
+ "use_sliding_window": false,
41
+ "vocab_size": 151936
42
+ }
configuration_sdar.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the 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
+ """SDAR model configuration"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.modeling_rope_utils import rope_config_validation
19
+ from transformers.utils import logging
20
+
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class SDARConfig(PretrainedConfig):
26
+ r"""
27
+ This is the configuration class to store the configuration of a [`SDARModel`]. It is used to instantiate a
28
+ SDAR model according to the specified arguments, defining the model architecture. Instantiating a configuration
29
+ with the defaults will yield a similar configuration to that of
30
+ SDAR-1.7B [DiffuOpen/SDAR-1.7B-Chat](https://huggingface.co/DiffuOpen/SDAR-1.7B-Chat/).
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+ Args:
34
+ vocab_size (`int`, *optional*, defaults to 151936):
35
+ Vocabulary size of the SDAR model. Defines the number of different tokens that can be represented by the
36
+ `inputs_ids` passed when calling [`SDARModel`]
37
+ hidden_size (`int`, *optional*, defaults to 4096):
38
+ Dimension of the hidden representations.
39
+ intermediate_size (`int`, *optional*, defaults to 22016):
40
+ Dimension of the MLP representations.
41
+ num_hidden_layers (`int`, *optional*, defaults to 32):
42
+ Number of hidden layers in the Transformer encoder.
43
+ num_attention_heads (`int`, *optional*, defaults to 32):
44
+ Number of attention heads for each attention layer in the Transformer encoder.
45
+ num_key_value_heads (`int`, *optional*, defaults to 32):
46
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
47
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
48
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
49
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
50
+ by meanpooling all the original heads within that group. For more details checkout [this
51
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
52
+ head_dim (`int`, *optional*, defaults to 128):
53
+ The attention head dimension.
54
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
55
+ The non-linear activation function (function or string) in the decoder.
56
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
57
+ The maximum sequence length that this model might ever be used with.
58
+ initializer_range (`float`, *optional*, defaults to 0.02):
59
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
60
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
61
+ The epsilon used by the rms normalization layers.
62
+ use_cache (`bool`, *optional*, defaults to `True`):
63
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
64
+ relevant if `config.is_decoder=True`.
65
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
66
+ Whether the model's input and output word embeddings should be tied.
67
+ rope_theta (`float`, *optional*, defaults to 10000.0):
68
+ The base period of the RoPE embeddings.
69
+ rope_scaling (`Dict`, *optional*):
70
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
71
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
72
+ accordingly.
73
+ Expected contents:
74
+ `rope_type` (`str`):
75
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
76
+ 'llama3'], with 'default' being the original RoPE implementation.
77
+ `factor` (`float`, *optional*):
78
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
79
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
80
+ original maximum pre-trained length.
81
+ `original_max_position_embeddings` (`int`, *optional*):
82
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
83
+ pretraining.
84
+ `attention_factor` (`float`, *optional*):
85
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
86
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
87
+ `factor` field to infer the suggested value.
88
+ `beta_fast` (`float`, *optional*):
89
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
90
+ ramp function. If unspecified, it defaults to 32.
91
+ `beta_slow` (`float`, *optional*):
92
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
93
+ ramp function. If unspecified, it defaults to 1.
94
+ `short_factor` (`List[float]`, *optional*):
95
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
96
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
97
+ size divided by the number of attention heads divided by 2
98
+ `long_factor` (`List[float]`, *optional*):
99
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
100
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
101
+ size divided by the number of attention heads divided by 2
102
+ `low_freq_factor` (`float`, *optional*):
103
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
104
+ `high_freq_factor` (`float`, *optional*):
105
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
106
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
107
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
108
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
109
+ Whether to use sliding window attention.
110
+ sliding_window (`int`, *optional*, defaults to 4096):
111
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
112
+ max_window_layers (`int`, *optional*, defaults to 28):
113
+ The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
114
+ attention_dropout (`float`, *optional*, defaults to 0.0):
115
+ The dropout ratio for the attention probabilities.
116
+ ```python
117
+ >>> from transformers import SDARModel, SDARConfig
118
+ >>> # Initializing a SDAR style configuration
119
+ >>> configuration = SDARConfig()
120
+ >>> # Initializing a model from the SDAR-8B style configuration
121
+ >>> model = SDARModel(configuration)
122
+ >>> # Accessing the model configuration
123
+ >>> configuration = model.config
124
+ ```"""
125
+
126
+ model_type = "sdar"
127
+ keys_to_ignore_at_inference = ["past_key_values"]
128
+
129
+ # Default tensor parallel plan for base model `SDAR`
130
+ base_model_tp_plan = {
131
+ "layers.*.self_attn.q_proj": "colwise",
132
+ "layers.*.self_attn.k_proj": "colwise",
133
+ "layers.*.self_attn.v_proj": "colwise",
134
+ "layers.*.self_attn.o_proj": "rowwise",
135
+ "layers.*.mlp.gate_proj": "colwise",
136
+ "layers.*.mlp.up_proj": "colwise",
137
+ "layers.*.mlp.down_proj": "rowwise",
138
+ }
139
+ base_model_pp_plan = {
140
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
141
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
142
+ "norm": (["hidden_states"], ["hidden_states"]),
143
+ }
144
+
145
+ def __init__(
146
+ self,
147
+ vocab_size=151936,
148
+ hidden_size=4096,
149
+ intermediate_size=22016,
150
+ num_hidden_layers=32,
151
+ num_attention_heads=32,
152
+ num_key_value_heads=32,
153
+ head_dim=128,
154
+ hidden_act="silu",
155
+ max_position_embeddings=32768,
156
+ initializer_range=0.02,
157
+ rms_norm_eps=1e-6,
158
+ use_cache=True,
159
+ tie_word_embeddings=False,
160
+ rope_theta=10000.0,
161
+ rope_scaling=None,
162
+ attention_bias=False,
163
+ use_sliding_window=False,
164
+ sliding_window=4096,
165
+ max_window_layers=28,
166
+ attention_dropout=0.0,
167
+ **kwargs,
168
+ ):
169
+ self.vocab_size = vocab_size
170
+ self.max_position_embeddings = max_position_embeddings
171
+ self.hidden_size = hidden_size
172
+ self.intermediate_size = intermediate_size
173
+ self.num_hidden_layers = num_hidden_layers
174
+ self.num_attention_heads = num_attention_heads
175
+ self.use_sliding_window = use_sliding_window
176
+ self.sliding_window = sliding_window # we check `use_sliding_window` in the modeling code
177
+ self.max_window_layers = max_window_layers
178
+
179
+ # for backward compatibility
180
+ if num_key_value_heads is None:
181
+ num_key_value_heads = num_attention_heads
182
+
183
+ self.num_key_value_heads = num_key_value_heads
184
+ self.head_dim = head_dim
185
+ self.hidden_act = hidden_act
186
+ self.initializer_range = initializer_range
187
+ self.rms_norm_eps = rms_norm_eps
188
+ self.use_cache = use_cache
189
+ self.rope_theta = rope_theta
190
+ self.rope_scaling = rope_scaling
191
+ self.attention_bias = attention_bias
192
+ self.attention_dropout = attention_dropout
193
+ # Validate the correctness of rotary position embeddings parameters
194
+ # BC: if there is a 'type' field, move it to 'rope_type'.
195
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
196
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
197
+ rope_config_validation(self)
198
+
199
+ super().__init__(
200
+ tie_word_embeddings=tie_word_embeddings,
201
+ **kwargs,
202
+ )
203
+
204
+
205
+ __all__ = ["SDARConfig"]
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.52.4"
13
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a49e88249587a3c5ce452a6c91a1a99a09819a9b199cbccdcee66aa9d17de53e
3
+ size 4902257696
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0922a9f20ff7d6ca49e6e18a539b0d600a6a52bdb81c98d66ba87f6a1f91873c
3
+ size 4915960368
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8543bdce1981b15e302a87d8466c09fae242fc9cf593282d803a17e2c27010aa
3
+ size 4983068496
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:443cbc4cee8b45a42acec04e29fd4c242dc8a0ccfa0ed52fb5c5db3a7a914f78
3
+ size 1580230264
model.safetensors.index.json ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16381470720
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00004-of-00004.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
30
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
31
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
32
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
33
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
34
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
35
+ "model.layers.10.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
36
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
37
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.10.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
39
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
40
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
41
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
42
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
43
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
44
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.11.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.11.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
50
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
54
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
55
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
56
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.12.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
58
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.12.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
68
+ "model.layers.13.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.13.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.14.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.14.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.15.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.15.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.16.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.16.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
111
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.17.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.17.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.18.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.18.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
128
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00004.safetensors",
130
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
131
+ "model.layers.19.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.19.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
134
+ "model.layers.19.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.19.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
138
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
139
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
140
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
141
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
142
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
143
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
144
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
145
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
146
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
147
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
148
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
149
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
150
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
151
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00004.safetensors",
152
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
153
+ "model.layers.20.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
154
+ "model.layers.20.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
155
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
156
+ "model.layers.20.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
157
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
158
+ "model.layers.20.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
159
+ "model.layers.20.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
160
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
161
+ "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
162
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00004.safetensors",
163
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
164
+ "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
165
+ "model.layers.21.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
166
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
167
+ "model.layers.21.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
168
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
169
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
170
+ "model.layers.21.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
171
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
172
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
173
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
174
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
175
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
176
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
177
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
178
+ "model.layers.22.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
179
+ "model.layers.22.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
180
+ "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
181
+ "model.layers.22.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
182
+ "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
183
+ "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
184
+ "model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
185
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
186
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
187
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
188
+ "model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
189
+ "model.layers.23.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
190
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
191
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.23.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
193
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
195
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
198
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
200
+ "model.layers.24.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.24.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
204
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
207
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
209
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
210
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.25.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
212
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.25.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.26.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
224
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.26.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.27.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
236
+ "model.layers.27.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
237
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
239
+ "model.layers.28.input_layernorm.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.28.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.28.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.28.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.28.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
246
+ "model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.28.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
248
+ "model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.29.input_layernorm.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.29.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.29.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.29.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.29.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.29.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
260
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
262
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
263
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
264
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
265
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
266
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
267
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
268
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
269
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
270
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
271
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
272
+ "model.layers.30.input_layernorm.weight": "model-00003-of-00004.safetensors",
273
+ "model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
274
+ "model.layers.30.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
275
+ "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
276
+ "model.layers.30.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
277
+ "model.layers.30.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
278
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
279
+ "model.layers.30.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
280
+ "model.layers.30.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
281
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
282
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.31.input_layernorm.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.31.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.31.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.31.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
287
+ "model.layers.31.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
288
+ "model.layers.31.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
289
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
290
+ "model.layers.31.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
291
+ "model.layers.31.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
292
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
293
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
294
+ "model.layers.32.input_layernorm.weight": "model-00003-of-00004.safetensors",
295
+ "model.layers.32.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
296
+ "model.layers.32.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
297
+ "model.layers.32.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
298
+ "model.layers.32.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
299
+ "model.layers.32.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
300
+ "model.layers.32.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
301
+ "model.layers.32.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
302
+ "model.layers.32.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
303
+ "model.layers.32.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
304
+ "model.layers.32.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
305
+ "model.layers.33.input_layernorm.weight": "model-00003-of-00004.safetensors",
306
+ "model.layers.33.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
307
+ "model.layers.33.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
308
+ "model.layers.33.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
309
+ "model.layers.33.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
310
+ "model.layers.33.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
311
+ "model.layers.33.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
312
+ "model.layers.33.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
313
+ "model.layers.33.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
314
+ "model.layers.33.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
315
+ "model.layers.33.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
316
+ "model.layers.34.input_layernorm.weight": "model-00003-of-00004.safetensors",
317
+ "model.layers.34.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
318
+ "model.layers.34.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
319
+ "model.layers.34.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
320
+ "model.layers.34.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
321
+ "model.layers.34.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
322
+ "model.layers.34.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
323
+ "model.layers.34.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
324
+ "model.layers.34.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
325
+ "model.layers.34.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
326
+ "model.layers.34.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
327
+ "model.layers.35.input_layernorm.weight": "model-00004-of-00004.safetensors",
328
+ "model.layers.35.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
329
+ "model.layers.35.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
330
+ "model.layers.35.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
331
+ "model.layers.35.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
332
+ "model.layers.35.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
333
+ "model.layers.35.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
334
+ "model.layers.35.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
335
+ "model.layers.35.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
336
+ "model.layers.35.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
337
+ "model.layers.35.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
338
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
339
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
340
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
341
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
342
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
343
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
344
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
345
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
346
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
347
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
348
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
349
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
350
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
351
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
352
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
353
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
354
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
355
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
356
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
357
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
358
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
359
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
360
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
361
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
362
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
363
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
364
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
365
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
366
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
367
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
368
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
369
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
370
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
371
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
372
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
373
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
374
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
375
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
376
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
377
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
378
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
379
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
380
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
381
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
382
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00004.safetensors",
383
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
384
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
385
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
386
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
387
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
388
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
389
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
390
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
391
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
392
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
393
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
394
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
395
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
396
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
397
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
398
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
399
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
400
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
401
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
402
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
403
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
404
+ "model.norm.weight": "model-00004-of-00004.safetensors"
405
+ }
406
+ }
modeling_sdar.py ADDED
@@ -0,0 +1,923 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ print(f"--- I am EXECUTING modeling_sdar.py from location: {__file__} ---")
2
+ # This file is modified based on https://github.com/huggingface/transformers/blob/v4.52.4/src/transformers/models/qwen3/modeling_qwen3.py.
3
+ #
4
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
5
+ # This file was automatically generated from src/transformers/models/qwen3/modular_qwen3.py.
6
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
7
+ # the file from the modular. If any change should be done, please apply the change to the
8
+ # modular_qwen3.py file directly. One of our CI enforces this.
9
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
10
+ # coding=utf-8
11
+ # Copyright 2025 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
12
+ #
13
+ # Licensed under the Apache License, Version 2.0 (the "License");
14
+ # you may not use this file except in compliance with the License.
15
+ # You may obtain a copy of the License at
16
+ #
17
+ # http://www.apache.org/licenses/LICENSE-2.0
18
+ #
19
+ # Unless required by applicable law or agreed to in writing, software
20
+ # distributed under the License is distributed on an "AS IS" BASIS,
21
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ # See the License for the specific language governing permissions and
23
+ # limitations under the License.
24
+
25
+ from typing import Callable, Optional, Tuple, Union
26
+
27
+ import torch
28
+ from torch import nn
29
+
30
+ from transformers.activations import ACT2FN
31
+ from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
32
+ from transformers.generation import GenerationMixin
33
+ from transformers.integrations import use_kernel_forward_from_hub
34
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
35
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
36
+ from transformers.modeling_layers import GradientCheckpointingLayer
37
+ from transformers.modeling_outputs import (
38
+ BaseModelOutputWithPast,
39
+ CausalLMOutputWithPast,
40
+ QuestionAnsweringModelOutput,
41
+ SequenceClassifierOutputWithPast,
42
+ TokenClassifierOutput,
43
+ )
44
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
45
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
46
+ from transformers.processing_utils import Unpack
47
+ from transformers.utils import LossKwargs, auto_docstring, can_return_tuple, is_torch_flex_attn_available, logging
48
+ from .configuration_sdar import SDARConfig
49
+
50
+ from flash_attn.ops.triton.layer_norm import rms_norm_fn as flash_rms_norm
51
+
52
+ import torch.nn.functional as F
53
+ try:
54
+ from flash_attn import flash_attn_func, flash_attn_varlen_func
55
+ from flash_attn.bert_padding import index_first_axis, pad_input, unpad_input
56
+ except:
57
+ pass
58
+
59
+ try:
60
+ from liger_kernel.ops.swiglu import LigerSiLUMulFunction # noqa: F401
61
+ liger_kernel_is_available = True
62
+ except ImportError:
63
+ liger_kernel_is_available = False
64
+
65
+
66
+ if is_torch_flex_attn_available():
67
+ from torch.nn.attention.flex_attention import BlockMask, create_block_mask, flex_attention
68
+ from transformers.integrations.flex_attention import make_flex_block_causal_mask
69
+
70
+
71
+ logger = logging.get_logger(__name__)
72
+
73
+
74
+ @use_kernel_forward_from_hub("RMSNorm")
75
+ class SDARRMSNorm(nn.Module):
76
+ def __init__(self, hidden_size, eps=1e-6):
77
+ """
78
+ SDARRMSNorm is equivalent to T5LayerNorm
79
+ """
80
+ super().__init__()
81
+ self.weight = nn.Parameter(torch.ones(hidden_size))
82
+ self.variance_epsilon = eps
83
+
84
+ def forward(self, hidden_states):
85
+ return flash_rms_norm(
86
+ hidden_states, weight=self.weight, bias=None, eps=self.variance_epsilon)
87
+ '''
88
+ input_dtype = hidden_states.dtype
89
+ hidden_states = hidden_states.to(torch.float32)
90
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
91
+ hidden_states = hidden_states * \
92
+ torch.rsqrt(variance + self.variance_epsilon)
93
+ return self.weight * hidden_states.to(input_dtype)
94
+ '''
95
+
96
+ def extra_repr(self):
97
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
98
+
99
+
100
+ class SDARMLP(nn.Module):
101
+ def __init__(self, config):
102
+ super().__init__()
103
+ self.config = config
104
+ self.hidden_size = config.hidden_size
105
+ self.intermediate_size = config.intermediate_size
106
+ self.gate_proj = nn.Linear(
107
+ self.hidden_size, self.intermediate_size, bias=False)
108
+ self.up_proj = nn.Linear(
109
+ self.hidden_size, self.intermediate_size, bias=False)
110
+ self.down_proj = nn.Linear(
111
+ self.intermediate_size, self.hidden_size, bias=False)
112
+ self.act_fn = ACT2FN[config.hidden_act]
113
+
114
+ def forward(self, x):
115
+ if liger_kernel_is_available:
116
+ return self.down_proj(LigerSiLUMulFunction.apply(self.gate_proj(x), self.up_proj(x)))
117
+ else:
118
+ down_proj = self.down_proj(self.act_fn(
119
+ self.gate_proj(x)) * self.up_proj(x))
120
+ return down_proj
121
+
122
+
123
+ def rotate_half(x):
124
+ """Rotates half the hidden dims of the input."""
125
+ x1 = x[..., : x.shape[-1] // 2]
126
+ x2 = x[..., x.shape[-1] // 2:]
127
+ return torch.cat((-x2, x1), dim=-1)
128
+
129
+
130
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
131
+ """Applies Rotary Position Embedding to the query and key tensors.
132
+ Args:
133
+ q (`torch.Tensor`): The query tensor.
134
+ k (`torch.Tensor`): The key tensor.
135
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
136
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
137
+ position_ids (`torch.Tensor`, *optional*):
138
+ Deprecated and unused.
139
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
140
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
141
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
142
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
143
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
144
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
145
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
146
+ Returns:
147
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
148
+ """
149
+ cos = cos.unsqueeze(unsqueeze_dim)
150
+ sin = sin.unsqueeze(unsqueeze_dim)
151
+ q_embed = (q * cos) + (rotate_half(q) * sin)
152
+ k_embed = (k * cos) + (rotate_half(k) * sin)
153
+ return q_embed, k_embed
154
+
155
+
156
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
157
+ """
158
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
159
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
160
+ """
161
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
162
+ if n_rep == 1:
163
+ return hidden_states
164
+ hidden_states = hidden_states[:, :, None, :, :].expand(
165
+ batch, num_key_value_heads, n_rep, slen, head_dim)
166
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
167
+
168
+
169
+ def eager_attention_forward(
170
+ module: nn.Module,
171
+ query: torch.Tensor,
172
+ key: torch.Tensor,
173
+ value: torch.Tensor,
174
+ attention_mask: Optional[torch.Tensor],
175
+ scaling: float,
176
+ dropout: float = 0.0,
177
+ **kwargs,
178
+ ):
179
+ key_states = repeat_kv(key, module.num_key_value_groups)
180
+ value_states = repeat_kv(value, module.num_key_value_groups)
181
+
182
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
183
+ if attention_mask is not None:
184
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
185
+ attn_weights = attn_weights + causal_mask
186
+
187
+ attn_weights = nn.functional.softmax(
188
+ attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
189
+ attn_weights = nn.functional.dropout(
190
+ attn_weights, p=dropout, training=module.training)
191
+ attn_output = torch.matmul(attn_weights, value_states)
192
+ attn_output = attn_output.transpose(1, 2).contiguous()
193
+
194
+ return attn_output, attn_weights
195
+
196
+
197
+ class SDARAttention(nn.Module):
198
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
199
+
200
+ def __init__(self, config: SDARConfig, layer_idx: int):
201
+ super().__init__()
202
+ self.config = config
203
+ self.layer_idx = layer_idx
204
+ self.head_dim = getattr(
205
+ config, "head_dim", config.hidden_size // config.num_attention_heads)
206
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
207
+ self.scaling = self.head_dim**-0.5
208
+ self.attention_dropout = config.attention_dropout
209
+ self.is_causal = True
210
+
211
+ self.hidden_size = config.hidden_size
212
+ self.num_attention_heads = config.num_attention_heads
213
+ self.num_key_value_heads = config.num_key_value_heads
214
+
215
+ self.q_proj = nn.Linear(
216
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
217
+ )
218
+ self.k_proj = nn.Linear(
219
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
220
+ )
221
+ self.v_proj = nn.Linear(
222
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
223
+ )
224
+ self.o_proj = nn.Linear(
225
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
226
+ )
227
+ # unlike olmo, only on the head dim!
228
+ self.q_norm = SDARRMSNorm(self.head_dim, eps=config.rms_norm_eps)
229
+ # thus post q_norm does not need reshape
230
+ self.k_norm = SDARRMSNorm(self.head_dim, eps=config.rms_norm_eps)
231
+ self.sliding_window = config.sliding_window
232
+ if not (
233
+ self.config.use_sliding_window
234
+ and getattr(self.config, "sliding_window", None) is not None
235
+ and self.layer_idx >= self.config.max_window_layers
236
+ ):
237
+ self.sliding_window = None
238
+
239
+ def forward(
240
+ self,
241
+ hidden_states: torch.Tensor,
242
+ position_embeddings: Tuple[torch.Tensor, torch.Tensor],
243
+ attention_mask: Optional[torch.Tensor],
244
+ past_key_value: Optional[Cache] = None,
245
+ cache_position: Optional[torch.LongTensor] = None,
246
+ **kwargs: Unpack[FlashAttentionKwargs],
247
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
248
+ input_shape = hidden_states.shape[:-1]
249
+ bsz, q_len = input_shape
250
+ hidden_shape = (*input_shape, -1, self.head_dim)
251
+
252
+ query_states = self.q_norm(self.q_proj(
253
+ hidden_states).view(hidden_shape)).transpose(1, 2)
254
+ key_states = self.k_norm(self.k_proj(
255
+ hidden_states).view(hidden_shape)).transpose(1, 2)
256
+ value_states = self.v_proj(hidden_states).view(
257
+ hidden_shape).transpose(1, 2)
258
+
259
+
260
+
261
+ cos, sin = position_embeddings
262
+ query_states, key_states = apply_rotary_pos_emb(
263
+ query_states, key_states, cos, sin)
264
+
265
+ if past_key_value is not None and kwargs.get("store_kv", False):
266
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
267
+ key_states, value_states = past_key_value.update(
268
+ key_states, value_states, self.layer_idx)
269
+ elif past_key_value is not None and not kwargs.get("store_kv", False) and len(past_key_value) > self.layer_idx:
270
+ # only retrive, do not store kv
271
+ past_key_states, past_value_states = past_key_value[self.layer_idx]
272
+ key_states = torch.cat(
273
+ [past_key_states, key_states], dim=-2)
274
+ value_states = torch.cat(
275
+ [past_value_states, value_states], dim=-2)
276
+
277
+ '''
278
+ attention_mask = attention_mask.bool() if attention_mask is not None else None
279
+ if torch.all(attention_mask): # decoding
280
+ query_states = query_states.transpose(1, 2)
281
+ key_states = key_states.transpose(1, 2)
282
+ value_states = value_states.transpose(1, 2)
283
+ attn_output = flash_attn_func(
284
+ query_states,
285
+ key_states,
286
+ value_states,
287
+ causal=False,
288
+ softmax_scale=self.scaling
289
+ )
290
+
291
+ else: # prefilling
292
+ attn_output = F.scaled_dot_product_attention(
293
+ query=query_states,
294
+ key=key_states,
295
+ value=value_states,
296
+ attn_mask=attention_mask,
297
+ is_causal=False,
298
+ scale=self.scaling,
299
+ enable_gqa=True
300
+ )
301
+ attn_output = attn_output.transpose(1, 2).contiguous()
302
+ '''
303
+
304
+ #print(query_states.shape, key_states.shape, value_states.shape)
305
+
306
+ # --- After RoPE and KV-cache handling, expand KV to all heads ---
307
+ key_states = repeat_kv(key_states, self.num_key_value_groups) # [B, H, K, D]
308
+ value_states = repeat_kv(value_states, self.num_key_value_groups) # [B, H, K, D]
309
+
310
+ # --- Convert a 0/1 or bool 4D mask into an *additive* mask, and align to [B, H, Q, K] ---
311
+ attn_mask = None
312
+ if attention_mask is not None:
313
+ k_len = key_states.shape[-2]
314
+ am = attention_mask
315
+ # Support either 2D [B, K] or 4D [B, 1/H, Q, K]
316
+ if am.dim() == 2:
317
+ am = am[:, None, None, :k_len] # -> [B,1,1,K]
318
+ else:
319
+ am = am[:, :, :, :k_len] # -> [B,1/H,Q,K]
320
+
321
+ finfo_min = torch.finfo(query_states.dtype).min
322
+ # 0/1 or bool -> float additive mask: 1->0, 0->-inf
323
+ if am.dtype == torch.bool:
324
+ zero = torch.zeros((), dtype=query_states.dtype, device=am.device)
325
+ neginf = torch.full((), finfo_min, dtype=query_states.dtype, device=am.device)
326
+ am = torch.where(am, zero, neginf)
327
+ else:
328
+ # For 0/1 float masks: values > 0 are treated as visible
329
+ am = am.to(query_states.dtype)
330
+ am = torch.where(am > 0, torch.zeros_like(am), torch.full_like(am, finfo_min))
331
+
332
+ # Expand to all heads
333
+ #if am.shape[1] == 1 and self.num_attention_heads > 1:
334
+ # am = am.expand(am.shape[0], self.num_attention_heads, am.shape[2], am.shape[3])
335
+
336
+ #attn_mask = am.contiguous()
337
+ attn_mask = am
338
+
339
+
340
+ bsz, q_len = input_shape
341
+
342
+ if q_len == 1 and past_key_value is not None:
343
+ # --- Decoding: flash-attn ---
344
+ q = query_states.transpose(1, 2) # [B,Q,H,D]
345
+ k = key_states.transpose(1, 2)
346
+ v = value_states.transpose(1, 2)
347
+ attn_output = flash_attn_func(
348
+ q, k, v,
349
+ causal=True, # For decoding, explicitly set causal=True
350
+ softmax_scale=self.scaling
351
+ )
352
+ attn_output = attn_output.transpose(1, 2).contiguous()
353
+ else:
354
+ attn_output = F.scaled_dot_product_attention(
355
+ query=query_states, # [B,H,Q,D]
356
+ key=key_states, # [B,H,K,D]
357
+ value=value_states, # [B,H,K,D]
358
+ attn_mask=attn_mask, # float additive mask
359
+ is_causal=False, # All constraints are already encoded in the mask
360
+ scale=self.scaling,
361
+ )
362
+ attn_output = attn_output.transpose(1, 2).contiguous() # -> [B,Q,H,D]
363
+
364
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
365
+ attn_output = self.o_proj(attn_output)
366
+ return attn_output, None # , attn_weights
367
+
368
+
369
+ class SDARDecoderLayer(GradientCheckpointingLayer):
370
+ def __init__(self, config: SDARConfig, layer_idx: int):
371
+ super().__init__()
372
+ self.hidden_size = config.hidden_size
373
+ self.self_attn = SDARAttention(config=config, layer_idx=layer_idx)
374
+ self.mlp = SDARMLP(config)
375
+ self.input_layernorm = SDARRMSNorm(
376
+ config.hidden_size, eps=config.rms_norm_eps)
377
+ self.post_attention_layernorm = SDARRMSNorm(
378
+ config.hidden_size, eps=config.rms_norm_eps)
379
+ if (
380
+ config.sliding_window and config._attn_implementation != "flash_attention_2"
381
+ ): # diff with Llama is this warning
382
+ logger.warning_once(
383
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
384
+ "unexpected results may be encountered."
385
+ )
386
+
387
+ def forward(
388
+ self,
389
+ hidden_states: torch.Tensor,
390
+ attention_mask: Optional[torch.Tensor] = None,
391
+ position_ids: Optional[torch.LongTensor] = None,
392
+ past_key_value: Optional[Cache] = None,
393
+ output_attentions: Optional[bool] = False,
394
+ use_cache: Optional[bool] = False,
395
+ store_kv: Optional[bool] = False,
396
+ cache_position: Optional[torch.LongTensor] = None,
397
+ # necessary, but kept here for BC
398
+ position_embeddings: Optional[Tuple[torch.Tensor,
399
+ torch.Tensor]] = None,
400
+ **kwargs: Unpack[FlashAttentionKwargs],
401
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
402
+ residual = hidden_states
403
+ hidden_states = self.input_layernorm(hidden_states)
404
+
405
+ # Self Attention
406
+ hidden_states, self_attn_weights = self.self_attn(
407
+ hidden_states=hidden_states,
408
+ attention_mask=attention_mask,
409
+ position_ids=position_ids,
410
+ past_key_value=past_key_value,
411
+ output_attentions=output_attentions,
412
+ use_cache=use_cache,
413
+ store_kv=store_kv,
414
+ cache_position=cache_position,
415
+ position_embeddings=position_embeddings,
416
+ **kwargs,
417
+ )
418
+ hidden_states = residual + hidden_states
419
+
420
+ # Fully Connected
421
+ residual = hidden_states
422
+ hidden_states = self.post_attention_layernorm(hidden_states)
423
+ hidden_states = self.mlp(hidden_states)
424
+ hidden_states = residual + hidden_states
425
+
426
+ outputs = (hidden_states,)
427
+ if output_attentions:
428
+ outputs += (self_attn_weights,)
429
+
430
+ return outputs
431
+
432
+
433
+ @auto_docstring
434
+ class SDARPreTrainedModel(PreTrainedModel):
435
+ config_class = SDARConfig
436
+ base_model_prefix = "model"
437
+ supports_gradient_checkpointing = True
438
+ _no_split_modules = ["SDARDecoderLayer"]
439
+ _skip_keys_device_placement = ["past_key_values"]
440
+ _supports_flash_attn_2 = True
441
+ _supports_sdpa = True
442
+ _supports_flex_attn = True
443
+ _supports_cache_class = True
444
+ _supports_quantized_cache = True
445
+ _supports_static_cache = True
446
+ _supports_attention_backend = True
447
+
448
+ def _init_weights(self, module):
449
+ std = self.config.initializer_range
450
+ if isinstance(module, nn.Linear):
451
+ module.weight.data.normal_(mean=0.0, std=std)
452
+ if module.bias is not None:
453
+ module.bias.data.zero_()
454
+ elif isinstance(module, nn.Embedding):
455
+ module.weight.data.normal_(mean=0.0, std=std)
456
+ if module.padding_idx is not None:
457
+ module.weight.data[module.padding_idx].zero_()
458
+ elif isinstance(module, SDARRMSNorm):
459
+ module.weight.data.fill_(1.0)
460
+
461
+
462
+ class SDARRotaryEmbedding(nn.Module):
463
+ def __init__(self, config: SDARConfig, device=None):
464
+ super().__init__()
465
+ # BC: "rope_type" was originally "type"
466
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
467
+ self.rope_type = config.rope_scaling.get(
468
+ "rope_type", config.rope_scaling.get("type"))
469
+ else:
470
+ self.rope_type = "default"
471
+ self.max_seq_len_cached = config.max_position_embeddings
472
+ self.original_max_seq_len = config.max_position_embeddings
473
+
474
+ self.config = config
475
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
476
+
477
+ inv_freq, self.attention_scaling = self.rope_init_fn(
478
+ self.config, device)
479
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
480
+ self.original_inv_freq = self.inv_freq
481
+
482
+ @torch.no_grad()
483
+ # power user: used with advanced RoPE types (e.g. dynamic rope)
484
+ @dynamic_rope_update
485
+ def forward(self, x, position_ids):
486
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(
487
+ position_ids.shape[0], -1, 1).to(x.device)
488
+ position_ids_expanded = position_ids[:, None, :].float()
489
+
490
+ device_type = x.device.type if isinstance(
491
+ x.device.type, str) and x.device.type != "mps" else "cpu"
492
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
493
+ freqs = (inv_freq_expanded.float() @
494
+ position_ids_expanded.float()).transpose(1, 2)
495
+ emb = torch.cat((freqs, freqs), dim=-1)
496
+ cos = emb.cos() * self.attention_scaling
497
+ sin = emb.sin() * self.attention_scaling
498
+
499
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
500
+
501
+
502
+ @auto_docstring
503
+ class SDARModel(SDARPreTrainedModel):
504
+ def __init__(self, config: SDARConfig):
505
+ super().__init__(config)
506
+ self.padding_idx = config.pad_token_id
507
+ self.vocab_size = config.vocab_size
508
+
509
+ self.embed_tokens = nn.Embedding(
510
+ config.vocab_size, config.hidden_size, self.padding_idx)
511
+ self.layers = nn.ModuleList(
512
+ [SDARDecoderLayer(config, layer_idx)
513
+ for layer_idx in range(config.num_hidden_layers)]
514
+ )
515
+ self.norm = SDARRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
516
+ self.rotary_emb = SDARRotaryEmbedding(config=config)
517
+ self.gradient_checkpointing = False
518
+
519
+ # Initialize weights and apply final processing
520
+ self.post_init()
521
+
522
+ def get_input_embeddings(self):
523
+ return self.embed_tokens
524
+
525
+ def set_input_embeddings(self, value):
526
+ self.embed_tokens = value
527
+
528
+ @can_return_tuple
529
+ @auto_docstring
530
+ def forward(
531
+ self,
532
+ input_ids: Optional[torch.LongTensor] = None,
533
+ attention_mask: Optional[torch.Tensor] = None,
534
+ position_ids: Optional[torch.LongTensor] = None,
535
+ past_key_values: Optional[Cache] = None,
536
+ inputs_embeds: Optional[torch.FloatTensor] = None,
537
+ use_cache: Optional[bool] = None,
538
+ store_kv: Optional[bool] = None,
539
+ output_attentions: Optional[bool] = None,
540
+ output_hidden_states: Optional[bool] = None,
541
+ cache_position: Optional[torch.LongTensor] = None,
542
+ **flash_attn_kwargs: Unpack[FlashAttentionKwargs],
543
+ ) -> BaseModelOutputWithPast:
544
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
545
+ output_hidden_states = (
546
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
547
+ )
548
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
549
+
550
+ if (input_ids is None) ^ (inputs_embeds is not None):
551
+ raise ValueError(
552
+ "You must specify exactly one of input_ids or inputs_embeds")
553
+
554
+ if self.gradient_checkpointing and self.training and use_cache:
555
+ logger.warning_once(
556
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
557
+ )
558
+ use_cache = False
559
+
560
+ # TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache
561
+ if not isinstance(past_key_values, (type(None), Cache)):
562
+ raise ValueError(
563
+ "The `past_key_values` should be either a `Cache` object or `None`.")
564
+
565
+ if inputs_embeds is None:
566
+ inputs_embeds = self.embed_tokens(input_ids)
567
+
568
+ if use_cache and past_key_values is None:
569
+ past_key_values = DynamicCache()
570
+
571
+ if cache_position is None:
572
+ past_seen_tokens = past_key_values.get_seq_length(
573
+ ) if past_key_values is not None else 0
574
+ cache_position = torch.arange(
575
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
576
+ )
577
+
578
+ if position_ids is None:
579
+ position_ids = cache_position.unsqueeze(0)
580
+
581
+ # causal_mask = self._update_causal_mask(
582
+ # attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
583
+ # )
584
+
585
+ hidden_states = inputs_embeds
586
+
587
+ # create position embeddings to be shared across the decoder layers
588
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
589
+
590
+ # decoder layers
591
+ all_hidden_states = () if output_hidden_states else None
592
+ all_self_attns = () if output_attentions else None
593
+
594
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
595
+ if output_hidden_states:
596
+ all_hidden_states += (hidden_states,)
597
+
598
+ layer_outputs = decoder_layer(
599
+ hidden_states,
600
+ attention_mask=attention_mask,
601
+ position_ids=position_ids,
602
+ past_key_value=past_key_values,
603
+ output_attentions=output_attentions,
604
+ use_cache=use_cache,
605
+ store_kv=store_kv,
606
+ cache_position=cache_position,
607
+ position_embeddings=position_embeddings,
608
+ **flash_attn_kwargs,
609
+ )
610
+
611
+ hidden_states = layer_outputs[0]
612
+
613
+ if output_attentions:
614
+ all_self_attns += (layer_outputs[1],)
615
+
616
+ hidden_states = self.norm(hidden_states)
617
+
618
+ # add hidden states from the last decoder layer
619
+ if output_hidden_states:
620
+ all_hidden_states += (hidden_states,)
621
+
622
+ return BaseModelOutputWithPast(
623
+ last_hidden_state=hidden_states,
624
+ past_key_values=past_key_values if use_cache else None,
625
+ hidden_states=all_hidden_states,
626
+ attentions=all_self_attns,
627
+ )
628
+
629
+ def _update_causal_mask(
630
+ self,
631
+ attention_mask: Union[torch.Tensor, "BlockMask"],
632
+ input_tensor: torch.Tensor,
633
+ cache_position: torch.Tensor,
634
+ past_key_values: Cache,
635
+ output_attentions: bool = False,
636
+ ):
637
+ if self.config._attn_implementation == "flash_attention_2":
638
+ if attention_mask is not None and past_key_values is not None:
639
+ is_padding_right = attention_mask[:, -
640
+ 1].sum().item() != input_tensor.size()[0]
641
+ if is_padding_right:
642
+ raise ValueError(
643
+ "You are attempting to perform batched generation with padding_side='right'"
644
+ " this may lead to unexpected behaviour for Flash Attention version of Qwen3. Make sure to "
645
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
646
+ )
647
+ if attention_mask is not None and 0.0 in attention_mask:
648
+ return attention_mask
649
+ return None
650
+ if self.config._attn_implementation == "flex_attention":
651
+ if isinstance(attention_mask, torch.Tensor):
652
+ seq_len_q, seq_len_kv = attention_mask.shape
653
+ assert seq_len_q == seq_len_kv, f"got {attention_mask.shape=}"
654
+ attention_mask = create_block_mask(
655
+ # 2d bool tensor, shape: [2*seqlen, 2*seqlen]
656
+ lambda b, h, q_idx, kv_idx: attention_mask[q_idx, kv_idx],
657
+ B=None, H=None, Q_LEN=seq_len_q, KV_LEN=seq_len_kv,
658
+ )
659
+ else:
660
+ # Here we pass in flex mask computed externally
661
+ assert isinstance(attention_mask, BlockMask)
662
+ return attention_mask
663
+
664
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
665
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
666
+ # to infer the attention mask.
667
+ past_seen_tokens = past_key_values.get_seq_length(
668
+ ) if past_key_values is not None else 0
669
+ using_static_cache = isinstance(past_key_values, StaticCache)
670
+ using_sliding_window_cache = isinstance(
671
+ past_key_values, SlidingWindowCache)
672
+
673
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
674
+ if (
675
+ self.config._attn_implementation == "sdpa"
676
+ and not (using_static_cache or using_sliding_window_cache)
677
+ and not output_attentions
678
+ ):
679
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
680
+ attention_mask,
681
+ inputs_embeds=input_tensor,
682
+ past_key_values_length=past_seen_tokens,
683
+ sliding_window=self.config.sliding_window,
684
+ is_training=self.training,
685
+ ):
686
+ return None
687
+
688
+ dtype = input_tensor.dtype
689
+ min_dtype = torch.finfo(dtype).min
690
+ sequence_length = input_tensor.shape[1]
691
+ # SlidingWindowCache or StaticCache
692
+ if using_sliding_window_cache or using_static_cache:
693
+ target_length = past_key_values.get_max_cache_shape()
694
+ # DynamicCache or no cache
695
+ else:
696
+ target_length = (
697
+ attention_mask.shape[-1]
698
+ if isinstance(attention_mask, torch.Tensor)
699
+ else past_seen_tokens + sequence_length + 1
700
+ )
701
+
702
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
703
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
704
+ attention_mask,
705
+ sequence_length=sequence_length,
706
+ target_length=target_length,
707
+ dtype=dtype,
708
+ cache_position=cache_position,
709
+ batch_size=input_tensor.shape[0],
710
+ config=self.config,
711
+ past_key_values=past_key_values,
712
+ )
713
+
714
+ if (
715
+ self.config._attn_implementation == "sdpa"
716
+ and attention_mask is not None
717
+ and attention_mask.device.type in ["cuda", "xpu", "npu"]
718
+ and not output_attentions
719
+ ):
720
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
721
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
722
+ # Details: https://github.com/pytorch/pytorch/issues/110213
723
+ causal_mask = AttentionMaskConverter._unmask_unattended(
724
+ causal_mask, min_dtype)
725
+
726
+ return causal_mask
727
+
728
+ @staticmethod
729
+ def _prepare_4d_causal_attention_mask_with_cache_position(
730
+ attention_mask: torch.Tensor,
731
+ sequence_length: int,
732
+ target_length: int,
733
+ dtype: torch.dtype,
734
+ cache_position: torch.Tensor,
735
+ batch_size: int,
736
+ config: SDARConfig,
737
+ past_key_values: Cache,
738
+ ):
739
+ """
740
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
741
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
742
+ Args:
743
+ attention_mask (`torch.Tensor`):
744
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
745
+ sequence_length (`int`):
746
+ The sequence length being processed.
747
+ target_length (`int`):
748
+ The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
749
+ dtype (`torch.dtype`):
750
+ The dtype to use for the 4D attention mask.
751
+ cache_position (`torch.Tensor`):
752
+ Indices depicting the position of the input sequence tokens in the sequence.
753
+ batch_size (`torch.Tensor`):
754
+ Batch size.
755
+ config (`SDARConfig`):
756
+ The model's configuration class
757
+ past_key_values (`Cache`):
758
+ The cache class that is being used currently to generate
759
+ """
760
+ if attention_mask is not None and attention_mask.dim() == 4:
761
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
762
+ causal_mask = attention_mask
763
+ else:
764
+ min_dtype = torch.finfo(dtype).min
765
+ causal_mask = torch.full(
766
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=cache_position.device
767
+ )
768
+ diagonal_attend_mask = torch.arange(target_length, device=cache_position.device) > cache_position.reshape(
769
+ -1, 1
770
+ )
771
+ text_config = config.get_text_config()
772
+ if getattr(text_config, "use_sliding_window", True) and text_config.sliding_window is not None:
773
+ # if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
774
+ # the check is needed to verify is current checkpoint was trained with sliding window or not
775
+ if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
776
+ sliding_attend_mask = torch.arange(target_length, device=cache_position.device) <= (
777
+ cache_position.reshape(-1, 1) -
778
+ text_config.sliding_window
779
+ )
780
+ diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
781
+ causal_mask *= diagonal_attend_mask
782
+ causal_mask = causal_mask[None, None,
783
+ :, :].expand(batch_size, 1, -1, -1)
784
+ if attention_mask is not None:
785
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
786
+ if attention_mask.shape[-1] > target_length:
787
+ attention_mask = attention_mask[:, :target_length]
788
+ mask_length = attention_mask.shape[-1]
789
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
790
+ causal_mask.device
791
+ )
792
+ padding_mask = padding_mask == 0
793
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
794
+ padding_mask, min_dtype
795
+ )
796
+ return causal_mask
797
+
798
+
799
+ class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs):
800
+ ...
801
+
802
+
803
+ @auto_docstring
804
+ class SDARForCausalLM(SDARPreTrainedModel, GenerationMixin):
805
+ _tied_weights_keys = ["lm_head.weight"]
806
+ _tp_plan = {"lm_head": "colwise_rep"}
807
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
808
+
809
+ def __init__(self, config):
810
+ super().__init__(config)
811
+ self.model = SDARModel(config)
812
+ self.vocab_size = config.vocab_size
813
+ self.lm_head = nn.Linear(
814
+ config.hidden_size, config.vocab_size, bias=False)
815
+
816
+ # Initialize weights and apply final processing
817
+ self.post_init()
818
+
819
+ def get_input_embeddings(self):
820
+ return self.model.embed_tokens
821
+
822
+ def set_input_embeddings(self, value):
823
+ self.model.embed_tokens = value
824
+
825
+ def get_output_embeddings(self):
826
+ return self.lm_head
827
+
828
+ def set_output_embeddings(self, new_embeddings):
829
+ self.lm_head = new_embeddings
830
+
831
+ def set_decoder(self, decoder):
832
+ self.model = decoder
833
+
834
+ def get_decoder(self):
835
+ return self.model
836
+
837
+ @can_return_tuple
838
+ @auto_docstring
839
+ def forward(
840
+ self,
841
+ input_ids: Optional[torch.LongTensor] = None,
842
+ attention_mask: Optional[torch.Tensor] = None,
843
+ position_ids: Optional[torch.LongTensor] = None,
844
+ past_key_values: Optional[Cache] = None,
845
+ inputs_embeds: Optional[torch.FloatTensor] = None,
846
+ labels: Optional[torch.LongTensor] = None,
847
+ use_cache: Optional[bool] = None,
848
+ output_attentions: Optional[bool] = None,
849
+ output_hidden_states: Optional[bool] = None,
850
+ cache_position: Optional[torch.LongTensor] = None,
851
+ logits_to_keep: Union[int, torch.Tensor] = 0,
852
+ **kwargs: Unpack[KwargsForCausalLM],
853
+ ) -> CausalLMOutputWithPast:
854
+ r"""
855
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
856
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
857
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
858
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
859
+ Example:
860
+ ```python
861
+ >>> from transformers import AutoTokenizer, SDARForCausalLM
862
+ >>> model = SDARForCausalLM.from_pretrained("DiffuOpen/SDAR-1.7B-Chat")
863
+ >>> tokenizer = AutoTokenizer.from_pretrained("DiffuOpen/SDAR-1.7B-Chat")
864
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
865
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
866
+ >>> # Generate
867
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
868
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
869
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
870
+ ```"""
871
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
872
+ output_hidden_states = (
873
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
874
+ )
875
+
876
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
877
+ outputs: BaseModelOutputWithPast = self.model(
878
+ input_ids=input_ids,
879
+ attention_mask=attention_mask,
880
+ position_ids=position_ids,
881
+ past_key_values=past_key_values,
882
+ inputs_embeds=inputs_embeds,
883
+ use_cache=use_cache,
884
+ output_attentions=output_attentions,
885
+ output_hidden_states=output_hidden_states,
886
+ cache_position=cache_position,
887
+ **kwargs,
888
+ )
889
+
890
+ hidden_states = outputs.last_hidden_state
891
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
892
+ slice_indices = slice(-logits_to_keep,
893
+ None) if isinstance(logits_to_keep, int) else logits_to_keep
894
+ hidden_states = hidden_states[:, slice_indices, :].contiguous()
895
+ fuse_linear_and_cross_entropy = self.config.fuse_cross_entropy and self.training
896
+ if fuse_linear_and_cross_entropy:
897
+ # When using fused_linear_ce_loss, we do not compute the whole logits on HBM
898
+ logits = None
899
+ else:
900
+ logits = self.lm_head(hidden_states)
901
+
902
+ loss = None
903
+ if labels is not None:
904
+ # FusedLinearCrossEntropyLoss will be implemented by monkey patch when training
905
+ # We don't use it when inferencing
906
+ loss_fct = nn.CrossEntropyLoss() # nn.CE
907
+ loss = loss_fct(
908
+ logits.view(-1, self.config.vocab_size), labels.view(-1))
909
+
910
+ return CausalLMOutputWithPast(
911
+ loss=loss,
912
+ logits=logits,
913
+ past_key_values=outputs.past_key_values,
914
+ hidden_states=outputs.hidden_states,
915
+ attentions=outputs.attentions,
916
+ )
917
+
918
+
919
+ __all__ = [
920
+ "SDARForCausalLM",
921
+ "SDARModel",
922
+ "SDARPreTrainedModel",
923
+ ]
special_tokens_map.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>",
16
+ "<|MASK|>"
17
+ ],
18
+ "eos_token": {
19
+ "content": "<|endoftext|>",
20
+ "lstrip": false,
21
+ "normalized": false,
22
+ "rstrip": false,
23
+ "single_word": false
24
+ },
25
+ "mask_token": {
26
+ "content": "<|MASK|>",
27
+ "lstrip": false,
28
+ "normalized": false,
29
+ "rstrip": false,
30
+ "single_word": false
31
+ },
32
+ "pad_token": {
33
+ "content": "<|endoftext|>",
34
+ "lstrip": false,
35
+ "normalized": false,
36
+ "rstrip": false,
37
+ "single_word": false
38
+ }
39
+ }
tokenization_qwen2.py ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ print(f"--- I am EXECUTING tokenization_qwen2.py from location: {__file__} ---")
2
+ # coding=utf-8
3
+ # Copyright 2024 The Qwen team, Alibaba Group and The HuggingFace Inc. team. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ """Tokenization classes for Qwen2."""
17
+
18
+ import json
19
+ import os
20
+ import unicodedata
21
+ from functools import lru_cache
22
+ from typing import Optional, Tuple
23
+
24
+ import regex as re
25
+
26
+ from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
27
+ from transformers.utils import logging
28
+
29
+
30
+ logger = logging.get_logger(__name__)
31
+
32
+ VOCAB_FILES_NAMES = {
33
+ "vocab_file": "vocab.json",
34
+ "merges_file": "merges.txt",
35
+ }
36
+
37
+
38
+ MAX_MODEL_INPUT_SIZES = {"qwen/qwen-tokenizer": 32768}
39
+
40
+ PRETOKENIZE_REGEX = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
41
+
42
+
43
+ @lru_cache()
44
+ # Copied from transformers.models.gpt2.tokenization_gpt2.bytes_to_unicode
45
+ def bytes_to_unicode():
46
+ """
47
+ Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control
48
+ characters the bpe code barfs on.
49
+
50
+ The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab
51
+ if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for
52
+ decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup
53
+ tables between utf-8 bytes and unicode strings.
54
+ """
55
+ bs = (
56
+ list(range(ord("!"), ord("~") + 1)) + list(range(ord("¡"), ord("¬") + 1)) + list(range(ord("®"), ord("ÿ") + 1))
57
+ )
58
+ cs = bs[:]
59
+ n = 0
60
+ for b in range(2**8):
61
+ if b not in bs:
62
+ bs.append(b)
63
+ cs.append(2**8 + n)
64
+ n += 1
65
+ cs = [chr(n) for n in cs]
66
+ return dict(zip(bs, cs))
67
+
68
+
69
+ # Copied from transformers.models.gpt2.tokenization_gpt2.get_pairs
70
+ def get_pairs(word):
71
+ """
72
+ Return set of symbol pairs in a word.
73
+
74
+ Word is represented as tuple of symbols (symbols being variable-length strings).
75
+ """
76
+ pairs = set()
77
+ prev_char = word[0]
78
+ for char in word[1:]:
79
+ pairs.add((prev_char, char))
80
+ prev_char = char
81
+ return pairs
82
+
83
+
84
+ class Qwen2Tokenizer(PreTrainedTokenizer):
85
+ """
86
+ Construct a Qwen2 tokenizer. Based on byte-level Byte-Pair-Encoding.
87
+
88
+ Same with GPT2Tokenizer, this tokenizer has been trained to treat spaces like parts of the tokens so a word will
89
+ be encoded differently whether it is at the beginning of the sentence (without space) or not:
90
+
91
+ ```python
92
+ >>> from transformers import Qwen2Tokenizer
93
+
94
+ >>> tokenizer = Qwen2Tokenizer.from_pretrained("Qwen/Qwen-tokenizer")
95
+ >>> tokenizer("Hello world")["input_ids"]
96
+ [9707, 1879]
97
+
98
+ >>> tokenizer(" Hello world")["input_ids"]
99
+ [21927, 1879]
100
+ ```
101
+ This is expected.
102
+
103
+ You should not use GPT2Tokenizer instead, because of the different pretokenization rules.
104
+
105
+ This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
106
+ this superclass for more information regarding those methods.
107
+
108
+ Args:
109
+ vocab_file (`str`):
110
+ Path to the vocabulary file.
111
+ merges_file (`str`):
112
+ Path to the merges file.
113
+ errors (`str`, *optional*, defaults to `"replace"`):
114
+ Paradigm to follow when decoding bytes to UTF-8. See
115
+ [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information.
116
+ unk_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
117
+ The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
118
+ token instead.
119
+ bos_token (`str`, *optional*):
120
+ The beginning of sequence token. Not applicable for this tokenizer.
121
+ eos_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
122
+ The end of sequence token.
123
+ pad_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
124
+ The token used for padding, for example when batching sequences of different lengths.
125
+ clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
126
+ Whether or not the model should cleanup the spaces that were added when splitting the input text during the
127
+ tokenization process. Not applicable to this tokenizer, since tokenization does not add spaces.
128
+ split_special_tokens (`bool`, *optional*, defaults to `False`):
129
+ Whether or not the special tokens should be split during the tokenization process. The default behavior is
130
+ to not split special tokens. This means that if `<|endoftext|>` is the `eos_token`, then `tokenizer.tokenize("<|endoftext|>") =
131
+ ['<|endoftext|>`]. Otherwise, if `split_special_tokens=True`, then `tokenizer.tokenize("<|endoftext|>")` will be give `['<',
132
+ '|', 'endo', 'ft', 'ext', '|', '>']`. This argument is only supported for `slow` tokenizers for the moment.
133
+ """
134
+
135
+ vocab_files_names = VOCAB_FILES_NAMES
136
+ model_input_names = ["input_ids", "attention_mask"]
137
+
138
+ def __init__(
139
+ self,
140
+ vocab_file,
141
+ merges_file,
142
+ errors="replace",
143
+ unk_token="<|endoftext|>",
144
+ bos_token=None,
145
+ eos_token="<|endoftext|>",
146
+ pad_token="<|endoftext|>",
147
+ clean_up_tokenization_spaces=False,
148
+ split_special_tokens=False,
149
+ **kwargs,
150
+ ):
151
+ # Qwen vocab does not contain control tokens; added tokens need to be special
152
+ bos_token = (
153
+ AddedToken(bos_token, lstrip=False, rstrip=False, special=True, normalized=False)
154
+ if isinstance(bos_token, str)
155
+ else bos_token
156
+ )
157
+ eos_token = (
158
+ AddedToken(eos_token, lstrip=False, rstrip=False, special=True, normalized=False)
159
+ if isinstance(eos_token, str)
160
+ else eos_token
161
+ )
162
+ unk_token = (
163
+ AddedToken(unk_token, lstrip=False, rstrip=False, special=True, normalized=False)
164
+ if isinstance(unk_token, str)
165
+ else unk_token
166
+ )
167
+ pad_token = (
168
+ AddedToken(pad_token, lstrip=False, rstrip=False, special=True, normalized=False)
169
+ if isinstance(pad_token, str)
170
+ else pad_token
171
+ )
172
+
173
+ with open(vocab_file, encoding="utf-8") as vocab_handle:
174
+ self.encoder = json.load(vocab_handle)
175
+ self.decoder = {v: k for k, v in self.encoder.items()}
176
+ self.errors = errors # how to handle errors in decoding
177
+ self.byte_encoder = bytes_to_unicode()
178
+ self.byte_decoder = {v: k for k, v in self.byte_encoder.items()}
179
+ bpe_merges = []
180
+ with open(merges_file, encoding="utf-8") as merges_handle:
181
+ for i, line in enumerate(merges_handle):
182
+ line = line.strip()
183
+ if (i == 0 and line.startswith("#version:")) or not line:
184
+ continue
185
+ bpe_merges.append(tuple(line.split()))
186
+ self.bpe_ranks = dict(zip(bpe_merges, range(len(bpe_merges))))
187
+ # NOTE: the cache can grow without bound and will get really large for long running processes
188
+ # (esp. for texts of language that do not use space between word, e.g. Chinese); technically
189
+ # not a memory leak but appears as one.
190
+ # GPT2Tokenizer has the same problem, so let's be consistent.
191
+ self.cache = {}
192
+
193
+ self.pat = re.compile(PRETOKENIZE_REGEX)
194
+
195
+ if kwargs.get("add_prefix_space", False):
196
+ logger.warning_once(
197
+ f"{self.__class__.__name} does not support `add_prefix_space`, setting it to True has no effect."
198
+ )
199
+
200
+ super().__init__(
201
+ errors=errors,
202
+ bos_token=bos_token,
203
+ eos_token=eos_token,
204
+ pad_token=pad_token,
205
+ unk_token=unk_token,
206
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
207
+ split_special_tokens=split_special_tokens,
208
+ **kwargs,
209
+ )
210
+
211
+ @property
212
+ def vocab_size(self) -> int:
213
+ return len(self.encoder)
214
+
215
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.get_vocab
216
+ def get_vocab(self):
217
+ return dict(self.encoder, **self.added_tokens_encoder)
218
+
219
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.bpe
220
+ def bpe(self, token):
221
+ if token in self.cache:
222
+ return self.cache[token]
223
+ word = tuple(token)
224
+ pairs = get_pairs(word)
225
+
226
+ if not pairs:
227
+ return token
228
+
229
+ while True:
230
+ bigram = min(pairs, key=lambda pair: self.bpe_ranks.get(pair, float("inf")))
231
+ if bigram not in self.bpe_ranks:
232
+ break
233
+ first, second = bigram
234
+ new_word = []
235
+ i = 0
236
+ while i < len(word):
237
+ try:
238
+ j = word.index(first, i)
239
+ except ValueError:
240
+ new_word.extend(word[i:])
241
+ break
242
+ else:
243
+ new_word.extend(word[i:j])
244
+ i = j
245
+
246
+ if word[i] == first and i < len(word) - 1 and word[i + 1] == second:
247
+ new_word.append(first + second)
248
+ i += 2
249
+ else:
250
+ new_word.append(word[i])
251
+ i += 1
252
+ new_word = tuple(new_word)
253
+ word = new_word
254
+ if len(word) == 1:
255
+ break
256
+ else:
257
+ pairs = get_pairs(word)
258
+ word = " ".join(word)
259
+ self.cache[token] = word
260
+ return word
261
+
262
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._tokenize
263
+ def _tokenize(self, text):
264
+ """Tokenize a string."""
265
+ bpe_tokens = []
266
+ for token in re.findall(self.pat, text):
267
+ token = "".join(
268
+ self.byte_encoder[b] for b in token.encode("utf-8")
269
+ ) # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
270
+ bpe_tokens.extend(bpe_token for bpe_token in self.bpe(token).split(" "))
271
+ return bpe_tokens
272
+
273
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._convert_token_to_id
274
+ def _convert_token_to_id(self, token):
275
+ """Converts a token (str) in an id using the vocab."""
276
+ return self.encoder.get(token, self.encoder.get(self.unk_token))
277
+
278
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer._convert_id_to_token
279
+ def _convert_id_to_token(self, index):
280
+ """Converts an index (integer) in a token (str) using the vocab."""
281
+ return self.decoder.get(index)
282
+
283
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.convert_tokens_to_string
284
+ def convert_tokens_to_string(self, tokens):
285
+ """Converts a sequence of tokens (string) in a single string."""
286
+ text = "".join(tokens)
287
+ text = bytearray([self.byte_decoder[c] for c in text]).decode("utf-8", errors=self.errors)
288
+ return text
289
+
290
+ def decode(
291
+ self,
292
+ token_ids,
293
+ skip_special_tokens: bool = False,
294
+ clean_up_tokenization_spaces: Optional[bool] = False,
295
+ spaces_between_special_tokens: bool = False,
296
+ **kwargs,
297
+ ) -> str:
298
+ # `spaces_between_special_tokens` defaults to True for _decode in slow tokenizers
299
+ # and cannot be configured elsewhere, but it should default to False for Qwen2Tokenizer
300
+ return super().decode(
301
+ token_ids,
302
+ skip_special_tokens=skip_special_tokens,
303
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
304
+ spaces_between_special_tokens=spaces_between_special_tokens,
305
+ **kwargs,
306
+ )
307
+
308
+ # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.save_vocabulary
309
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
310
+ if not os.path.isdir(save_directory):
311
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
312
+ return
313
+ vocab_file = os.path.join(
314
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
315
+ )
316
+ merge_file = os.path.join(
317
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"]
318
+ )
319
+
320
+ with open(vocab_file, "w", encoding="utf-8") as f:
321
+ f.write(json.dumps(self.encoder, indent=2, sort_keys=True, ensure_ascii=False) + "\n")
322
+
323
+ index = 0
324
+ with open(merge_file, "w", encoding="utf-8") as writer:
325
+ writer.write("#version: 0.2\n")
326
+ for bpe_tokens, token_index in sorted(self.bpe_ranks.items(), key=lambda kv: kv[1]):
327
+ if index != token_index:
328
+ logger.warning(
329
+ f"Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."
330
+ " Please check that the tokenizer is not corrupted!"
331
+ )
332
+ index = token_index
333
+ writer.write(" ".join(bpe_tokens) + "\n")
334
+ index += 1
335
+
336
+ return vocab_file, merge_file
337
+
338
+ def prepare_for_tokenization(self, text, **kwargs):
339
+ text = unicodedata.normalize("NFC", text)
340
+ return (text, kwargs)
341
+
342
+
343
+ __all__ = ["Qwen2Tokenizer"]
tokenization_qwen2_fast.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and The 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
+ """Tokenization classes for Qwen2."""
16
+
17
+ from typing import Optional, Tuple
18
+
19
+ from transformers.tokenization_utils import AddedToken
20
+ from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
21
+ from transformers.utils import logging
22
+ from .tokenization_qwen2 import Qwen2Tokenizer
23
+
24
+
25
+ logger = logging.get_logger(__name__)
26
+
27
+ VOCAB_FILES_NAMES = {
28
+ "vocab_file": "vocab.json",
29
+ "merges_file": "merges.txt",
30
+ "tokenizer_file": "tokenizer.json",
31
+ }
32
+
33
+
34
+ MAX_MODEL_INPUT_SIZES = {"qwen/qwen-tokenizer": 32768}
35
+
36
+
37
+ class Qwen2TokenizerFast(PreTrainedTokenizerFast):
38
+ """
39
+ Construct a "fast" Qwen2 tokenizer (backed by HuggingFace's *tokenizers* library). Based on byte-level
40
+ Byte-Pair-Encoding.
41
+
42
+ Same with GPT2Tokenizer, this tokenizer has been trained to treat spaces like parts of the tokens so a word will
43
+ be encoded differently whether it is at the beginning of the sentence (without space) or not:
44
+
45
+ ```python
46
+ >>> from transformers import Qwen2TokenizerFast
47
+
48
+ >>> tokenizer = Qwen2TokenizerFast.from_pretrained("Qwen/Qwen-tokenizer")
49
+ >>> tokenizer("Hello world")["input_ids"]
50
+ [9707, 1879]
51
+
52
+ >>> tokenizer(" Hello world")["input_ids"]
53
+ [21927, 1879]
54
+ ```
55
+ This is expected.
56
+
57
+ This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
58
+ refer to this superclass for more information regarding those methods.
59
+
60
+ Args:
61
+ vocab_file (`str`, *optional*):
62
+ Path to the vocabulary file.
63
+ merges_file (`str`, *optional*):
64
+ Path to the merges file.
65
+ tokenizer_file (`str`, *optional*):
66
+ Path to [tokenizers](https://github.com/huggingface/tokenizers) file (generally has a .json extension) that
67
+ contains everything needed to load the tokenizer.
68
+ unk_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
69
+ The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
70
+ token instead. Not applicable to this tokenizer.
71
+ bos_token (`str`, *optional*):
72
+ The beginning of sequence token. Not applicable for this tokenizer.
73
+ eos_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
74
+ The end of sequence token.
75
+ pad_token (`str`, *optional*, defaults to `"<|endoftext|>"`):
76
+ The token used for padding, for example when batching sequences of different lengths.
77
+ """
78
+
79
+ vocab_files_names = VOCAB_FILES_NAMES
80
+ model_input_names = ["input_ids", "attention_mask"]
81
+ slow_tokenizer_class = Qwen2Tokenizer
82
+
83
+ def __init__(
84
+ self,
85
+ vocab_file=None,
86
+ merges_file=None,
87
+ tokenizer_file=None,
88
+ unk_token="<|endoftext|>",
89
+ bos_token=None,
90
+ eos_token="<|endoftext|>",
91
+ pad_token="<|endoftext|>",
92
+ **kwargs,
93
+ ):
94
+ # We need to at least pass vocab_file and merges_file to base class
95
+ # in case a slow tokenizer needs to be initialized; other can be
96
+ # configured through files.
97
+ # following GPT2TokenizerFast, also adding unk_token, bos_token, and eos_token
98
+
99
+ bos_token = (
100
+ AddedToken(bos_token, lstrip=False, rstrip=False, special=True, normalized=False)
101
+ if isinstance(bos_token, str)
102
+ else bos_token
103
+ )
104
+ eos_token = (
105
+ AddedToken(eos_token, lstrip=False, rstrip=False, special=True, normalized=False)
106
+ if isinstance(eos_token, str)
107
+ else eos_token
108
+ )
109
+ unk_token = (
110
+ AddedToken(unk_token, lstrip=False, rstrip=False, special=True, normalized=False)
111
+ if isinstance(unk_token, str)
112
+ else unk_token
113
+ )
114
+ pad_token = (
115
+ AddedToken(pad_token, lstrip=False, rstrip=False, special=True, normalized=False)
116
+ if isinstance(pad_token, str)
117
+ else pad_token
118
+ )
119
+
120
+ super().__init__(
121
+ vocab_file=vocab_file,
122
+ merges_file=merges_file,
123
+ tokenizer_file=tokenizer_file,
124
+ unk_token=unk_token,
125
+ bos_token=bos_token,
126
+ eos_token=eos_token,
127
+ pad_token=pad_token,
128
+ **kwargs,
129
+ )
130
+
131
+ # Copied from transformers.models.gpt2.tokenization_gpt2_fast.GPT2TokenizerFast.save_vocabulary
132
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
133
+ files = self._tokenizer.model.save(save_directory, name=filename_prefix)
134
+ return tuple(files)
135
+
136
+
137
+ __all__ = ["Qwen2TokenizerFast"]
tokenizer_config.json ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ },
213
+ "151669": {
214
+ "content": "<|MASK|>",
215
+ "lstrip": false,
216
+ "normalized": false,
217
+ "rstrip": false,
218
+ "single_word": false,
219
+ "special": true
220
+ }
221
+ },
222
+ "additional_special_tokens": [
223
+ "<|im_start|>",
224
+ "<|im_end|>",
225
+ "<|object_ref_start|>",
226
+ "<|object_ref_end|>",
227
+ "<|box_start|>",
228
+ "<|box_end|>",
229
+ "<|quad_start|>",
230
+ "<|quad_end|>",
231
+ "<|vision_start|>",
232
+ "<|vision_end|>",
233
+ "<|vision_pad|>",
234
+ "<|image_pad|>",
235
+ "<|video_pad|>",
236
+ "<|MASK|>"
237
+ ],
238
+ "auto_map": {
239
+ "AutoTokenizer": [
240
+ "tokenization_qwen2.Qwen2Tokenizer",
241
+ null
242
+ ]
243
+ },
244
+ "bos_token": null,
245
+ "clean_up_tokenization_spaces": false,
246
+ "eos_token": "<|endoftext|>",
247
+ "errors": "replace",
248
+ "extra_special_tokens": {},
249
+ "mask_token": "<|MASK|>",
250
+ "model_max_length": 131072,
251
+ "pad_token": "<|endoftext|>",
252
+ "split_special_tokens": false,
253
+ "tokenizer_class": "Qwen2Tokenizer",
254
+ "unk_token": null
255
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff