Qubitium commited on
Commit
3eb68fa
·
verified ·
1 Parent(s): 162e007

Add files using upload-large-folder tool

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|box_end|>": 151649,
9
+ "<|box_start|>": 151648,
10
+ "<|endoftext|>": 151643,
11
+ "<|file_sep|>": 151664,
12
+ "<|fim_middle|>": 151660,
13
+ "<|fim_pad|>": 151662,
14
+ "<|fim_prefix|>": 151659,
15
+ "<|fim_suffix|>": 151661,
16
+ "<|im_end|>": 151645,
17
+ "<|im_start|>": 151644,
18
+ "<|image_pad|>": 151655,
19
+ "<|object_ref_end|>": 151647,
20
+ "<|object_ref_start|>": 151646,
21
+ "<|quad_end|>": 151651,
22
+ "<|quad_start|>": 151650,
23
+ "<|repo_name|>": 151663,
24
+ "<|video_pad|>": 151656,
25
+ "<|vision_end|>": 151653,
26
+ "<|vision_pad|>": 151654,
27
+ "<|vision_start|>": 151652
28
+ }
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,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BrumbyForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_brumby.BrumbyConfig",
9
+ "AutoModelForCausalLM": "modeling_brumby.BrumbyForCausalLM"
10
+ },
11
+ "bos_token_id": 151643,
12
+ "chunk_size": 64,
13
+ "dtype": "bfloat16",
14
+ "eos_token_id": 151643,
15
+ "head_dim": 128,
16
+ "hidden_act": "silu",
17
+ "hidden_size": 5120,
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 17408,
20
+ "layer_types": [
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention",
58
+ "full_attention",
59
+ "full_attention",
60
+ "full_attention"
61
+ ],
62
+ "max_position_embeddings": 32768,
63
+ "max_window_layers": 40,
64
+ "model_type": "brumby",
65
+ "num_attention_heads": 40,
66
+ "num_hidden_layers": 40,
67
+ "num_key_value_heads": 8,
68
+ "p": 2,
69
+ "pad_token_id": 151643,
70
+ "prefill_chunk_size": 1024,
71
+ "quantization_config": {
72
+ "bits": 4,
73
+ "checkpoint_format": "gptq",
74
+ "desc_act": false,
75
+ "group_size": 32,
76
+ "lm_head": false,
77
+ "meta": {
78
+ "act_group_aware": true,
79
+ "damp_auto_increment": 0.01,
80
+ "damp_percent": 0.05,
81
+ "mse": 0.0,
82
+ "quantizer": [
83
+ "gptqmodel:5.1.0-dev"
84
+ ],
85
+ "static_groups": false,
86
+ "true_sequential": true,
87
+ "uri": "https://github.com/modelcloud/gptqmodel",
88
+ "v2": false,
89
+ "v2_alpha": 0.25
90
+ },
91
+ "pack_dtype": "int32",
92
+ "pack_impl": "cpu",
93
+ "quant_method": "gptq",
94
+ "sym": true
95
+ },
96
+ "rms_norm_eps": 1e-06,
97
+ "rope_scaling": null,
98
+ "rope_theta": 1000000,
99
+ "sliding_window": null,
100
+ "switch_over_seq_len": 8192,
101
+ "tie_word_embeddings": false,
102
+ "transformers_version": "4.57.1",
103
+ "use_cache": true,
104
+ "use_exp": false,
105
+ "use_sliding_window": false,
106
+ "vocab_size": 151936
107
+ }
configuration_brumby.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 Manifest AI.
3
+ # Copyright (c) 2025, NVIDIA CORPORATION. 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
+ """Brumby model configuration"""
17
+
18
+ from transformers.configuration_utils import PretrainedConfig, layer_type_validation
19
+ from transformers.modeling_rope_utils import rope_config_validation
20
+ from transformers.utils import logging
21
+
22
+
23
+ logger = logging.get_logger(__name__)
24
+
25
+
26
+ class BrumbyConfig(PretrainedConfig):
27
+ r"""
28
+ This is the configuration class to store the configuration of a [`BrumbyModel`]. It is used to instantiate a
29
+ Brumby model according to the specified arguments, defining the model architecture. Instantiating a configuration
30
+ with the defaults will yield a similar configuration to that of
31
+ Brumby-14B-base [Brumby/Brumby-14B-base](https://huggingface.co/manifestai/Brumby-14B-base).
32
+
33
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
34
+ documentation from [`PretrainedConfig`] for more information.
35
+
36
+
37
+ Args:
38
+ vocab_size (`int`, *optional*, defaults to 151936):
39
+ Vocabulary size of the Brumby model. Defines the number of different tokens that can be represented by the
40
+ `inputs_ids` passed when calling [`BrumbyModel`]
41
+ hidden_size (`int`, *optional*, defaults to 4096):
42
+ Dimension of the hidden representations.
43
+ intermediate_size (`int`, *optional*, defaults to 22016):
44
+ Dimension of the MLP representations.
45
+ num_hidden_layers (`int`, *optional*, defaults to 32):
46
+ Number of hidden layers in the Transformer encoder.
47
+ num_attention_heads (`int`, *optional*, defaults to 32):
48
+ Number of attention heads for each attention layer in the Transformer encoder.
49
+ num_key_value_heads (`int`, *optional*, defaults to 32):
50
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
51
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
52
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
53
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
54
+ by meanpooling all the original heads within that group. For more details, check out [this
55
+ paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `32`.
56
+ head_dim (`int`, *optional*, defaults to 128):
57
+ The attention head dimension.
58
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
59
+ The non-linear activation function (function or string) in the decoder.
60
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
61
+ The maximum sequence length that this model might ever be used with.
62
+ initializer_range (`float`, *optional*, defaults to 0.02):
63
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
64
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
65
+ The epsilon used by the rms normalization layers.
66
+ use_cache (`bool`, *optional*, defaults to `True`):
67
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
68
+ relevant if `config.is_decoder=True`.
69
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
70
+ Whether the model's input and output word embeddings should be tied.
71
+ rope_theta (`float`, *optional*, defaults to 10000.0):
72
+ The base period of the RoPE embeddings.
73
+ rope_scaling (`Dict`, *optional*):
74
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
75
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
76
+ accordingly.
77
+ Expected contents:
78
+ `rope_type` (`str`):
79
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
80
+ 'llama3'], with 'default' being the original RoPE implementation.
81
+ `factor` (`float`, *optional*):
82
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
83
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
84
+ original maximum pre-trained length.
85
+ `original_max_position_embeddings` (`int`, *optional*):
86
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
87
+ pretraining.
88
+ `attention_factor` (`float`, *optional*):
89
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
90
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
91
+ `factor` field to infer the suggested value.
92
+ `beta_fast` (`float`, *optional*):
93
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
94
+ ramp function. If unspecified, it defaults to 32.
95
+ `beta_slow` (`float`, *optional*):
96
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
97
+ ramp function. If unspecified, it defaults to 1.
98
+ `short_factor` (`list[float]`, *optional*):
99
+ Only used with 'longrope'. The scaling factor to be applied to short 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
+ `long_factor` (`list[float]`, *optional*):
103
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
104
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
105
+ size divided by the number of attention heads divided by 2
106
+ `low_freq_factor` (`float`, *optional*):
107
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
108
+ `high_freq_factor` (`float`, *optional*):
109
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
110
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
111
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
112
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
113
+ Whether to use sliding window attention.
114
+ sliding_window (`int`, *optional*, defaults to 4096):
115
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
116
+ max_window_layers (`int`, *optional*, defaults to 28):
117
+ The number of layers using full attention. The first `max_window_layers` layers will use full attention, while any
118
+ additional layer afterwards will use SWA (Sliding Window Attention).
119
+ layer_types (`list`, *optional*):
120
+ Attention pattern for each layer.
121
+ attention_dropout (`float`, *optional*, defaults to 0.0):
122
+ The dropout ratio for the attention probabilities.
123
+
124
+ ```python
125
+ >>> from transformers import BrumbyModel, BrumbyConfig
126
+
127
+ >>> # Initializing a Brumby style configuration
128
+ >>> configuration = BrumbyConfig()
129
+
130
+ >>> # Initializing a model from the Brumby-14B-base style configuration
131
+ >>> model = BrumbyModel(configuration)
132
+
133
+ >>> # Accessing the model configuration
134
+ >>> configuration = model.config
135
+ ```"""
136
+
137
+ model_type = "brumby"
138
+ keys_to_ignore_at_inference = ["past_key_values"]
139
+
140
+ # Default tensor parallel plan for base model `Brumby`
141
+ base_model_tp_plan = {
142
+ "layers.*.self_attn.q_proj": "colwise",
143
+ "layers.*.self_attn.k_proj": "colwise",
144
+ "layers.*.self_attn.v_proj": "colwise",
145
+ "layers.*.self_attn.o_proj": "rowwise",
146
+ "layers.*.mlp.gate_proj": "colwise",
147
+ "layers.*.mlp.up_proj": "colwise",
148
+ "layers.*.mlp.down_proj": "rowwise",
149
+ }
150
+ base_model_pp_plan = {
151
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
152
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
153
+ "norm": (["hidden_states"], ["hidden_states"]),
154
+ }
155
+
156
+ def __init__(
157
+ self,
158
+ vocab_size=151936,
159
+ hidden_size=5120,
160
+ intermediate_size=17408,
161
+ num_hidden_layers=40,
162
+ num_attention_heads=40,
163
+ num_key_value_heads=8,
164
+ head_dim=128,
165
+ hidden_act="silu",
166
+ max_position_embeddings=32768,
167
+ initializer_range=0.02,
168
+ rms_norm_eps=1e-6,
169
+ use_cache=True,
170
+ tie_word_embeddings=False,
171
+ rope_theta=10000.0,
172
+ rope_scaling=None,
173
+ attention_bias=False,
174
+ use_sliding_window=False,
175
+ sliding_window=4096,
176
+ max_window_layers=40,
177
+ layer_types=None,
178
+ attention_dropout=0.0,
179
+ chunk_size=64,
180
+ switch_over_seq_len=8192,
181
+ prefill_chunk_size=1024,
182
+ use_exp=False,
183
+ **kwargs,
184
+ ):
185
+ self.vocab_size = vocab_size
186
+ self.max_position_embeddings = max_position_embeddings
187
+ self.hidden_size = hidden_size
188
+ self.intermediate_size = intermediate_size
189
+ self.num_hidden_layers = num_hidden_layers
190
+ self.num_attention_heads = num_attention_heads
191
+ self.use_sliding_window = use_sliding_window
192
+ self.sliding_window = sliding_window if self.use_sliding_window else None
193
+ self.max_window_layers = max_window_layers
194
+
195
+ # for backward compatibility
196
+ if num_key_value_heads is None:
197
+ num_key_value_heads = num_attention_heads
198
+
199
+ self.num_key_value_heads = num_key_value_heads
200
+ self.head_dim = head_dim
201
+ self.hidden_act = hidden_act
202
+ self.initializer_range = initializer_range
203
+ self.rms_norm_eps = rms_norm_eps
204
+ self.use_cache = use_cache
205
+ self.rope_theta = rope_theta
206
+ self.rope_scaling = rope_scaling
207
+ self.attention_bias = attention_bias
208
+ self.attention_dropout = attention_dropout
209
+ # Validate the correctness of rotary position embeddings parameters
210
+ # BC: if there is a 'type' field, move it to 'rope_type'.
211
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
212
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
213
+ rope_config_validation(self)
214
+
215
+ self.layer_types = layer_types
216
+ if self.layer_types is None:
217
+ self.layer_types = [
218
+ "sliding_attention"
219
+ if self.sliding_window is not None and i >= self.max_window_layers
220
+ else "full_attention"
221
+ for i in range(self.num_hidden_layers)
222
+ ]
223
+ layer_type_validation(self.layer_types, self.num_hidden_layers)
224
+ self.chunk_size = chunk_size
225
+ self.switch_over_seq_len = switch_over_seq_len
226
+ self.prefill_chunk_size = prefill_chunk_size
227
+ self.use_exp = use_exp
228
+ self.p = 2 # power of expansion for power attention, only 2 is supported for now
229
+ super().__init__(
230
+ tie_word_embeddings=tie_word_embeddings,
231
+ **kwargs,
232
+ )
233
+
234
+
235
+ __all__ = ["BrumbyConfig"]
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": 151643,
5
+ "max_new_tokens": 2048,
6
+ "transformers_version": "4.57.1"
7
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7a5fb6d7c5f0fbe8881269a0d64950655c2116fd54d57c0faa2ac418455cc8f
3
+ size 4285645429
model-00002-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edebaa9a0222e8d49729b0765b38ee700a5df083da31a710aa50d6bb601b69cb
3
+ size 4275983127
model-00003-of-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89ff91b78f9922f4309be337441185574508c9ef5e5ff6a4381da637c9579455
3
+ size 2200218491
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
modeling_brumby.py ADDED
@@ -0,0 +1,857 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 HuggingFace Inc. team.
3
+ # Copyright (c) 2025, NVIDIA CORPORATION. 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
+ """PyTorch Brumby model."""
17
+
18
+ from typing import Callable, Optional, Union, Any, Dict, Tuple
19
+
20
+ import torch
21
+ from torch import nn
22
+
23
+ from transformers.activations import ACT2FN
24
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache, SlidingWindowCache
25
+ from transformers.generation import GenerationMixin
26
+ from transformers.integrations import use_kernel_forward_from_hub
27
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
28
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
29
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
30
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
31
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
32
+ from transformers.processing_utils import Unpack
33
+ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple
34
+ from transformers.utils.deprecation import deprecate_kwarg
35
+ from transformers.utils.generic import check_model_inputs
36
+ from .configuration_brumby import BrumbyConfig
37
+
38
+
39
+ try:
40
+ from retention.triton import power_retention, power_retention_inference
41
+ from retention._utils import compute_expanded_dim
42
+ except ImportError:
43
+ raise ImportError("Retention is required by the Brumby model. Please install it with `pip install retention`.")
44
+
45
+
46
+ class PowerAttentionDynamicCache(DynamicCache):
47
+ """
48
+ A dynamic cache that encompasses 2 sets of caches:
49
+ 1. attention cache with a short seq_len (determined by the chunk_size parameter):
50
+ - key_cache: [batch_size, num_heads, chunk_size, head_dim]
51
+ - value_cache: [batch_size, num_heads, chunk_size, head_dim]
52
+ - gating_cache: [batch_size, num_heads, chunk_size]
53
+ 2. fixed-size state-based cache:
54
+ - state: [batch_size, num_heads, state_dim, head_dim]
55
+ - sum_of_keys: [batch_size, num_heads, state_dim]
56
+
57
+ where state_dim is determined by the power of expansion for power attention.
58
+ """
59
+ def __init__(self, config: BrumbyConfig, batch_size: int, dtype=torch.bfloat16, device=None):
60
+ super().__init__()
61
+ self.config = config
62
+ self.batch_size = batch_size
63
+ self.device = device
64
+ self.dtype = dtype
65
+ self.chunk_size = config.chunk_size
66
+ self.head_dim = config.hidden_size // config.num_attention_heads
67
+ self.p = config.p
68
+ self.state_dim = compute_expanded_dim(self.head_dim, deg=self.p)
69
+
70
+ self.states = [None for _ in range(config.num_hidden_layers)]
71
+ self.sum_of_keys = [None for _ in range(config.num_hidden_layers)]
72
+ self.key_cache = [torch.tensor([[]] * batch_size, device=device, dtype=dtype) for _ in range(config.num_hidden_layers)]
73
+ self.value_cache = [torch.tensor([[]] * batch_size, device=device, dtype=dtype) for _ in range(config.num_hidden_layers)]
74
+ self.gate_cache = [torch.tensor([[]] * batch_size, device=device, dtype=torch.float32) for _ in range(config.num_hidden_layers)]
75
+
76
+ def clean_cache(self, layer_idx: int) -> None:
77
+ self.key_cache[layer_idx] = torch.tensor([[]] * self.batch_size, device=self.device, dtype=self.dtype)
78
+ self.value_cache[layer_idx] = torch.tensor([[]] * self.batch_size, device=self.device, dtype=self.dtype)
79
+ self.gate_cache[layer_idx] = torch.tensor([[]] * self.batch_size, device=self.device, dtype=torch.float32)
80
+
81
+ def update_cache(
82
+ self,
83
+ key_states: torch.Tensor,
84
+ value_states: torch.Tensor,
85
+ gate_states: torch.Tensor,
86
+ layer_idx: int,
87
+ cache_kwargs: Optional[Dict[str, Any]] = None,
88
+ ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
89
+ if self.key_cache[layer_idx].shape[-1] == 0:
90
+ self.key_cache[layer_idx] = key_states
91
+ self.value_cache[layer_idx] = value_states
92
+ self.gate_cache[layer_idx] = gate_states
93
+ else:
94
+ self.key_cache[layer_idx] = torch.cat([self.key_cache[layer_idx], key_states], dim=2)
95
+ self.value_cache[layer_idx] = torch.cat([self.value_cache[layer_idx], value_states], dim=2)
96
+ self.gate_cache[layer_idx] = torch.cat([self.gate_cache[layer_idx], gate_states], dim=2)
97
+ return self.key_cache[layer_idx], self.value_cache[layer_idx], self.gate_cache[layer_idx], self.states[layer_idx], self.sum_of_keys[layer_idx]
98
+
99
+ def reorder_cache(self, beam_idx: torch.LongTensor):
100
+ """Reorders the cache for beam search, given the selected beam indices."""
101
+ for layer_idx in range(len(self.key_cache)):
102
+ device = self.key_cache[layer_idx].device
103
+ self.key_cache[layer_idx] = self.key_cache[layer_idx].index_select(0, beam_idx.to(device))
104
+ device = self.value_cache[layer_idx].device
105
+ self.value_cache[layer_idx] = self.value_cache[layer_idx].index_select(0, beam_idx.to(device))
106
+ device = self.gate_cache[layer_idx].device
107
+ self.gate_cache[layer_idx] = self.gate_cache[layer_idx].index_select(0, beam_idx.to(device))
108
+ device = self.states[layer_idx].device
109
+ self.states[layer_idx] = self.states[layer_idx].index_select(0, beam_idx.to(device))
110
+ device = self.sum_of_keys[layer_idx].device
111
+ self.sum_of_keys[layer_idx] = self.sum_of_keys[layer_idx].index_select(0, beam_idx.to(device))
112
+
113
+ def get_seq_length(self, layer_idx: Optional[int] = 0) -> int:
114
+ """Returns the sequence length of the cached states. A layer index can be optionally passed."""
115
+ # take any layer that contains cache and not empty tensor
116
+ if layer_idx is None:
117
+ layer_idx = 0
118
+ if layer_idx >= len(self.key_cache):
119
+ return 0
120
+ # Check if the cache for this layer is empty
121
+ if self.key_cache[layer_idx].numel() == 0:
122
+ return 0
123
+ return self.key_cache[layer_idx].shape[-2]
124
+
125
+ def to_legacy_cache(self) -> tuple[tuple[torch.Tensor, torch.Tensor]]:
126
+ raise NotImplementedError("PowerAttentionDynamicCache does not have a legacy cache equivalent.")
127
+
128
+ @classmethod
129
+ def from_legacy_cache(cls, past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None) -> "PowerAttentionDynamicCache":
130
+ raise NotImplementedError("PowerAttentionDynamicCache does not have a legacy cache equivalent.")
131
+
132
+ def update_state(self, layer_idx: int, new_state: torch.Tensor, new_sum_of_keys: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
133
+ self.states[layer_idx] = new_state
134
+ self.sum_of_keys[layer_idx] = new_sum_of_keys
135
+ return self.states[layer_idx], self.sum_of_keys[layer_idx]
136
+
137
+ def reset(self):
138
+ self.states.zero_()
139
+ self.sum_of_keys.zero_()
140
+ self.key_cache.zero_()
141
+ self.value_cache.zero_()
142
+ self.gate_cache.zero_()
143
+
144
+
145
+
146
+ @use_kernel_forward_from_hub("RMSNorm")
147
+ class BrumbyRMSNorm(nn.Module):
148
+ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
149
+ """
150
+ BrumbyRMSNorm is equivalent to T5LayerNorm
151
+ """
152
+ super().__init__()
153
+ self.weight = nn.Parameter(torch.ones(hidden_size))
154
+ self.variance_epsilon = eps
155
+
156
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
157
+ input_dtype = hidden_states.dtype
158
+ hidden_states = hidden_states.to(torch.float32)
159
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
160
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
161
+ return self.weight * hidden_states.to(input_dtype)
162
+
163
+ def extra_repr(self):
164
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
165
+
166
+
167
+ class BrumbyMLP(nn.Module):
168
+ def __init__(self, config):
169
+ super().__init__()
170
+ self.config = config
171
+ self.hidden_size = config.hidden_size
172
+ self.intermediate_size = config.intermediate_size
173
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
174
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
175
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
176
+ self.act_fn = ACT2FN[config.hidden_act]
177
+
178
+ def forward(self, x):
179
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
180
+ return down_proj
181
+
182
+
183
+ def rotate_half(x):
184
+ """Rotates half the hidden dims of the input."""
185
+ x1 = x[..., : x.shape[-1] // 2]
186
+ x2 = x[..., x.shape[-1] // 2 :]
187
+ return torch.cat((-x2, x1), dim=-1)
188
+
189
+
190
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
191
+ """Applies Rotary Position Embedding to the query and key tensors.
192
+
193
+ Args:
194
+ q (`torch.Tensor`): The query tensor.
195
+ k (`torch.Tensor`): The key tensor.
196
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
197
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
198
+ position_ids (`torch.Tensor`, *optional*):
199
+ Deprecated and unused.
200
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
201
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
202
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
203
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
204
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
205
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
206
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
207
+ Returns:
208
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
209
+ """
210
+ cos = cos.unsqueeze(unsqueeze_dim)
211
+ sin = sin.unsqueeze(unsqueeze_dim)
212
+ q_embed = (q * cos) + (rotate_half(q) * sin)
213
+ k_embed = (k * cos) + (rotate_half(k) * sin)
214
+ return q_embed, k_embed
215
+
216
+
217
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
218
+ """
219
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
220
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
221
+ """
222
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
223
+ if n_rep == 1:
224
+ return hidden_states
225
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
226
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
227
+
228
+
229
+ def eager_attention_forward(
230
+ module: nn.Module,
231
+ query: torch.Tensor,
232
+ key: torch.Tensor,
233
+ value: torch.Tensor,
234
+ attention_mask: Optional[torch.Tensor],
235
+ scaling: float,
236
+ dropout: float = 0.0,
237
+ **kwargs: Unpack[TransformersKwargs],
238
+ ):
239
+ key_states = repeat_kv(key, module.num_key_value_groups)
240
+ value_states = repeat_kv(value, module.num_key_value_groups)
241
+
242
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
243
+ if attention_mask is not None:
244
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
245
+ attn_weights = attn_weights + causal_mask
246
+
247
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
248
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
249
+ attn_output = torch.matmul(attn_weights, value_states)
250
+ attn_output = attn_output.transpose(1, 2).contiguous()
251
+
252
+ return attn_output, attn_weights
253
+
254
+
255
+ class BrumbyAttention(nn.Module):
256
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
257
+
258
+ def __init__(self, config: BrumbyConfig, layer_idx: int):
259
+ super().__init__()
260
+ self.config = config
261
+ self.layer_idx = layer_idx
262
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
263
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
264
+ self.scaling = self.head_dim**-0.5
265
+ self.attention_dropout = config.attention_dropout
266
+ self.is_causal = True
267
+ self.use_exp = config.use_exp
268
+ self.prefill_chunk_size = config.prefill_chunk_size
269
+ self.chunk_size = config.chunk_size
270
+ self.switch_over_seq_len = config.switch_over_seq_len
271
+
272
+ self.q_proj = nn.Linear(
273
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
274
+ )
275
+ self.k_proj = nn.Linear(
276
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
277
+ )
278
+ self.v_proj = nn.Linear(
279
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
280
+ )
281
+ self.g_proj = nn.Linear(
282
+ config.hidden_size, config.num_key_value_heads, bias=config.attention_bias
283
+ )
284
+ self.o_proj = nn.Linear(
285
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
286
+ )
287
+ self.q_norm = BrumbyRMSNorm(self.head_dim, eps=config.rms_norm_eps) # unlike olmo, only on the head dim!
288
+ self.k_norm = BrumbyRMSNorm(self.head_dim, eps=config.rms_norm_eps) # thus post q_norm does not need reshape
289
+ self.sliding_window = config.sliding_window if config.layer_types[layer_idx] == "sliding_attention" else None
290
+
291
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
292
+ def forward(
293
+ self,
294
+ hidden_states: torch.Tensor,
295
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
296
+ attention_mask: Optional[torch.Tensor],
297
+ past_key_values: Optional[PowerAttentionDynamicCache] = None,
298
+ cache_position: Optional[torch.LongTensor] = None,
299
+ **kwargs: Unpack[FlashAttentionKwargs],
300
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
301
+ input_shape = hidden_states.shape[:-1]
302
+ hidden_shape = (*input_shape, -1, self.head_dim)
303
+
304
+ query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
305
+ key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
306
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
307
+ gate_states = self.g_proj(hidden_states).view(hidden_shape[:-1]).transpose(1, 2)
308
+ gate_states = nn.functional.logsigmoid(gate_states.to(torch.float32))
309
+
310
+ cos, sin = position_embeddings
311
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
312
+
313
+ if past_key_values is not None:
314
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
315
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
316
+ key_states, value_states, gate_states, state, sum_of_keys = past_key_values.update_cache(key_states, value_states, gate_states, self.layer_idx, cache_kwargs)
317
+
318
+ if self.use_exp:
319
+ attention_interface: Callable = eager_attention_forward
320
+ if self.config._attn_implementation != "eager":
321
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
322
+
323
+ attn_output, attn_weights = attention_interface(
324
+ self,
325
+ query_states,
326
+ key_states,
327
+ value_states,
328
+ attention_mask,
329
+ dropout=0.0 if not self.training else self.attention_dropout,
330
+ scaling=self.scaling,
331
+ sliding_window=self.sliding_window, # diff with Llama
332
+ **kwargs,
333
+ )
334
+
335
+ elif query_states.shape[2] == 1:
336
+ key_len = key_states.shape[2]
337
+ attn_output, state, sum_of_keys = power_retention_inference(
338
+ query_states.transpose(1, 2),
339
+ key_states.transpose(1, 2),
340
+ value_states.transpose(1, 2),
341
+ gate_states.transpose(1, 2),
342
+ initial_state=state,
343
+ sum_of_keys=sum_of_keys,
344
+ deg=2,
345
+ scale=self.scaling,
346
+ switch_over_seq_len=self.chunk_size,
347
+ )
348
+ if self.chunk_size is not None and key_len >= self.chunk_size:
349
+ past_key_values.clean_cache(self.layer_idx)
350
+ past_key_values.update_state(self.layer_idx, state, sum_of_keys)
351
+
352
+ attn_weights = None
353
+
354
+ else:
355
+ key_len = key_states.shape[2]
356
+ attn_output = power_retention(
357
+ query_states.transpose(1, 2),
358
+ key_states.transpose(1, 2),
359
+ value_states.transpose(1, 2),
360
+ gate_states.transpose(1, 2),
361
+ deg=2,
362
+ scale=self.scaling,
363
+ chunk_size=self.prefill_chunk_size, # enable chunked prefilling by default
364
+ switch_over_seq_len=self.switch_over_seq_len,
365
+ )
366
+ attn_weights = None
367
+
368
+
369
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
370
+ attn_output = self.o_proj(attn_output)
371
+ return attn_output, attn_weights
372
+
373
+
374
+ class BrumbyDecoderLayer(nn.Module):
375
+ def __init__(self, config: BrumbyConfig, layer_idx: int):
376
+ super().__init__()
377
+ self.hidden_size = config.hidden_size
378
+
379
+ self.self_attn = BrumbyAttention(config=config, layer_idx=layer_idx)
380
+
381
+ self.mlp = BrumbyMLP(config)
382
+ self.input_layernorm = BrumbyRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
383
+ self.post_attention_layernorm = BrumbyRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
384
+ self.attention_type = config.layer_types[layer_idx]
385
+
386
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
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_values: Optional[Cache] = None,
393
+ use_cache: Optional[bool] = False,
394
+ cache_position: Optional[torch.LongTensor] = None,
395
+ position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
396
+ **kwargs: Unpack[TransformersKwargs],
397
+ ) -> torch.Tensor:
398
+ residual = hidden_states
399
+ hidden_states = self.input_layernorm(hidden_states)
400
+ # Self Attention
401
+ hidden_states, _ = self.self_attn(
402
+ hidden_states=hidden_states,
403
+ attention_mask=attention_mask,
404
+ position_ids=position_ids,
405
+ past_key_values=past_key_values,
406
+ use_cache=use_cache,
407
+ cache_position=cache_position,
408
+ position_embeddings=position_embeddings,
409
+ **kwargs,
410
+ )
411
+ hidden_states = residual + hidden_states
412
+
413
+ # Fully Connected
414
+ residual = hidden_states
415
+ hidden_states = self.post_attention_layernorm(hidden_states)
416
+ hidden_states = self.mlp(hidden_states)
417
+ hidden_states = residual + hidden_states
418
+ return hidden_states
419
+
420
+
421
+ @auto_docstring
422
+ class BrumbyPreTrainedModel(PreTrainedModel):
423
+ config: BrumbyConfig
424
+ base_model_prefix = "model"
425
+ supports_gradient_checkpointing = True
426
+ _no_split_modules = ["BrumbyDecoderLayer"]
427
+ _skip_keys_device_placement = ["past_key_values"]
428
+ _supports_flash_attn = True
429
+ _supports_sdpa = True
430
+ _supports_flex_attn = True
431
+
432
+ _can_compile_fullgraph = True
433
+ _supports_attention_backend = True
434
+ _can_record_outputs = {
435
+ "hidden_states": BrumbyDecoderLayer,
436
+ "attentions": BrumbyAttention,
437
+ }
438
+
439
+
440
+ class BrumbyRotaryEmbedding(nn.Module):
441
+ inv_freq: torch.Tensor # fix linting for `register_buffer`
442
+
443
+ def __init__(self, config: BrumbyConfig, device=None):
444
+ super().__init__()
445
+ # BC: "rope_type" was originally "type"
446
+ if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
447
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
448
+ else:
449
+ self.rope_type = "default"
450
+ self.max_seq_len_cached = config.max_position_embeddings
451
+ self.original_max_seq_len = config.max_position_embeddings
452
+
453
+ self.config = config
454
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
455
+
456
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
457
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
458
+ self.original_inv_freq = self.inv_freq
459
+
460
+ @torch.no_grad()
461
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
462
+ def forward(self, x, position_ids):
463
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
464
+ position_ids_expanded = position_ids[:, None, :].float()
465
+
466
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
467
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
468
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
469
+ emb = torch.cat((freqs, freqs), dim=-1)
470
+ cos = emb.cos() * self.attention_scaling
471
+ sin = emb.sin() * self.attention_scaling
472
+
473
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
474
+
475
+
476
+ @auto_docstring
477
+ class BrumbyModel(BrumbyPreTrainedModel):
478
+ def __init__(self, config: BrumbyConfig):
479
+ super().__init__(config)
480
+ self.padding_idx = config.pad_token_id
481
+ self.vocab_size = config.vocab_size
482
+
483
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
484
+ self.layers = nn.ModuleList(
485
+ [BrumbyDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
486
+ )
487
+ self.norm = BrumbyRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
488
+ self.rotary_emb = BrumbyRotaryEmbedding(config=config)
489
+ self.gradient_checkpointing = False
490
+ self.has_sliding_layers = "sliding_attention" in self.config.layer_types
491
+
492
+ # Initialize weights and apply final processing
493
+ self.post_init()
494
+
495
+ @check_model_inputs
496
+ @auto_docstring
497
+ def forward(
498
+ self,
499
+ input_ids: Optional[torch.LongTensor] = None,
500
+ attention_mask: Optional[torch.Tensor] = None,
501
+ position_ids: Optional[torch.LongTensor] = None,
502
+ past_key_values: Optional[PowerAttentionDynamicCache] = None,
503
+ inputs_embeds: Optional[torch.FloatTensor] = None,
504
+ use_cache: Optional[bool] = None,
505
+ cache_position: Optional[torch.LongTensor] = None,
506
+ **kwargs: Unpack[TransformersKwargs],
507
+ ) -> BaseModelOutputWithPast:
508
+ if (input_ids is None) ^ (inputs_embeds is not None):
509
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
510
+
511
+ if inputs_embeds is None:
512
+ inputs_embeds = self.embed_tokens(input_ids)
513
+
514
+ if use_cache and past_key_values is None:
515
+ raise ValueError("Brumby requires an initialized `PowerAttentionDynamicCache` to return a cache. None was provided, so no cache will be returned.")
516
+
517
+ if cache_position is None:
518
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
519
+ cache_position = torch.arange(
520
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
521
+ )
522
+
523
+ if position_ids is None:
524
+ position_ids = cache_position.unsqueeze(0)
525
+
526
+ causal_mask = self._update_causal_mask(
527
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions=False
528
+ )
529
+
530
+ hidden_states = inputs_embeds
531
+
532
+ # create position embeddings to be shared across the decoder layers
533
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
534
+
535
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
536
+ hidden_states = decoder_layer(
537
+ hidden_states,
538
+ attention_mask=causal_mask,
539
+ position_ids=position_ids,
540
+ past_key_values=past_key_values,
541
+ use_cache=use_cache,
542
+ cache_position=cache_position,
543
+ position_embeddings=position_embeddings,
544
+ **kwargs,
545
+ )
546
+
547
+ hidden_states = self.norm(hidden_states)
548
+ return BaseModelOutputWithPast(
549
+ last_hidden_state=hidden_states,
550
+ past_key_values=past_key_values if use_cache else None,
551
+ )
552
+
553
+ def _update_causal_mask(
554
+ self,
555
+ attention_mask: torch.Tensor,
556
+ input_tensor: torch.Tensor,
557
+ cache_position: torch.Tensor,
558
+ past_key_values: Cache,
559
+ output_attentions: bool = False,
560
+ ):
561
+ if self.config._attn_implementation == "flash_attention_2":
562
+ if attention_mask is not None and past_key_values is not None:
563
+ is_padding_right = attention_mask[:, -1].sum().item() != input_tensor.size()[0]
564
+ if is_padding_right:
565
+ raise ValueError(
566
+ "You are attempting to perform batched generation with padding_side='right'"
567
+ " this may lead to unexpected behaviour for Flash Attention version of Qwen3. Make sure to "
568
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
569
+ )
570
+ if attention_mask is not None and 0.0 in attention_mask:
571
+ return attention_mask
572
+ return None
573
+
574
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
575
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
576
+ # to infer the attention mask.
577
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
578
+ using_static_cache = isinstance(past_key_values, StaticCache)
579
+ using_sliding_window_cache = isinstance(past_key_values, SlidingWindowCache)
580
+
581
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
582
+ if (
583
+ self.config._attn_implementation == "sdpa"
584
+ and not (using_static_cache or using_sliding_window_cache)
585
+ and not output_attentions
586
+ ):
587
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
588
+ attention_mask,
589
+ inputs_embeds=input_tensor,
590
+ past_key_values_length=past_seen_tokens,
591
+ sliding_window=self.config.sliding_window,
592
+ is_training=self.training,
593
+ ):
594
+ return None
595
+
596
+ dtype, device = input_tensor.dtype, input_tensor.device
597
+ min_dtype = torch.finfo(dtype).min
598
+ sequence_length = input_tensor.shape[1]
599
+ # SlidingWindowCache or StaticCache
600
+ if using_sliding_window_cache or using_static_cache:
601
+ target_length = past_key_values.get_max_cache_shape()
602
+ # DynamicCache or no cache
603
+ else:
604
+ target_length = (
605
+ attention_mask.shape[-1]
606
+ if isinstance(attention_mask, torch.Tensor)
607
+ else past_seen_tokens + sequence_length + 1
608
+ )
609
+
610
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
611
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
612
+ attention_mask,
613
+ sequence_length=sequence_length,
614
+ target_length=target_length,
615
+ dtype=dtype,
616
+ device=device,
617
+ cache_position=cache_position,
618
+ batch_size=input_tensor.shape[0],
619
+ config=self.config,
620
+ past_key_values=past_key_values,
621
+ )
622
+
623
+ if (
624
+ self.config._attn_implementation == "sdpa"
625
+ and attention_mask is not None
626
+ and attention_mask.device.type in ["cuda", "xpu"]
627
+ and not output_attentions
628
+ ):
629
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
630
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
631
+ # Details: https://github.com/pytorch/pytorch/issues/110213
632
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
633
+
634
+ return causal_mask
635
+
636
+ @staticmethod
637
+ def _prepare_4d_causal_attention_mask_with_cache_position(
638
+ attention_mask: torch.Tensor,
639
+ sequence_length: int,
640
+ target_length: int,
641
+ dtype: torch.dtype,
642
+ device: torch.device,
643
+ cache_position: torch.Tensor,
644
+ batch_size: int,
645
+ config: BrumbyConfig,
646
+ past_key_values: Cache,
647
+ ):
648
+ """
649
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
650
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
651
+
652
+ Args:
653
+ attention_mask (`torch.Tensor`):
654
+ 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)`.
655
+ sequence_length (`int`):
656
+ The sequence length being processed.
657
+ target_length (`int`):
658
+ 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.
659
+ dtype (`torch.dtype`):
660
+ The dtype to use for the 4D attention mask.
661
+ device (`torch.device`):
662
+ The device to place the 4D attention mask on.
663
+ cache_position (`torch.Tensor`):
664
+ Indices depicting the position of the input sequence tokens in the sequence.
665
+ batch_size (`torch.Tensor`):
666
+ Batch size.
667
+ config (`Qwen3Config`):
668
+ The model's configuration class
669
+ past_key_values (`Cache`):
670
+ The cache class that is being used currently to generate
671
+ """
672
+ if attention_mask is not None and attention_mask.dim() == 4:
673
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
674
+ causal_mask = attention_mask
675
+ else:
676
+ min_dtype = torch.finfo(dtype).min
677
+ causal_mask = torch.full(
678
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
679
+ )
680
+ diagonal_attend_mask = torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
681
+ if config.sliding_window is not None:
682
+ # if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
683
+ # the check is needed to verify is current checkpoint was trained with sliding window or not
684
+ if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
685
+ sliding_attend_mask = torch.arange(target_length, device=device) <= (
686
+ cache_position.reshape(-1, 1) - config.sliding_window
687
+ )
688
+ diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
689
+ causal_mask *= diagonal_attend_mask
690
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
691
+ if attention_mask is not None:
692
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
693
+ if attention_mask.shape[-1] > target_length:
694
+ attention_mask = attention_mask[:, :target_length]
695
+ mask_length = attention_mask.shape[-1]
696
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
697
+ causal_mask.device
698
+ )
699
+ padding_mask = padding_mask == 0
700
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
701
+ padding_mask, min_dtype
702
+ )
703
+ return causal_mask
704
+
705
+
706
+ @auto_docstring
707
+ class BrumbyForCausalLM(BrumbyPreTrainedModel, GenerationMixin):
708
+ _tied_weights_keys = ["lm_head.weight"]
709
+ _tp_plan = {"lm_head": "colwise_rep"}
710
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
711
+
712
+ def __init__(self, config):
713
+ super().__init__(config)
714
+ self.model = BrumbyModel(config)
715
+ self.vocab_size = config.vocab_size
716
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
717
+
718
+ # Initialize weights and apply final processing
719
+ self.post_init()
720
+
721
+ def prepare_inputs_for_generation(
722
+ self,
723
+ input_ids,
724
+ past_key_values=None,
725
+ attention_mask=None,
726
+ inputs_embeds=None,
727
+ cache_position=None,
728
+ position_ids=None,
729
+ use_cache=True,
730
+ **kwargs,
731
+ ):
732
+ # Copy from https://github.com/huggingface/transformers/blob/main/src/transformers/models/jamba/modeling_jamba.py
733
+ # Overwitten -- uses `past_key_values` as opposed to `past_key_values`
734
+ empty_past_kv = past_key_values is None
735
+
736
+ # First pass
737
+ if not isinstance(past_key_values, PowerAttentionDynamicCache):
738
+ past_key_values = PowerAttentionDynamicCache(self.config, input_ids.shape[0], self.dtype, device=self.device)
739
+
740
+ # If we have cache: let's slice `input_ids` through `cache_position`, to keep only the unprocessed tokens
741
+ # Exception 1: when passing input_embeds, input_ids may be missing entries
742
+ # Exception 2: some generation methods do special slicing of input_ids, so we don't need to do it here
743
+ # Exception 3: with synced GPUs cache_position may go out of bounds, but we only want dummy token in that case.
744
+ # (we can't check exception 3 while compiling)
745
+ if not empty_past_kv:
746
+ if (
747
+ inputs_embeds is not None # Exception 1
748
+ or cache_position[-1] >= input_ids.shape[1] # Exception 3
749
+ ):
750
+ input_ids = input_ids[:, -cache_position.shape[0] :]
751
+ elif input_ids.shape[1] != cache_position.shape[0]: # Default case (the "else", a no op, is Exception 2)
752
+ input_ids = input_ids[:, cache_position]
753
+ else:
754
+ past_key_values = PowerAttentionDynamicCache(
755
+ self.config, input_ids.shape[0], self.dtype, device=self.device
756
+ )
757
+
758
+ if attention_mask is not None and position_ids is None:
759
+ # create position_ids on the fly for batch generation
760
+ position_ids = attention_mask.long().cumsum(-1) - 1
761
+ position_ids.masked_fill_(attention_mask == 0, 1)
762
+ if not empty_past_kv:
763
+ position_ids = position_ids[:, -input_ids.shape[1] :]
764
+
765
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
766
+ if inputs_embeds is not None and empty_past_kv:
767
+ # TODO(pjin): workaround fix for properly extending inputs_embeds;
768
+ # longer term, may be better handled elsewhere in .generate().
769
+ if input_ids is not None and inputs_embeds.shape[1] < input_ids.shape[1]:
770
+ new_token_embeds = self.get_input_embeddings()(input_ids[:,inputs_embeds.shape[1]:])
771
+ inputs_embeds = torch.cat([inputs_embeds, new_token_embeds], dim=1)
772
+ model_inputs = {"inputs_embeds": inputs_embeds}
773
+ else:
774
+ model_inputs = {"input_ids": input_ids.contiguous()} # `contiguous()` needed for compilation use cases
775
+
776
+ model_inputs.update(
777
+ {
778
+ "position_ids": position_ids,
779
+ "past_key_values": past_key_values,
780
+ "use_cache": use_cache,
781
+ "attention_mask": attention_mask,
782
+ "cache_position": cache_position,
783
+ }
784
+ )
785
+ return model_inputs
786
+
787
+ @can_return_tuple
788
+ @auto_docstring
789
+ def forward(
790
+ self,
791
+ input_ids: Optional[torch.LongTensor] = None,
792
+ attention_mask: Optional[torch.Tensor] = None,
793
+ position_ids: Optional[torch.LongTensor] = None,
794
+ past_key_values: Optional[PowerAttentionDynamicCache] = None,
795
+ inputs_embeds: Optional[torch.FloatTensor] = None,
796
+ labels: Optional[torch.LongTensor] = None,
797
+ use_cache: Optional[bool] = None,
798
+ cache_position: Optional[torch.LongTensor] = None,
799
+ logits_to_keep: Union[int, torch.Tensor] = 0,
800
+ **kwargs: Unpack[TransformersKwargs],
801
+ ) -> CausalLMOutputWithPast:
802
+ r"""
803
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
804
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
805
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
806
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
807
+
808
+ Example:
809
+
810
+ ```python
811
+ >>> from transformers import AutoTokenizer, BrumbyForCausalLM
812
+
813
+ >>> model = BrumbyForCausalLM.from_pretrained("Qwen/Brumby-8B")
814
+ >>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Brumby-8B")
815
+
816
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
817
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
818
+
819
+ >>> # Generate
820
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
821
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
822
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
823
+ ```"""
824
+ outputs: BaseModelOutputWithPast = self.model(
825
+ input_ids=input_ids,
826
+ attention_mask=attention_mask,
827
+ position_ids=position_ids,
828
+ past_key_values=past_key_values,
829
+ inputs_embeds=inputs_embeds,
830
+ use_cache=use_cache,
831
+ cache_position=cache_position,
832
+ **kwargs,
833
+ )
834
+
835
+ hidden_states = outputs.last_hidden_state
836
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
837
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
838
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
839
+
840
+ loss = None
841
+ if labels is not None:
842
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
843
+
844
+ return CausalLMOutputWithPast(
845
+ loss=loss,
846
+ logits=logits,
847
+ past_key_values=outputs.past_key_values,
848
+ hidden_states=outputs.hidden_states,
849
+ attentions=outputs.attentions,
850
+ )
851
+
852
+
853
+ __all__ = [
854
+ "BrumbyForCausalLM",
855
+ "BrumbyPreTrainedModel",
856
+ "BrumbyModel",
857
+ ]
quant_log.csv ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ layer,module,loss,samples,damp,time
2
+ 0,self_attn.v_proj,0.0000000055,0.05000,4.851
3
+ 0,self_attn.k_proj,0.0000000067,0.05000,4.868
4
+ 0,self_attn.q_proj,0.0000000245,0.05000,4.875
5
+ 0,self_attn.o_proj,0.0000001023,0.05000,1.463
6
+ 0,mlp.gate_proj,0.0000014832,0.05000,3.275
7
+ 0,mlp.up_proj,0.0000012088,0.05000,3.334
8
+ 0,mlp.down_proj,0.0000007021,0.05000,5.384
9
+ 1,self_attn.q_proj,0.0000000516,0.05000,4.584
10
+ 1,self_attn.v_proj,0.0000000140,0.05000,4.683
11
+ 1,self_attn.k_proj,0.0000000128,0.05000,4.723
12
+ 1,self_attn.o_proj,0.0000001024,0.05000,1.334
13
+ 1,mlp.up_proj,0.0000235446,0.05000,3.642
14
+ 1,mlp.gate_proj,0.0000679487,0.05000,3.677
15
+ 1,mlp.down_proj,0.0000010552,0.05000,5.334
16
+ 2,self_attn.k_proj,0.0000000361,0.05000,4.120
17
+ 2,self_attn.v_proj,0.0000000386,0.05000,4.189
18
+ 2,self_attn.q_proj,0.0000001411,0.05000,4.244
19
+ 2,self_attn.o_proj,0.0000002282,0.05000,1.332
20
+ 2,mlp.gate_proj,0.0000977210,0.05000,3.152
21
+ 2,mlp.up_proj,0.0000492783,0.05000,3.153
22
+ 2,mlp.down_proj,0.0000008231,0.05000,5.410
23
+ 3,self_attn.q_proj,0.0000003171,0.05000,4.748
24
+ 3,self_attn.k_proj,0.0000000801,0.05000,4.758
25
+ 3,self_attn.v_proj,0.0000000896,0.05000,4.779
26
+ 3,self_attn.o_proj,0.0000002193,0.05000,1.414
27
+ 3,mlp.gate_proj,0.0001480885,0.05000,3.153
28
+ 3,mlp.up_proj,0.0000745903,0.05000,3.224
29
+ 3,mlp.down_proj,0.0000013200,0.05000,5.582
30
+ 4,self_attn.v_proj,0.0000001349,0.05000,5.075
31
+ 4,self_attn.q_proj,0.0000004968,0.05000,5.101
32
+ 4,self_attn.k_proj,0.0000001217,0.05000,5.105
33
+ 4,self_attn.o_proj,0.0000003706,0.05000,1.499
34
+ 4,mlp.up_proj,0.0001282589,0.05000,3.353
35
+ 4,mlp.gate_proj,0.0002110812,0.05000,3.373
36
+ 4,mlp.down_proj,0.0000014401,0.05000,5.379
37
+ 5,self_attn.q_proj,0.0000005028,0.05000,4.952
38
+ 5,self_attn.v_proj,0.0000001383,0.05000,4.969
39
+ 5,self_attn.k_proj,0.0000001241,0.05000,4.978
40
+ 5,self_attn.o_proj,0.0000003825,0.05000,1.373
41
+ 5,mlp.up_proj,0.0000865598,0.05000,3.568
42
+ 5,mlp.gate_proj,0.0001970606,0.05000,3.592
43
+ 5,mlp.down_proj,0.0000036706,0.05000,5.314
44
+ 6,self_attn.v_proj,0.0000002469,0.05000,4.978
45
+ 6,self_attn.q_proj,0.0000008867,0.05000,5.061
46
+ 6,self_attn.k_proj,0.0000002098,0.05000,5.067
47
+ 6,self_attn.o_proj,0.0000005215,0.05000,1.377
48
+ 6,mlp.up_proj,0.0001740953,0.05000,2.960
49
+ 6,mlp.gate_proj,0.0003093244,0.05000,3.049
50
+ 6,mlp.down_proj,0.0000451711,0.05000,5.501
51
+ 7,self_attn.q_proj,0.0000032589,0.05000,4.941
52
+ 7,self_attn.k_proj,0.0000007494,0.05000,4.953
53
+ 7,self_attn.v_proj,0.0000008548,0.05000,4.969
54
+ 7,self_attn.o_proj,0.0000011350,0.05000,1.371
55
+ 7,mlp.gate_proj,0.0002542938,0.05000,3.356
56
+ 7,mlp.up_proj,0.0001292021,0.05000,3.370
57
+ 7,mlp.down_proj,0.0000053761,0.05000,5.684
58
+ 8,self_attn.v_proj,0.0000008264,0.05000,4.899
59
+ 8,self_attn.q_proj,0.0000030318,0.05000,4.924
60
+ 8,self_attn.k_proj,0.0000007100,0.05000,4.975
61
+ 8,self_attn.o_proj,0.0000013708,0.05000,1.409
62
+ 8,mlp.up_proj,0.0000463701,0.05000,3.645
63
+ 8,mlp.gate_proj,0.0000779276,0.05000,3.699
64
+ 8,mlp.down_proj,0.0000070508,0.05000,5.465
65
+ 9,self_attn.v_proj,0.0000006791,0.05000,5.006
66
+ 9,self_attn.q_proj,0.0000025509,0.05000,5.023
67
+ 9,self_attn.k_proj,0.0000006144,0.05000,5.032
68
+ 9,self_attn.o_proj,0.0000013103,0.05000,1.424
69
+ 9,mlp.gate_proj,0.0000426071,0.05000,3.332
70
+ 9,mlp.up_proj,0.0000384853,0.05000,3.368
71
+ 9,mlp.down_proj,0.0000094974,0.05000,5.585
72
+ 10,self_attn.k_proj,0.0000008871,0.05000,5.058
73
+ 10,self_attn.v_proj,0.0000010250,0.05000,5.070
74
+ 10,self_attn.q_proj,0.0000039080,0.05000,5.100
75
+ 10,self_attn.o_proj,0.0000023923,0.05000,1.394
76
+ 10,mlp.gate_proj,0.0000476698,0.05000,2.910
77
+ 10,mlp.up_proj,0.0000438941,0.05000,2.918
78
+ 10,mlp.down_proj,0.0000099568,0.05000,5.422
79
+ 11,self_attn.v_proj,0.0000016619,0.05000,5.104
80
+ 11,self_attn.q_proj,0.0000061273,0.05000,5.127
81
+ 11,self_attn.k_proj,0.0000014110,0.05000,5.151
82
+ 11,self_attn.o_proj,0.0000034863,0.05000,1.411
83
+ 11,mlp.up_proj,0.0000549275,0.05000,3.648
84
+ 11,mlp.gate_proj,0.0000592392,0.05000,3.697
85
+ 11,mlp.down_proj,0.0000136331,0.05000,5.316
86
+ 12,self_attn.k_proj,0.0000015385,0.05000,4.950
87
+ 12,self_attn.v_proj,0.0000017779,0.05000,4.997
88
+ 12,self_attn.q_proj,0.0000064274,0.05000,5.019
89
+ 12,self_attn.o_proj,0.0000026011,0.05000,1.423
90
+ 12,mlp.gate_proj,0.0000721614,0.05000,3.257
91
+ 12,mlp.up_proj,0.0000664742,0.05000,3.284
92
+ 12,mlp.down_proj,0.0000165714,0.05000,5.587
93
+ 13,self_attn.v_proj,0.0000035299,0.05000,4.510
94
+ 13,self_attn.q_proj,0.0000127921,0.05000,4.531
95
+ 13,self_attn.k_proj,0.0000029702,0.05000,4.564
96
+ 13,self_attn.o_proj,0.0000040227,0.05000,1.394
97
+ 13,mlp.up_proj,0.0000723846,0.05000,2.925
98
+ 13,mlp.gate_proj,0.0000838850,0.05000,2.940
99
+ 13,mlp.down_proj,0.0000187251,0.05000,5.496
100
+ 14,self_attn.v_proj,0.0000024263,0.05000,4.790
101
+ 14,self_attn.q_proj,0.0000085204,0.05000,4.817
102
+ 14,self_attn.k_proj,0.0000020249,0.05000,4.848
103
+ 14,self_attn.o_proj,0.0000040741,0.05000,1.353
104
+ 14,mlp.gate_proj,0.0000798361,0.05000,2.961
105
+ 14,mlp.up_proj,0.0000716579,0.05000,2.974
106
+ 14,mlp.down_proj,0.0000192025,0.05000,5.455
107
+ 15,self_attn.v_proj,0.0000024046,0.05000,4.509
108
+ 15,self_attn.k_proj,0.0000021407,0.05000,4.558
109
+ 15,self_attn.q_proj,0.0000092248,0.05000,4.569
110
+ 15,self_attn.o_proj,0.0000045808,0.05000,1.348
111
+ 15,mlp.up_proj,0.0000751190,0.05000,3.045
112
+ 15,mlp.gate_proj,0.0000782121,0.05000,3.079
113
+ 15,mlp.down_proj,0.0000209370,0.05000,5.471
114
+ 16,self_attn.q_proj,0.0000100945,0.05000,5.142
115
+ 16,self_attn.v_proj,0.0000027845,0.05000,5.142
116
+ 16,self_attn.k_proj,0.0000023761,0.05000,5.241
117
+ 16,self_attn.o_proj,0.0000062379,0.05000,1.380
118
+ 16,mlp.up_proj,0.0000748809,0.05000,2.870
119
+ 16,mlp.gate_proj,0.0000727667,0.05000,2.884
120
+ 16,mlp.down_proj,0.0000219730,0.05000,5.353
121
+ 17,self_attn.k_proj,0.0000028254,0.05000,4.584
122
+ 17,self_attn.q_proj,0.0000126655,0.05000,4.615
123
+ 17,self_attn.v_proj,0.0000032815,0.05000,4.642
124
+ 17,self_attn.o_proj,0.0000061028,0.05000,1.371
125
+ 17,mlp.gate_proj,0.0000801209,0.05000,3.312
126
+ 17,mlp.up_proj,0.0000837841,0.05000,3.340
127
+ 17,mlp.down_proj,0.0000245772,0.05000,5.519
128
+ 18,self_attn.v_proj,0.0000047651,0.05000,4.578
129
+ 18,self_attn.k_proj,0.0000041778,0.05000,4.587
130
+ 18,self_attn.q_proj,0.0000184517,0.05000,4.621
131
+ 18,self_attn.o_proj,0.0000063895,0.05000,1.366
132
+ 18,mlp.up_proj,0.0000915147,0.05000,3.025
133
+ 18,mlp.gate_proj,0.0000842209,0.05000,3.032
134
+ 18,mlp.down_proj,0.0000275443,0.05000,5.559
135
+ 19,self_attn.k_proj,0.0000049127,0.05000,4.855
136
+ 19,self_attn.v_proj,0.0000055556,0.05000,4.940
137
+ 19,self_attn.q_proj,0.0000216752,0.05000,4.962
138
+ 19,self_attn.o_proj,0.0000083279,0.05000,1.398
139
+ 19,mlp.up_proj,0.0001011631,0.05000,2.898
140
+ 19,mlp.gate_proj,0.0000937019,0.05000,2.930
141
+ 19,mlp.down_proj,0.0000327259,0.05000,5.399
142
+ 20,self_attn.v_proj,0.0000109982,0.05000,4.754
143
+ 20,self_attn.k_proj,0.0000086623,0.05000,4.805
144
+ 20,self_attn.q_proj,0.0000405637,0.05000,4.808
145
+ 20,self_attn.o_proj,0.0000105337,0.05000,1.392
146
+ 20,mlp.gate_proj,0.0000998617,0.05000,3.189
147
+ 20,mlp.up_proj,0.0001093770,0.05000,3.217
148
+ 20,mlp.down_proj,0.0000415528,0.05000,5.438
149
+ 21,self_attn.k_proj,0.0000117670,0.05000,4.439
150
+ 21,self_attn.q_proj,0.0000514724,0.05000,4.453
151
+ 21,self_attn.v_proj,0.0000140596,0.05000,4.516
152
+ 21,self_attn.o_proj,0.0000151081,0.05000,1.453
153
+ 21,mlp.gate_proj,0.0001088591,0.05000,2.926
154
+ 21,mlp.up_proj,0.0001167877,0.05000,2.938
155
+ 21,mlp.down_proj,0.0000477426,0.05000,5.551
156
+ 22,self_attn.v_proj,0.0000117180,0.05000,4.538
157
+ 22,self_attn.k_proj,0.0000094837,0.05000,4.573
158
+ 22,self_attn.q_proj,0.0000441959,0.05000,4.617
159
+ 22,self_attn.o_proj,0.0000190037,0.05000,1.410
160
+ 22,mlp.up_proj,0.0001366769,0.05000,3.587
161
+ 22,mlp.gate_proj,0.0001259929,0.05000,3.622
162
+ 22,mlp.down_proj,0.0000632469,0.05000,5.323
163
+ 23,self_attn.v_proj,0.0000206423,0.05000,5.066
164
+ 23,self_attn.q_proj,0.0000767674,0.05000,5.099
165
+ 23,self_attn.k_proj,0.0000157870,0.05000,5.111
166
+ 23,self_attn.o_proj,0.0000160790,0.05000,1.398
167
+ 23,mlp.up_proj,0.0001518091,0.05000,3.378
168
+ 23,mlp.gate_proj,0.0001383609,0.05000,3.395
169
+ 23,mlp.down_proj,0.0000856998,0.05000,5.398
170
+ 24,self_attn.v_proj,0.0000329967,0.05000,5.030
171
+ 24,self_attn.k_proj,0.0000237478,0.05000,5.054
172
+ 24,self_attn.q_proj,0.0001217306,0.05000,5.056
173
+ 24,self_attn.o_proj,0.0000220392,0.05000,1.360
174
+ 24,mlp.gate_proj,0.0001632924,0.05000,3.625
175
+ 24,mlp.up_proj,0.0001751961,0.05000,3.657
176
+ 24,mlp.down_proj,0.0000941419,0.05000,5.674
177
+ 25,self_attn.k_proj,0.0000201400,0.05000,4.789
178
+ 25,self_attn.q_proj,0.0000949212,0.05000,4.936
179
+ 25,self_attn.v_proj,0.0000253956,0.05000,4.953
180
+ 25,self_attn.o_proj,0.0000235002,0.05000,1.350
181
+ 25,mlp.up_proj,0.0002028768,0.05000,3.754
182
+ 25,mlp.gate_proj,0.0001922596,0.05000,3.767
183
+ 25,mlp.down_proj,0.0001267621,0.05000,5.595
184
+ 26,self_attn.k_proj,0.0000225750,0.05000,4.881
185
+ 26,self_attn.v_proj,0.0000295418,0.05000,4.921
186
+ 26,self_attn.q_proj,0.0001108223,0.05000,4.949
187
+ 26,self_attn.o_proj,0.0000265471,0.05000,1.385
188
+ 26,mlp.up_proj,0.0002334800,0.05000,3.388
189
+ 26,mlp.gate_proj,0.0002268478,0.05000,3.422
190
+ 26,mlp.down_proj,0.0001893703,0.05000,5.634
191
+ 27,self_attn.q_proj,0.0001638606,0.05000,5.063
192
+ 27,self_attn.v_proj,0.0000431965,0.05000,5.074
193
+ 27,self_attn.k_proj,0.0000341267,0.05000,5.090
194
+ 27,self_attn.o_proj,0.0000498931,0.05000,1.395
195
+ 27,mlp.up_proj,0.0002877421,0.05000,3.456
196
+ 27,mlp.gate_proj,0.0002798097,0.05000,3.483
197
+ 27,mlp.down_proj,0.0002758613,0.05000,5.413
198
+ 28,self_attn.q_proj,0.0002983511,0.05000,5.019
199
+ 28,self_attn.k_proj,0.0000565795,0.05000,5.021
200
+ 28,self_attn.v_proj,0.0000813798,0.05000,5.037
201
+ 28,self_attn.o_proj,0.0000459752,0.05000,1.567
202
+ 28,mlp.gate_proj,0.0003511385,0.05000,3.554
203
+ 28,mlp.up_proj,0.0003660403,0.05000,3.605
204
+ 28,mlp.down_proj,0.0003470357,0.05000,5.451
205
+ 29,self_attn.v_proj,0.0000988175,0.05000,4.698
206
+ 29,self_attn.q_proj,0.0003714425,0.05000,4.765
207
+ 29,self_attn.k_proj,0.0000788545,0.05000,4.812
208
+ 29,self_attn.o_proj,0.0000517854,0.05000,1.332
209
+ 29,mlp.up_proj,0.0004072312,0.05000,3.735
210
+ 29,mlp.gate_proj,0.0003876266,0.05000,3.765
211
+ 29,mlp.down_proj,0.0004905408,0.05000,5.507
212
+ 30,self_attn.q_proj,0.0005447937,0.05000,4.696
213
+ 30,self_attn.v_proj,0.0001534902,0.05000,4.769
214
+ 30,self_attn.k_proj,0.0001148308,0.05000,4.786
215
+ 30,self_attn.o_proj,0.0000775836,0.05000,1.395
216
+ 30,mlp.gate_proj,0.0004827204,0.05000,3.138
217
+ 30,mlp.up_proj,0.0005053384,0.05000,3.150
218
+ 30,mlp.down_proj,0.0005774746,0.05000,5.607
219
+ 31,self_attn.k_proj,0.0001142838,0.05000,4.573
220
+ 31,self_attn.v_proj,0.0001417302,0.05000,4.617
221
+ 31,self_attn.q_proj,0.0005521921,0.05000,4.641
222
+ 31,self_attn.o_proj,0.0000683407,0.05000,1.471
223
+ 31,mlp.gate_proj,0.0005245574,0.05000,3.371
224
+ 31,mlp.up_proj,0.0005602224,0.05000,3.391
225
+ 31,mlp.down_proj,0.0007208518,0.05000,5.466
226
+ 32,self_attn.k_proj,0.0002052982,0.05000,4.842
227
+ 32,self_attn.q_proj,0.0009621031,0.05000,4.916
228
+ 32,self_attn.v_proj,0.0002829138,0.05000,4.930
229
+ 32,self_attn.o_proj,0.0000929007,0.05000,1.420
230
+ 32,mlp.gate_proj,0.0005781620,0.05000,3.086
231
+ 32,mlp.up_proj,0.0006268456,0.05000,3.146
232
+ 32,mlp.down_proj,0.0007982043,0.05000,5.426
233
+ 33,self_attn.v_proj,0.0003873876,0.05000,4.661
234
+ 33,self_attn.q_proj,0.0013329935,0.05000,4.679
235
+ 33,self_attn.k_proj,0.0002684569,0.05000,4.699
236
+ 33,self_attn.o_proj,0.0001004743,0.05000,1.397
237
+ 33,mlp.gate_proj,0.0006186912,0.05000,3.072
238
+ 33,mlp.up_proj,0.0006873148,0.05000,3.080
239
+ 33,mlp.down_proj,0.0008831521,0.05000,5.923
240
+ 34,self_attn.k_proj,0.0004681831,0.05000,4.314
241
+ 34,self_attn.q_proj,0.0022188602,0.05000,4.330
242
+ 34,self_attn.v_proj,0.0006818156,0.05000,4.369
243
+ 34,self_attn.o_proj,0.0001390811,0.05000,1.400
244
+ 34,mlp.gate_proj,0.0006815079,0.05000,2.850
245
+ 34,mlp.up_proj,0.0007714760,0.05000,2.856
246
+ 34,mlp.down_proj,0.0010444433,0.05000,5.671
247
+ 35,self_attn.v_proj,0.0009464067,0.05000,4.743
248
+ 35,self_attn.q_proj,0.0028209405,0.05000,4.756
249
+ 35,self_attn.k_proj,0.0005987322,0.05000,4.770
250
+ 35,self_attn.o_proj,0.0001368956,0.05000,1.364
251
+ 35,mlp.up_proj,0.0008114978,0.05000,3.085
252
+ 35,mlp.gate_proj,0.0007047556,0.05000,3.087
253
+ 35,mlp.down_proj,0.0012339309,0.05000,5.406
254
+ 36,self_attn.k_proj,0.0005470300,0.05000,4.830
255
+ 36,self_attn.q_proj,0.0024462599,0.05000,4.882
256
+ 36,self_attn.v_proj,0.0008094013,0.05000,4.888
257
+ 36,self_attn.o_proj,0.0002597887,0.05000,1.454
258
+ 36,mlp.up_proj,0.0008480489,0.05000,3.371
259
+ 36,mlp.gate_proj,0.0007133146,0.05000,3.388
260
+ 36,mlp.down_proj,0.0015971187,0.05000,5.952
261
+ 37,self_attn.q_proj,0.0035302981,0.05000,4.597
262
+ 37,self_attn.k_proj,0.0007176153,0.05000,4.631
263
+ 37,self_attn.v_proj,0.0012357151,0.05000,4.644
264
+ 37,self_attn.o_proj,0.0002945466,0.05000,1.404
265
+ 37,mlp.gate_proj,0.0007103522,0.05000,3.077
266
+ 37,mlp.up_proj,0.0008592182,0.05000,3.084
267
+ 37,mlp.down_proj,0.0022288549,0.05000,5.345
268
+ 38,self_attn.v_proj,0.0011880093,0.05000,4.358
269
+ 38,self_attn.q_proj,0.0031908930,0.05000,4.372
270
+ 38,self_attn.k_proj,0.0006751707,0.05000,4.399
271
+ 38,self_attn.o_proj,0.0003943942,0.05000,1.340
272
+ 38,mlp.gate_proj,0.0008062866,0.05000,3.148
273
+ 38,mlp.up_proj,0.0009217460,0.05000,3.174
274
+ 38,mlp.down_proj,0.0034524150,0.05000,5.362
275
+ 39,self_attn.k_proj,0.0002554454,0.05000,4.257
276
+ 39,self_attn.v_proj,0.0003735272,0.05000,4.294
277
+ 39,self_attn.q_proj,0.0012166777,0.05000,4.295
278
+ 39,self_attn.o_proj,0.0003847522,0.05000,1.344
279
+ 39,mlp.gate_proj,0.0009165438,0.05000,3.561
280
+ 39,mlp.up_proj,0.0010139998,0.05000,3.578
281
+ 39,mlp.down_proj,0.0066875947,0.05000,5.467
quantize_config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bits": 4,
3
+ "group_size": 32,
4
+ "desc_act": false,
5
+ "sym": true,
6
+ "lm_head": false,
7
+ "quant_method": "gptq",
8
+ "checkpoint_format": "gptq",
9
+ "pack_dtype": "int32",
10
+ "meta": {
11
+ "quantizer": [
12
+ "gptqmodel:5.1.0-dev"
13
+ ],
14
+ "uri": "https://github.com/modelcloud/gptqmodel",
15
+ "damp_percent": 0.05,
16
+ "damp_auto_increment": 0.01,
17
+ "static_groups": false,
18
+ "true_sequential": true,
19
+ "mse": 0.0,
20
+ "v2": false,
21
+ "v2_alpha": 0.25,
22
+ "act_group_aware": true
23
+ },
24
+ "pack_impl": "cpu"
25
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ],
17
+ "eos_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": "<|endoftext|>"
25
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
3
+ size 11422654
tokenizer_config.json ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|endoftext|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "model_max_length": 131072,
235
+ "pad_token": "<|endoftext|>",
236
+ "split_special_tokens": false,
237
+ "tokenizer_class": "Qwen2Tokenizer",
238
+ "unk_token": null
239
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff