CodeIsAbstract commited on
Commit
66f7fef
·
verified ·
1 Parent(s): e2f21bb

Training in progress, step 100, checkpoint

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
+ last-checkpoint/tokenizer.json filter=lfs diff=lfs merge=lfs -text
last-checkpoint/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
last-checkpoint/chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# 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>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\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" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
last-checkpoint/config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "HybridTimeScaleLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "model.HybridTimeScaleConfig",
7
+ "AutoModelForCausalLM": "model.HybridTimeScaleLM"
8
+ },
9
+ "bos_token_id": 1,
10
+ "chunk_size": 128,
11
+ "dropout": 0.0,
12
+ "dtype": "bfloat16",
13
+ "eos_token_id": 2,
14
+ "latent_dim": 1344,
15
+ "layer_types": [
16
+ "linear",
17
+ "linear",
18
+ "linear",
19
+ "softmax",
20
+ "linear",
21
+ "linear",
22
+ "linear",
23
+ "softmax",
24
+ "linear",
25
+ "linear",
26
+ "linear",
27
+ "softmax",
28
+ "linear",
29
+ "linear",
30
+ "linear",
31
+ "softmax",
32
+ "linear",
33
+ "linear",
34
+ "linear",
35
+ "softmax",
36
+ "linear",
37
+ "linear",
38
+ "linear",
39
+ "softmax",
40
+ "linear",
41
+ "linear",
42
+ "linear",
43
+ "softmax",
44
+ "linear",
45
+ "linear",
46
+ "linear",
47
+ "softmax"
48
+ ],
49
+ "model_type": "hybrid_timescale_lm",
50
+ "num_layers": 32,
51
+ "num_modes": 16,
52
+ "pad_token_id": 0,
53
+ "time_scale": 128.0,
54
+ "transformers_version": "4.56.0",
55
+ "vocab_size": 151665
56
+ }
last-checkpoint/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 0,
6
+ "transformers_version": "4.56.0"
7
+ }
last-checkpoint/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
last-checkpoint/model.py ADDED
@@ -0,0 +1,656 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HybridTimeScaleLM – Optimized Linear Model Architecture (model_linear.py)
3
+ ========================================================================
4
+ Optimized alternative to `model.py` featuring Chunked Parallel Linear Attention.
5
+ - VRAM Growth: Strictly linear O(S) scaling with sequence length.
6
+ - Speed & Parallelism: Fully vectorized GPU kernel math, maintaining parallel execution speed.
7
+ - Context Length: Designed for long token lengths (2048, 4096, 8192, 16384+).
8
+ - Weight & State-Dict Compatibility: 100% drop-in replacement for `model.py` checkpoints.
9
+ """
10
+
11
+ import math
12
+ import os
13
+ import torch
14
+ import torch.nn as nn
15
+ import torch.nn.functional as F
16
+ from torch.utils.checkpoint import checkpoint
17
+ from transformers import (
18
+ AutoConfig,
19
+ AutoModelForCausalLM,
20
+ GenerationMixin,
21
+ PretrainedConfig,
22
+ PreTrainedModel,
23
+ )
24
+ from transformers.modeling_outputs import CausalLMOutputWithPast, ModelOutput
25
+ from dataclasses import dataclass
26
+ from typing import Optional, Tuple, List
27
+
28
+ @dataclass(init=False)
29
+ class HybridTimeScaleOutput(ModelOutput):
30
+ """
31
+ Base class for model's outputs that also contains a past key/values.
32
+ """
33
+ loss: Optional[torch.FloatTensor] = None
34
+ logits: torch.FloatTensor = None
35
+ past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None
36
+ hidden_states: Optional[Tuple[torch.FloatTensor]] = None
37
+ attentions: Optional[Tuple[torch.FloatTensor]] = None
38
+ last_hidden_state: Optional[torch.FloatTensor] = None
39
+ # Global default tokenizer ID
40
+ GLOBAL_TOKENIZER_ID = "mistralai/Mistral-7B-v0.3"
41
+
42
+ # Prevent protobuf/sentencepiece version conflicts when AutoTokenizer loads Mistral/Llama tokenizers on macOS
43
+ os.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")
44
+
45
+ # Ensure `transformers` automatically strips `_orig_mod.` prefixes left by `torch.compile` / `Trainer` wrappers
46
+ # (Note: _orig_mod. prefixes should be stripped from the safetensors file directly before uploading, not patched at runtime).
47
+
48
+
49
+
50
+ # ──────────────────────────────────────────────────────────────────────
51
+ # Config
52
+ # ──────────────────────────────────────────────────────────────────────
53
+
54
+ class HybridTimeScaleConfig(PretrainedConfig):
55
+ model_type = "hybrid_timescale_lm"
56
+
57
+ def __init__(
58
+ self,
59
+ vocab_size=50304,
60
+ latent_dim=768,
61
+ num_layers=12,
62
+ num_modes=64,
63
+ layer_types=None,
64
+ time_scale=128.0,
65
+ dropout=0.05,
66
+ pad_token_id=0,
67
+ bos_token_id=1,
68
+ eos_token_id=2,
69
+ tie_word_embeddings=True,
70
+ chunk_size=128,
71
+ **kwargs,
72
+ ):
73
+ self.vocab_size = vocab_size
74
+ self.latent_dim = latent_dim
75
+ self.num_layers = num_layers
76
+ self.num_modes = num_modes
77
+ self.time_scale = time_scale
78
+ self.dropout = dropout
79
+ self.chunk_size = chunk_size
80
+
81
+ if layer_types is None:
82
+ layer_types = [
83
+ "softmax" if (i % 4 == 3) else "linear"
84
+ for i in range(num_layers)
85
+ ]
86
+ assert len(layer_types) == num_layers, (
87
+ f"layer_types length ({len(layer_types)}) must equal num_layers ({num_layers})"
88
+ )
89
+ self.layer_types = layer_types
90
+
91
+ super().__init__(
92
+ pad_token_id=pad_token_id,
93
+ bos_token_id=bos_token_id,
94
+ eos_token_id=eos_token_id,
95
+ tie_word_embeddings=tie_word_embeddings,
96
+ **kwargs,
97
+ )
98
+
99
+
100
+ # ──────────────────────────────────────────────────────────────────────
101
+ # Optimized Chunked Parallel Linear Fourier Mixer
102
+ # ──────────────────────────────────────────────────────────────────────
103
+
104
+ class LinearFourierMixer(nn.Module):
105
+ """
106
+ Optimized Linear Fourier Mixer using Chunked Parallel Linear Attention.
107
+ Computes intra-chunk parallel attention and inter-chunk cumulative state scan
108
+ without allocating large O(S^2) attention matrices or quadratic memory.
109
+ """
110
+ def __init__(self, channels, num_modes=64, num_heads=12, time_scale=128, dropout=0.05, chunk_size=128):
111
+ super().__init__()
112
+ assert channels % num_heads == 0, (
113
+ f"channels ({channels}) must be perfectly divisible by num_heads ({num_heads})"
114
+ )
115
+ self.channels = channels
116
+ self.num_modes = num_modes
117
+ self.num_heads = num_heads
118
+ self.head_dim = channels // num_heads
119
+ self.time_scale = time_scale
120
+ self.chunk_size = chunk_size
121
+
122
+ freq_bands = torch.exp(torch.linspace(math.log(0.0001), math.log(num_modes), num_modes))
123
+ self.num_modes = freq_bands.shape[0]
124
+ self.register_buffer("frequencies", freq_bands)
125
+
126
+ self.q_proj = nn.Linear(channels, self.num_heads * self.num_modes)
127
+ self.k_proj = nn.Linear(channels, self.num_heads * self.num_modes)
128
+ self.v_proj = nn.Linear(channels, channels)
129
+ self.proj_v2 = nn.Linear(channels, channels)
130
+ self.out_proj = nn.Linear(channels, channels)
131
+ self.activation = nn.SiLU()
132
+ self.norm_in = nn.LayerNorm(channels)
133
+ self.norm_out = nn.LayerNorm(channels)
134
+ self.dropout = nn.Dropout(dropout)
135
+
136
+ def forward(self, x, attention_mask=None, position_ids=None, past_key_value=None):
137
+ B, seq_len, C = x.shape
138
+ norm_x = self.norm_in(x)
139
+
140
+ Q = F.elu(self.q_proj(norm_x)).view(B, seq_len, self.num_heads, self.num_modes) + 1.0
141
+ K = F.elu(self.k_proj(norm_x)).view(B, seq_len, self.num_heads, self.num_modes) + 1.0
142
+
143
+ v1 = self.v_proj(norm_x)
144
+ v2 = self.activation(self.proj_v2(norm_x))
145
+
146
+ if position_ids is None:
147
+ position_ids = torch.arange(seq_len, device=x.device, dtype=torch.long).unsqueeze(0)
148
+
149
+ t = (position_ids.unsqueeze(-1).to(dtype=x.dtype) / self.time_scale)
150
+ omega_t = 2 * math.pi * t * self.frequencies
151
+ U = torch.cos(omega_t).unsqueeze(2) # [B, S, 1, M]
152
+ V = torch.sin(omega_t).unsqueeze(2) # [B, S, 1, M]
153
+
154
+ Q_cos = Q * U
155
+ Q_sin = Q * V
156
+ K_cos = K * U
157
+ K_sin = K * V
158
+
159
+ Q_rot = torch.cat([Q_cos, Q_sin], dim=-1) # [B, seq_len, H, 2M]
160
+ K_rot = torch.cat([K_cos, K_sin], dim=-1) # [B, seq_len, H, 2M]
161
+ v1_heads = v1.view(B, seq_len, self.num_heads, self.head_dim)
162
+
163
+ if attention_mask is not None:
164
+ if attention_mask.shape[1] > seq_len:
165
+ mask = attention_mask[:, -seq_len:].unsqueeze(-1).unsqueeze(-1).to(dtype=x.dtype)
166
+ else:
167
+ mask = attention_mask.unsqueeze(-1).unsqueeze(-1).to(dtype=x.dtype)
168
+ K_rot = K_rot * mask
169
+ v1_heads = v1_heads * mask
170
+
171
+ scale = 1.0 / math.sqrt(self.num_modes * 2)
172
+
173
+ orig_dtype = Q_rot.dtype
174
+
175
+ Q_rot_f = Q_rot.view(B, seq_len, self.num_heads, 2 * self.num_modes).transpose(1, 2).float()
176
+ K_rot_f = K_rot.view(B, seq_len, self.num_heads, 2 * self.num_modes).transpose(1, 2).float()
177
+ v1_f = v1_heads.view(B, seq_len, self.num_heads, self.head_dim).transpose(1, 2).float()
178
+
179
+ if past_key_value is not None:
180
+ # Recurrent O(1) step
181
+ cum_kv_past, cum_k_past = past_key_value
182
+
183
+ curr_kv = torch.matmul(K_rot_f.transpose(-1, -2), v1_f)
184
+ curr_k = K_rot_f.sum(dim=-2, keepdim=True).transpose(-1, -2) # [B, H, 2M, 1]
185
+
186
+ cum_kv_new = cum_kv_past + curr_kv
187
+ cum_k_new = cum_k_past + curr_k
188
+
189
+ num_total = torch.matmul(Q_rot_f, cum_kv_new) * scale
190
+ denom_total = torch.matmul(Q_rot_f, cum_k_new) * scale
191
+
192
+ denom_total = denom_total.clamp(min=1e-4)
193
+ v1_token_mixed = (num_total / denom_total)
194
+ v1_token_mixed = torch.clamp(v1_token_mixed, min=-100.0, max=100.0)
195
+ v1_token_mixed = v1_token_mixed.to(orig_dtype).transpose(1, 2).reshape(B, seq_len, self.channels)
196
+
197
+ present_key_value = (cum_kv_new, cum_k_new)
198
+ else:
199
+ # Full sequence parallel chunking (Prefill)
200
+ chunk_size = self.chunk_size
201
+ pad_len = (chunk_size - (seq_len % chunk_size)) % chunk_size
202
+ if pad_len > 0:
203
+ Q_rot = F.pad(Q_rot, (0, 0, 0, 0, 0, pad_len))
204
+ K_rot = F.pad(K_rot, (0, 0, 0, 0, 0, pad_len))
205
+ v1_heads = F.pad(v1_heads, (0, 0, 0, 0, 0, pad_len))
206
+
207
+ S_padded = seq_len + pad_len
208
+ N_chunks = S_padded // chunk_size
209
+
210
+ Q_c = Q_rot.view(B, N_chunks, chunk_size, self.num_heads, 2 * self.num_modes).transpose(2, 3)
211
+ K_c = K_rot.view(B, N_chunks, chunk_size, self.num_heads, 2 * self.num_modes).transpose(2, 3)
212
+ V_c = v1_heads.view(B, N_chunks, chunk_size, self.num_heads, self.head_dim).transpose(2, 3)
213
+
214
+ Q_c_f = Q_c.float()
215
+ K_c_f = K_c.float()
216
+ V_c_f = V_c.float()
217
+
218
+ A_intra = torch.matmul(Q_c_f, K_c_f.transpose(-1, -2)) * scale
219
+ causal_mask = torch.tril(torch.ones(chunk_size, chunk_size, device=x.device, dtype=torch.float32))
220
+ A_intra = A_intra * causal_mask.unsqueeze(0).unsqueeze(0).unsqueeze(0)
221
+
222
+ num_intra = torch.matmul(A_intra, V_c_f)
223
+ denom_intra = A_intra.sum(dim=-1, keepdim=True)
224
+
225
+ chunk_kv = torch.matmul(K_c_f.transpose(-1, -2), V_c_f)
226
+ chunk_kv_past = torch.cat([torch.zeros_like(chunk_kv[:, :1]), chunk_kv[:, :-1]], dim=1)
227
+ cum_kv_past = torch.cumsum(chunk_kv_past, dim=1)
228
+
229
+ chunk_k_sum = K_c_f.sum(dim=-2, keepdim=True).transpose(-1, -2)
230
+ chunk_k_past = torch.cat([torch.zeros_like(chunk_k_sum[:, :1]), chunk_k_sum[:, :-1]], dim=1)
231
+ cum_k_past = torch.cumsum(chunk_k_past, dim=1)
232
+
233
+ num_inter = torch.matmul(Q_c_f, cum_kv_past) * scale
234
+ denom_inter = torch.matmul(Q_c_f, cum_k_past) * scale
235
+
236
+ num_total = num_intra + num_inter
237
+ denom_total = (denom_intra + denom_inter).clamp(min=1e-4)
238
+
239
+ if num_total.requires_grad:
240
+ num_total.register_hook(lambda grad: torch.clamp(grad, min=-30000.0, max=30000.0))
241
+ if denom_total.requires_grad:
242
+ denom_total.register_hook(lambda grad: torch.clamp(grad, min=-30000.0, max=30000.0))
243
+
244
+ v1_token_mixed = (num_total / denom_total)
245
+ v1_token_mixed = torch.clamp(v1_token_mixed, min=-100.0, max=100.0)
246
+
247
+ v1_token_mixed = v1_token_mixed.to(orig_dtype).transpose(2, 3).reshape(B, S_padded, self.channels)
248
+ if pad_len > 0:
249
+ v1_token_mixed = v1_token_mixed[:, :seq_len]
250
+
251
+ # Compute final state for the cache
252
+ cum_kv_final = cum_kv_past[:, -1] + chunk_kv[:, -1]
253
+ cum_k_final = cum_k_past[:, -1] + chunk_k_sum[:, -1]
254
+ present_key_value = (cum_kv_final, cum_k_final)
255
+
256
+ v1_token_mixed = self.dropout(v1_token_mixed)
257
+ if attention_mask is not None:
258
+ v1_token_mixed = torch.nan_to_num(v1_token_mixed, nan=0.0, posinf=0.0, neginf=0.0)
259
+ if attention_mask.shape[1] > seq_len:
260
+ mask = attention_mask[:, -seq_len:].unsqueeze(-1).to(dtype=v1_token_mixed.dtype)
261
+ else:
262
+ mask = attention_mask.unsqueeze(-1).to(dtype=v1_token_mixed.dtype)
263
+ v1_token_mixed = v1_token_mixed * mask
264
+
265
+ v3 = v1_token_mixed * v2
266
+ return self.norm_out(self.out_proj(v3)) + x, present_key_value
267
+
268
+
269
+ # ──────────────────────────────────────────────────────────────────────
270
+ # Softmax Fourier Mixer
271
+ # ──────────────────────────────────────────────────────────────────────
272
+
273
+ class SoftmaxFourierMixer(nn.Module):
274
+ def __init__(self, channels, num_modes=64, num_heads=12, time_scale=128.0, dropout=0.05):
275
+ super().__init__()
276
+ assert channels % num_heads == 0, (
277
+ f"channels ({channels}) must be perfectly divisible by num_heads ({num_heads})"
278
+ )
279
+ self.channels = channels
280
+ self.num_modes = num_modes
281
+ self.num_heads = num_heads
282
+ self.head_dim = channels // num_heads
283
+ self.time_scale = time_scale
284
+
285
+ freq_bands = torch.exp(torch.linspace(math.log(0.0001), math.log(num_modes), num_modes))
286
+ self.num_modes = freq_bands.shape[0]
287
+ self.register_buffer("frequencies", freq_bands)
288
+
289
+ self.q_proj = nn.Linear(channels, self.num_heads * self.num_modes)
290
+ self.k_proj = nn.Linear(channels, self.num_heads * self.num_modes)
291
+ self.v_proj = nn.Linear(channels, channels)
292
+ self.proj_v2 = nn.Linear(channels, channels)
293
+ self.out_proj = nn.Linear(channels, channels)
294
+ self.activation = nn.SiLU()
295
+ self.norm_in = nn.LayerNorm(channels)
296
+ self.norm_out = nn.LayerNorm(channels)
297
+ self.dropout = nn.Dropout(dropout)
298
+
299
+ def forward(self, x, attention_mask=None, position_ids=None, past_key_value=None):
300
+ B, seq_len, C = x.shape
301
+ norm_x = self.norm_in(x)
302
+
303
+ Q = self.q_proj(norm_x).view(B, seq_len, self.num_heads, self.num_modes)
304
+ K = self.k_proj(norm_x).view(B, seq_len, self.num_heads, self.num_modes)
305
+
306
+ v1 = self.v_proj(norm_x)
307
+ v2 = self.activation(self.proj_v2(norm_x))
308
+
309
+ if position_ids is None:
310
+ position_ids = torch.arange(seq_len, device=x.device, dtype=torch.long).unsqueeze(0)
311
+
312
+ t = (position_ids.unsqueeze(-1).to(dtype=x.dtype) / self.time_scale)
313
+ omega_t = 2 * math.pi * t * self.frequencies
314
+ U = torch.cos(omega_t).unsqueeze(2)
315
+ V = torch.sin(omega_t).unsqueeze(2)
316
+
317
+ Q_cos = Q * U
318
+ Q_sin = Q * V
319
+ K_cos = K * U
320
+ K_sin = K * V
321
+
322
+ Q_rot = torch.cat([Q_cos, Q_sin], dim=-1)
323
+ K_rot = torch.cat([K_cos, K_sin], dim=-1)
324
+
325
+ v1_heads = v1.view(B, seq_len, self.num_heads, self.head_dim)
326
+
327
+ Q_b = Q_rot.transpose(1, 2)
328
+ K_b = K_rot.transpose(1, 2)
329
+ V_b = v1_heads.transpose(1, 2)
330
+
331
+ if past_key_value is not None:
332
+ K_past, V_past = past_key_value
333
+ K_b = torch.cat([K_past, K_b], dim=2)
334
+ V_b = torch.cat([V_past, V_b], dim=2)
335
+
336
+ present_key_value = (K_b, V_b)
337
+ seq_len_kv = K_b.size(2)
338
+
339
+ if x.device.type == "mps" or (seq_len > 512 and x.device.type != "cuda"):
340
+ scale = 1.0 / math.sqrt(Q_b.size(-1))
341
+ if seq_len > 256:
342
+ out_chunks = []
343
+ chunk_size = 256 if seq_len > 1024 else 512
344
+ for i_start in range(0, seq_len, chunk_size):
345
+ i_end = min(i_start + chunk_size, seq_len)
346
+ Q_chunk = Q_b[:, :, i_start:i_end, :]
347
+
348
+ # Causal chunking math for long sequences (typically prefill)
349
+ K_past_chunk = K_b[:, :, :i_end + (seq_len_kv - seq_len), :]
350
+ V_past_chunk = V_b[:, :, :i_end + (seq_len_kv - seq_len), :]
351
+
352
+ scores_chunk = torch.matmul(Q_chunk, K_past_chunk.transpose(-2, -1)) * scale
353
+
354
+ i_abs = torch.arange(i_start, i_end, device=x.device).view(-1, 1) + (seq_len_kv - seq_len)
355
+ j_abs = torch.arange(i_end + (seq_len_kv - seq_len), device=x.device).view(1, -1)
356
+ causal_mask = (j_abs <= i_abs)
357
+ scores_chunk = scores_chunk.masked_fill(~causal_mask.unsqueeze(0).unsqueeze(0), float("-inf"))
358
+
359
+ if attention_mask is not None:
360
+ pad_mask = attention_mask[:, None, None, :i_end + (seq_len_kv - seq_len)].to(dtype=torch.bool)
361
+ scores_chunk = scores_chunk.masked_fill(~pad_mask, float("-inf"))
362
+
363
+ attn_weights = F.softmax(scores_chunk, dim=-1)
364
+ out_chunk = torch.matmul(attn_weights, V_past_chunk)
365
+ out_chunks.append(out_chunk)
366
+ v1_token_mixed = torch.cat(out_chunks, dim=2)
367
+ else:
368
+ scale = 1.0 / math.sqrt(Q_b.size(-1))
369
+ scores = torch.matmul(Q_b, K_b.transpose(-2, -1)) * scale
370
+
371
+ i_abs = torch.arange(seq_len, device=x.device).view(-1, 1) + (seq_len_kv - seq_len)
372
+ j_abs = torch.arange(seq_len_kv, device=x.device).view(1, -1)
373
+ causal_mask = (j_abs <= i_abs)
374
+
375
+ scores = scores.masked_fill(~causal_mask.unsqueeze(0).unsqueeze(0), float("-inf"))
376
+ if attention_mask is not None:
377
+ pad_mask = attention_mask[:, None, None, :].to(dtype=torch.bool)
378
+ scores = scores.masked_fill(~pad_mask, float("-inf"))
379
+ attn_weights = F.softmax(scores, dim=-1)
380
+ v1_token_mixed = torch.matmul(attn_weights, V_b)
381
+ else:
382
+ attn_mask = None
383
+ if attention_mask is not None:
384
+ attn_mask = attention_mask[:, None, None, :].to(dtype=Q_b.dtype)
385
+ attn_mask = (1.0 - attn_mask) * torch.finfo(Q_b.dtype).min
386
+
387
+ # If past_key_value is present, seq_len=1 so causality isn't needed.
388
+ is_causal = past_key_value is None
389
+
390
+ try:
391
+ v1_token_mixed = F.scaled_dot_product_attention(
392
+ Q_b, K_b, V_b,
393
+ attn_mask=attn_mask,
394
+ is_causal=is_causal,
395
+ )
396
+ except Exception:
397
+ scale = 1.0 / math.sqrt(Q_b.size(-1))
398
+ scores = torch.matmul(Q_b, K_b.transpose(-2, -1)) * scale
399
+
400
+ i_abs = torch.arange(seq_len, device=x.device).view(-1, 1) + (seq_len_kv - seq_len)
401
+ j_abs = torch.arange(seq_len_kv, device=x.device).view(1, -1)
402
+ causal_mask = (j_abs <= i_abs)
403
+
404
+ scores = scores.masked_fill(~causal_mask.unsqueeze(0).unsqueeze(0), float("-inf"))
405
+ if attention_mask is not None:
406
+ pad_mask = attention_mask[:, None, None, :].to(dtype=torch.bool)
407
+ scores = scores.masked_fill(~pad_mask, float("-inf"))
408
+ attn_weights = F.softmax(scores, dim=-1)
409
+ v1_token_mixed = torch.matmul(attn_weights, V_b)
410
+
411
+ v1_token_mixed = v1_token_mixed.transpose(1, 2).reshape(B, seq_len, C)
412
+ v1_token_mixed = self.dropout(v1_token_mixed)
413
+ if attention_mask is not None:
414
+ v1_token_mixed = torch.nan_to_num(v1_token_mixed, nan=0.0, posinf=0.0, neginf=0.0)
415
+ if attention_mask.shape[1] > seq_len:
416
+ mask = attention_mask[:, -seq_len:].unsqueeze(-1).to(dtype=v1_token_mixed.dtype)
417
+ else:
418
+ mask = attention_mask.unsqueeze(-1).to(dtype=v1_token_mixed.dtype)
419
+ v1_token_mixed = v1_token_mixed * mask
420
+
421
+ v3 = v1_token_mixed * v2
422
+ out = self.norm_out(self.out_proj(v3)) + x
423
+ return out, present_key_value
424
+
425
+
426
+ # ──────────────────────────────────────────────────────────────────────
427
+ # Transformer block
428
+ # ──────────────────────────────────────────────────���───────────────────
429
+
430
+ class HybridSpectralBlock(nn.Module):
431
+ def __init__(self, latent_dim, num_modes=64, is_softmax=False,
432
+ time_scale=128.0, dropout=0.05, num_heads=None, chunk_size=128):
433
+ super().__init__()
434
+ self.is_softmax = is_softmax
435
+ num_heads = num_heads if num_heads is not None else max(1, latent_dim // 64)
436
+
437
+ if is_softmax:
438
+ self.mixer = SoftmaxFourierMixer(latent_dim, num_modes, num_heads, time_scale, dropout)
439
+ else:
440
+ self.mixer = LinearFourierMixer(latent_dim, num_modes, num_heads, time_scale, dropout, chunk_size=chunk_size)
441
+
442
+ self.ffn = nn.Sequential(
443
+ nn.LayerNorm(latent_dim),
444
+ nn.Linear(latent_dim, 4 * latent_dim),
445
+ nn.GELU(),
446
+ nn.Linear(4 * latent_dim, latent_dim),
447
+ nn.Dropout(dropout),
448
+ )
449
+ self.gradient_checkpointing = False
450
+
451
+ def forward(self, x, attention_mask=None, position_ids=None, past_key_value=None):
452
+ z, present_key_value = self.mixer(x, attention_mask=attention_mask, position_ids=position_ids, past_key_value=past_key_value)
453
+ out = z + self.ffn(z)
454
+ return out, present_key_value
455
+
456
+
457
+ # ──────────────────────────────────────────────────────────────────────
458
+ # Full model
459
+ # ──────────────────────────────────────────────────────────────────────
460
+
461
+ class HybridTimeScalePreTrainedModel(PreTrainedModel):
462
+ config_class = HybridTimeScaleConfig
463
+ base_model_prefix = "hybrid_timescale"
464
+ supports_gradient_checkpointing = True
465
+ _no_split_modules = ["HybridSpectralBlock"]
466
+ _tied_weights_keys = {"lm_head.weight": "embedding.weight"}
467
+ _supports_loss_kwargs = False
468
+ _supports_cache_class = False
469
+
470
+ def _init_weights(self, module):
471
+ if isinstance(module, nn.Linear):
472
+ torch.nn.init.normal_(module.weight, mean=0.0, std=0.02)
473
+ if module.bias is not None:
474
+ torch.nn.init.zeros_(module.bias)
475
+ elif isinstance(module, nn.Embedding):
476
+ torch.nn.init.normal_(module.weight, mean=0.0, std=0.02)
477
+ elif isinstance(module, nn.LayerNorm):
478
+ torch.nn.init.zeros_(module.bias)
479
+ torch.nn.init.ones_(module.weight)
480
+
481
+
482
+ class HybridTimeScaleLM(HybridTimeScalePreTrainedModel, GenerationMixin):
483
+
484
+ def __init__(self, config):
485
+ super().__init__(config)
486
+ self.config = config
487
+
488
+ self.embedding = nn.Embedding(config.vocab_size, config.latent_dim,
489
+ padding_idx=config.pad_token_id)
490
+
491
+ chunk_size = getattr(config, "chunk_size", 128)
492
+ blocks = []
493
+ for layer_type in config.layer_types:
494
+ blocks.append(HybridSpectralBlock(
495
+ config.latent_dim,
496
+ config.num_modes,
497
+ is_softmax=(layer_type == "softmax"),
498
+ time_scale=config.time_scale,
499
+ dropout=config.dropout,
500
+ chunk_size=chunk_size,
501
+ ))
502
+ self.mixers = nn.ModuleList(blocks)
503
+
504
+ self.ln_f = nn.LayerNorm(config.latent_dim)
505
+ self.lm_head = nn.Linear(config.latent_dim, config.vocab_size, bias=False)
506
+
507
+ self.post_init()
508
+
509
+ def get_input_embeddings(self):
510
+ return self.embedding
511
+
512
+ def set_input_embeddings(self, value):
513
+ self.embedding = value
514
+
515
+ def get_output_embeddings(self):
516
+ return self.lm_head
517
+
518
+ def set_output_embeddings(self, new_embedding):
519
+ self.lm_head = new_embedding
520
+
521
+ def forward(
522
+ self,
523
+ input_ids=None,
524
+ attention_mask=None,
525
+ position_ids=None,
526
+ past_key_values=None,
527
+ inputs_embeds=None,
528
+ labels=None,
529
+ use_cache=None,
530
+ output_attentions=None,
531
+ output_hidden_states=None,
532
+ return_dict=None,
533
+ **kwargs,
534
+ ):
535
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
536
+ output_hidden_states = (
537
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
538
+ )
539
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
540
+ use_cache = use_cache if use_cache is not None else getattr(self.config, "use_cache", True)
541
+
542
+ if input_ids is not None and inputs_embeds is not None:
543
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
544
+ elif input_ids is not None:
545
+ batch_size, seq_length = input_ids.shape
546
+ elif inputs_embeds is not None:
547
+ batch_size, seq_length, _ = inputs_embeds.shape
548
+ else:
549
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
550
+
551
+ if inputs_embeds is None:
552
+ hidden_states = self.embedding(input_ids)
553
+ else:
554
+ hidden_states = inputs_embeds
555
+
556
+ if position_ids is None:
557
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
558
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=device)
559
+ position_ids = position_ids.unsqueeze(0).expand(batch_size, -1)
560
+
561
+ all_hidden_states = () if output_hidden_states else None
562
+ presents = () if use_cache else None
563
+
564
+ for i, mixer in enumerate(self.mixers):
565
+ if output_hidden_states:
566
+ all_hidden_states += (hidden_states,)
567
+
568
+ past_key_value = past_key_values[i] if past_key_values is not None else None
569
+
570
+ if getattr(self, "gradient_checkpointing", False) and self.training:
571
+ hidden_states, _ = checkpoint(
572
+ mixer,
573
+ hidden_states,
574
+ attention_mask,
575
+ position_ids,
576
+ None,
577
+ use_reentrant=False
578
+ )
579
+ else:
580
+ hidden_states, present = mixer(hidden_states, attention_mask=attention_mask, position_ids=position_ids, past_key_value=past_key_value)
581
+ if use_cache:
582
+ presents += (present,)
583
+
584
+ hidden_states = self.ln_f(hidden_states)
585
+
586
+ if output_hidden_states:
587
+ all_hidden_states += (hidden_states,)
588
+
589
+ logits = self.lm_head(hidden_states)
590
+
591
+ loss = None
592
+ if labels is not None:
593
+ shift_logits = logits[..., :-1, :].contiguous()
594
+ shift_labels = labels[..., 1:].contiguous()
595
+ loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
596
+ loss = loss_fct(
597
+ shift_logits.view(-1, shift_logits.size(-1)),
598
+ shift_labels.view(-1),
599
+ )
600
+
601
+ if not return_dict:
602
+ output = (logits,)
603
+ if output_hidden_states:
604
+ output += (all_hidden_states,)
605
+ return ((loss,) + output) if loss is not None else output
606
+
607
+ return HybridTimeScaleOutput(
608
+ loss=loss,
609
+ logits=logits,
610
+ past_key_values=presents,
611
+ hidden_states=all_hidden_states,
612
+ attentions=None,
613
+ last_hidden_state=hidden_states,
614
+ )
615
+
616
+ def prepare_inputs_for_generation(self, input_ids, past_key_values=None,
617
+ attention_mask=None, inputs_embeds=None, **kwargs):
618
+ position_ids = kwargs.get("position_ids", None)
619
+ if attention_mask is not None and position_ids is None:
620
+ position_ids = attention_mask.long().cumsum(-1) - 1
621
+ position_ids.masked_fill_(attention_mask == 0, 1)
622
+
623
+ if past_key_values is not None:
624
+ if isinstance(input_ids, torch.Tensor):
625
+ input_ids = input_ids[:, -1:]
626
+ if position_ids is not None:
627
+ position_ids = position_ids[:, -1].unsqueeze(-1)
628
+
629
+ model_inputs = {
630
+ "input_ids": input_ids,
631
+ "past_key_values": past_key_values,
632
+ "use_cache": kwargs.get("use_cache", True),
633
+ "position_ids": position_ids,
634
+ "attention_mask": attention_mask,
635
+ }
636
+ return model_inputs
637
+
638
+ def _prepare_cache_for_generation(self, *args, **kwargs):
639
+ # Override GenerationMixin's method to bypass Hugging Face's DynamicCache initialization.
640
+ # This completely avoids the KeyError: 'linear' crash by ensuring HF uses standard tuple caching.
641
+ return None
642
+
643
+ def _get_initial_cache(self, **kwargs):
644
+ return None
645
+
646
+ def _reorder_cache(self, past_key_values, beam_idx):
647
+ return past_key_values
648
+
649
+
650
+ # ── Register with AutoClasses ────────────────────────────────────────
651
+ AutoConfig.register("hybrid_timescale_lm", HybridTimeScaleConfig)
652
+ AutoModelForCausalLM.register(HybridTimeScaleConfig, HybridTimeScaleLM)
653
+
654
+ # Required for push_to_hub to upload the custom python code and generate auto_map
655
+ HybridTimeScaleConfig.register_for_auto_class("AutoConfig")
656
+ HybridTimeScaleLM.register_for_auto_class("AutoModelForCausalLM")
last-checkpoint/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd67d7aff17d4c04f065891a8ceba243346c4e36f53d807997e52209ae039ec0
3
+ size 1738460416
last-checkpoint/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48998fa4e64b0552833c6886caf08be135639f3a2f2eedc6a2ff97fd05414a26
3
+ size 3477327340
last-checkpoint/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4a9f217e852f439efa6bd32fde98d6867f11aa6ea13ddc021ba10af6a0b0934
3
+ size 14645
last-checkpoint/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5638739d9917cfd5ef0eac6652b3a82be017aee5432b6e7503833c5022688e4
3
+ size 1465
last-checkpoint/special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
last-checkpoint/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
3
+ size 11421896
last-checkpoint/tokenizer_config.json ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
182
+ "additional_special_tokens": [
183
+ "<|im_start|>",
184
+ "<|im_end|>",
185
+ "<|object_ref_start|>",
186
+ "<|object_ref_end|>",
187
+ "<|box_start|>",
188
+ "<|box_end|>",
189
+ "<|quad_start|>",
190
+ "<|quad_end|>",
191
+ "<|vision_start|>",
192
+ "<|vision_end|>",
193
+ "<|vision_pad|>",
194
+ "<|image_pad|>",
195
+ "<|video_pad|>"
196
+ ],
197
+ "bos_token": null,
198
+ "clean_up_tokenization_spaces": false,
199
+ "eos_token": "<|endoftext|>",
200
+ "errors": "replace",
201
+ "extra_special_tokens": {},
202
+ "model_max_length": 1000000000,
203
+ "pad_token": "<|endoftext|>",
204
+ "split_special_tokens": false,
205
+ "tokenizer_class": "Qwen2Tokenizer",
206
+ "unk_token": null
207
+ }
last-checkpoint/trainer_state.json ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_global_step": null,
3
+ "best_metric": null,
4
+ "best_model_checkpoint": null,
5
+ "epoch": 0.01,
6
+ "eval_steps": 50,
7
+ "global_step": 100,
8
+ "is_hyper_param_search": false,
9
+ "is_local_process_zero": true,
10
+ "is_world_process_zero": true,
11
+ "log_history": [
12
+ {
13
+ "epoch": 0.0005,
14
+ "grad_norm": 6.46875,
15
+ "learning_rate": 2e-05,
16
+ "loss": 12.1248,
17
+ "step": 5
18
+ },
19
+ {
20
+ "epoch": 0.001,
21
+ "grad_norm": 3.328125,
22
+ "learning_rate": 4.5e-05,
23
+ "loss": 11.2119,
24
+ "step": 10
25
+ },
26
+ {
27
+ "epoch": 0.0015,
28
+ "grad_norm": 1.890625,
29
+ "learning_rate": 5e-05,
30
+ "loss": 10.2505,
31
+ "step": 15
32
+ },
33
+ {
34
+ "epoch": 0.002,
35
+ "grad_norm": 1.9375,
36
+ "learning_rate": 5e-05,
37
+ "loss": 9.8307,
38
+ "step": 20
39
+ },
40
+ {
41
+ "epoch": 0.0025,
42
+ "grad_norm": 1.8046875,
43
+ "learning_rate": 5e-05,
44
+ "loss": 9.5638,
45
+ "step": 25
46
+ },
47
+ {
48
+ "epoch": 0.003,
49
+ "grad_norm": 1.546875,
50
+ "learning_rate": 5e-05,
51
+ "loss": 9.3031,
52
+ "step": 30
53
+ },
54
+ {
55
+ "epoch": 0.0035,
56
+ "grad_norm": 1.4375,
57
+ "learning_rate": 5e-05,
58
+ "loss": 8.97,
59
+ "step": 35
60
+ },
61
+ {
62
+ "epoch": 0.004,
63
+ "grad_norm": 1.28125,
64
+ "learning_rate": 5e-05,
65
+ "loss": 8.7355,
66
+ "step": 40
67
+ },
68
+ {
69
+ "epoch": 0.0045,
70
+ "grad_norm": 1.296875,
71
+ "learning_rate": 5e-05,
72
+ "loss": 8.4612,
73
+ "step": 45
74
+ },
75
+ {
76
+ "epoch": 0.005,
77
+ "grad_norm": 1.1015625,
78
+ "learning_rate": 5e-05,
79
+ "loss": 8.2349,
80
+ "step": 50
81
+ },
82
+ {
83
+ "epoch": 0.005,
84
+ "eval_loss": 8.104817390441895,
85
+ "eval_runtime": 18.203,
86
+ "eval_samples_per_second": 14.778,
87
+ "eval_steps_per_second": 1.483,
88
+ "step": 50
89
+ },
90
+ {
91
+ "epoch": 0.0055,
92
+ "grad_norm": 1.0,
93
+ "learning_rate": 5e-05,
94
+ "loss": 8.0171,
95
+ "step": 55
96
+ },
97
+ {
98
+ "epoch": 0.006,
99
+ "grad_norm": 0.94140625,
100
+ "learning_rate": 5e-05,
101
+ "loss": 7.8534,
102
+ "step": 60
103
+ },
104
+ {
105
+ "epoch": 0.0065,
106
+ "grad_norm": 0.765625,
107
+ "learning_rate": 5e-05,
108
+ "loss": 7.7173,
109
+ "step": 65
110
+ },
111
+ {
112
+ "epoch": 0.007,
113
+ "grad_norm": 1.046875,
114
+ "learning_rate": 5e-05,
115
+ "loss": 7.535,
116
+ "step": 70
117
+ },
118
+ {
119
+ "epoch": 0.0075,
120
+ "grad_norm": 1.0703125,
121
+ "learning_rate": 5e-05,
122
+ "loss": 7.4876,
123
+ "step": 75
124
+ },
125
+ {
126
+ "epoch": 0.008,
127
+ "grad_norm": 0.98046875,
128
+ "learning_rate": 5e-05,
129
+ "loss": 7.4177,
130
+ "step": 80
131
+ },
132
+ {
133
+ "epoch": 0.0085,
134
+ "grad_norm": 0.9296875,
135
+ "learning_rate": 5e-05,
136
+ "loss": 7.3471,
137
+ "step": 85
138
+ },
139
+ {
140
+ "epoch": 0.009,
141
+ "grad_norm": 0.7421875,
142
+ "learning_rate": 5e-05,
143
+ "loss": 7.35,
144
+ "step": 90
145
+ },
146
+ {
147
+ "epoch": 0.0095,
148
+ "grad_norm": 0.64453125,
149
+ "learning_rate": 5e-05,
150
+ "loss": 7.2766,
151
+ "step": 95
152
+ },
153
+ {
154
+ "epoch": 0.01,
155
+ "grad_norm": 0.73046875,
156
+ "learning_rate": 5e-05,
157
+ "loss": 7.1746,
158
+ "step": 100
159
+ },
160
+ {
161
+ "epoch": 0.01,
162
+ "eval_loss": 7.275140285491943,
163
+ "eval_runtime": 17.5509,
164
+ "eval_samples_per_second": 15.327,
165
+ "eval_steps_per_second": 1.538,
166
+ "step": 100
167
+ }
168
+ ],
169
+ "logging_steps": 5,
170
+ "max_steps": 10000,
171
+ "num_input_tokens_seen": 0,
172
+ "num_train_epochs": 9223372036854775807,
173
+ "save_steps": 100,
174
+ "stateful_callbacks": {
175
+ "TrainerControl": {
176
+ "args": {
177
+ "should_epoch_stop": false,
178
+ "should_evaluate": false,
179
+ "should_log": false,
180
+ "should_save": true,
181
+ "should_training_stop": false
182
+ },
183
+ "attributes": {}
184
+ }
185
+ },
186
+ "total_flos": 1.6351837028352e+16,
187
+ "train_batch_size": 10,
188
+ "trial_name": null,
189
+ "trial_params": null
190
+ }
last-checkpoint/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:93663ce2422ad42e4302eebc4223254912b3e8626b07cdb378fa0ebab8884f21
3
+ size 5841
last-checkpoint/vocab.json ADDED
The diff for this file is too large to render. See raw diff