lukeleeai commited on
Commit
3d79a5c
·
verified ·
1 Parent(s): a9e1171

End of training

Browse files
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - generated_from_trainer
4
+ model-index:
5
+ - name: sparse_mistral_refined_web_90p_debugging_2024-03-23
6
+ results: []
7
+ ---
8
+
9
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
10
+ should probably proofread and complete it, then remove this comment. -->
11
+
12
+ # sparse_mistral_refined_web_90p_debugging_2024-03-23
13
+
14
+ This model is a fine-tuned version of [](https://huggingface.co/) on the None dataset.
15
+ It achieves the following results on the evaluation set:
16
+ - Loss: 10.3833
17
+
18
+ ## Model description
19
+
20
+ More information needed
21
+
22
+ ## Intended uses & limitations
23
+
24
+ More information needed
25
+
26
+ ## Training and evaluation data
27
+
28
+ More information needed
29
+
30
+ ## Training procedure
31
+
32
+ ### Training hyperparameters
33
+
34
+ The following hyperparameters were used during training:
35
+ - learning_rate: 1e-05
36
+ - train_batch_size: 1
37
+ - eval_batch_size: 1
38
+ - seed: 0
39
+ - distributed_type: multi-GPU
40
+ - num_devices: 4
41
+ - gradient_accumulation_steps: 8
42
+ - total_train_batch_size: 32
43
+ - total_eval_batch_size: 4
44
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
45
+ - lr_scheduler_type: linear
46
+ - training_steps: 10
47
+
48
+ ### Training results
49
+
50
+
51
+
52
+ ### Framework versions
53
+
54
+ - Transformers 4.37.2
55
+ - Pytorch 2.1.1+cu121
56
+ - Datasets 2.15.0
57
+ - Tokenizers 0.15.0
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SparseMistralforCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "auto_map": {
7
+ "AutoConfig": "sparsification_sftt.SparseMistralConfig",
8
+ "AutoModelForCausalLM": "sparsification_sftt.SparseMistralforCausalLM"
9
+ },
10
+ "bos_token_id": 1,
11
+ "eos_token_id": 2,
12
+ "hidden_act": "silu",
13
+ "hidden_size": 64,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 64,
16
+ "max_position_embeddings": 131072,
17
+ "model_type": "sparse_mistral",
18
+ "num_attention_heads": 32,
19
+ "num_hidden_layers": 4,
20
+ "num_key_value_heads": 8,
21
+ "rms_norm_eps": 1e-06,
22
+ "rope_theta": 10000.0,
23
+ "sliding_window": 4096,
24
+ "thresholds": [
25
+ 0.12938815355300903,
26
+ 0.1313941776752472,
27
+ 0.1253761202096939,
28
+ 0.12938815355300903
29
+ ],
30
+ "tie_word_embeddings": false,
31
+ "torch_dtype": "float32",
32
+ "transformers_version": "4.37.2",
33
+ "use_cache": false,
34
+ "use_relu": false,
35
+ "use_sparse_model": true,
36
+ "use_sparse_predictor": false,
37
+ "use_sparse_regularization": false,
38
+ "vocab_size": 32000
39
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.37.2"
6
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c781fc2306e57acd1afe1f97280d67eb3056b652e0f564eb5d9889e5ac590a74
3
+ size 16750904
sparsification_sftt.py ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TrainerCallback, Trainer
2
+ from trl import SFTTrainer, DataCollatorForCompletionOnlyLM
3
+ from peft import PeftModel
4
+ from datasets import Dataset
5
+ from transformers.utils import is_sagemaker_mp_enabled, is_sagemaker_dp_enabled
6
+ from typing import Any, Dict, Union, Optional, Tuple
7
+ from torch.nn import MSELoss
8
+
9
+ import warnings
10
+ import torch
11
+ import torch.nn as nn
12
+ import torch.nn.functional as F
13
+ import matplotlib.pyplot as plt
14
+ import numpy as np
15
+ import time
16
+ import os
17
+ import copy
18
+
19
+ from transformers.models.mistral.modeling_mistral import (
20
+ MistralMLP,
21
+ MistralAttention,
22
+ MistralModel,
23
+ MistralDecoderLayer,
24
+ MistralConfig,
25
+ MISTRAL_ATTENTION_CLASSES,
26
+ MistralRMSNorm,
27
+ MistralForCausalLM,
28
+ )
29
+ from experiments.models.sparse_mistral.svd_router import (
30
+ low_rank_approximation,
31
+ SparsePredictor,
32
+ )
33
+ from utils.utils import (
34
+ print_size_of_model,
35
+ is_running_deepspeed,
36
+ is_mainprocess,
37
+ get_datetime,
38
+ ds_print,
39
+ )
40
+
41
+
42
+ class SparseSFTTTrainer(SFTTrainer):
43
+ def __init__(self, *args, **kwargs):
44
+ self.regularization_coefficient = kwargs.pop("regularization_coefficient", 10)
45
+ self.use_sparse_regularization = kwargs.pop("use_sparse_regularization", False)
46
+ self.use_spm_loss = False
47
+ self.freeze_original_weights = False
48
+ self.regularization_type = kwargs.pop("regularization_type", "L1 positive activation")
49
+ assert self.regularization_type in [
50
+ "L2 activation",
51
+ "L1 positive activation",
52
+ ], f"Invalid regularization type: {self.regularization_type}"
53
+ self.sparse_layers = []
54
+ self.sparse_decoder_layers = []
55
+ super(SparseSFTTTrainer, self).__init__(*args, **kwargs)
56
+
57
+ def initialize_sparse_silu_layers(self, model):
58
+ self.sparse_layers = [m for m in model.modules() if isinstance(m, MistralSparseSiluMLP)]
59
+
60
+ def initialize_sparse_decoder_layers(self, model):
61
+ self.sparse_decoder_layers = [m for m in model.modules() if isinstance(m, SparseMistralDecoderLayer)]
62
+
63
+ def training_step(self, model: nn.Module, inputs: Dict[str, Union[torch.Tensor, Any]]) -> torch.Tensor:
64
+ """
65
+ Override the huggingface's training_step function to add a regularization term.
66
+ A regularization term is computed with intermediate values, which are freed after "backward()."
67
+ You need to set `retain_graph=True` inside `backward` function to keep the values.
68
+ """
69
+ model.train()
70
+ inputs = self._prepare_inputs(inputs)
71
+
72
+ with self.compute_loss_context_manager():
73
+ loss = self.compute_loss(model, inputs)
74
+
75
+ if self.args.n_gpu > 1:
76
+ loss = loss.mean() # mean() to average on multi-gpu parallel training
77
+ if not self.freeze_original_weights:
78
+ if loss is not None:
79
+ self.accelerator.backward(loss, retain_graph=False)
80
+
81
+ if self.use_sparse_regularization:
82
+ regularization_loss = self.compute_regularization(model)
83
+ if self.args.n_gpu > 1:
84
+ regularization_loss = regularization_loss.mean()
85
+ if regularization_loss is not None:
86
+ self.accelerator.backward(regularization_loss, retain_graph=True)
87
+ loss += regularization_loss
88
+
89
+ if self.use_spm_loss:
90
+ spm_loss = self.compute_spm_loss(model)
91
+ if self.args.n_gpu > 1:
92
+ spm_loss = spm_loss.mean()
93
+ if spm_loss is not None:
94
+ self.accelerator.backward(spm_loss, retain_graph=False)
95
+ loss += spm_loss
96
+
97
+ return loss.detach() / self.args.gradient_accumulation_steps
98
+
99
+ def compute_regularization(self, model):
100
+ """
101
+ Compute a sparse regularization loss for SiLU
102
+ """
103
+ loss = 0
104
+ if len(self.sparse_layers) == 0:
105
+ self.initialize_sparse_silu_layers(model)
106
+ num_layers = len(self.sparse_layers)
107
+
108
+ for module in self.sparse_layers:
109
+ if module.activation_norm is not None:
110
+ loss += module.activation_norm
111
+
112
+ loss /= num_layers
113
+ loss *= self.regularization_coefficient
114
+
115
+ if self.state.global_step % 20 == 0 and loss != 0:
116
+ print("Negative relularizer loss: ", loss.item())
117
+ return loss
118
+
119
+ def compute_spm_loss(self, model):
120
+ loss = 0
121
+ if len(self.sparse_decoder_layers) == 0:
122
+ self.initialize_sparse_decoder_layers(model)
123
+ for module in self.sparse_decoder_layers:
124
+ if module.distill_loss != None:
125
+ loss += module.distill_loss
126
+ if self.state.global_step % 20 == 0 and loss != 0:
127
+ print("Sparse Predictor Distillation loss: ", loss.item())
128
+ return loss
129
+
130
+ # def compute_loss(self, model, inputs, return_outputs=False):
131
+ # loss = super().compute_loss(model, inputs, return_outputs)
132
+ #
133
+ # if is_sagemaker_mp_enabled():
134
+ # import smdistributed.modelparallel.torch as smp
135
+ # @smp.step()
136
+ # def smp_forward_backward(model, inputs, gradient_accumulation_steps=1):
137
+ # outputs = model(**inputs)
138
+ # loss = outputs["loss"] if isinstance(outputs, dict) else outputs[0]
139
+ # loss /= gradient_accumulation_steps
140
+ # model.backward(loss)
141
+ # return loss
142
+ #
143
+ # loss_mb = smp_forward_backward(
144
+ # model, inputs, self.args.gradient_accumulation_steps
145
+ # )
146
+ # if self.use_sparse_regularization:
147
+ # return loss_mb.reduce_mean().detach().to(
148
+ # self.args.device
149
+ # ) + self.regularization_coefficient * self.compute_regularization(model)
150
+ # else:
151
+ # return loss_mb.reduce_mean().detach().to(self)
152
+ #
153
+ # if return_outputs:
154
+ # classification_loss, outputs = loss
155
+ # else:
156
+ # classification_loss = loss
157
+ #
158
+ # loss = classification_loss
159
+ # if self.use_sparse_regularization:
160
+ # regularization_loss = self.compute_regularization(model)
161
+ # loss += self.regularization_coefficient * regularization_loss
162
+ #
163
+ # return (loss, outputs) if return_outputs else loss
164
+
165
+
166
+ class SparseTrainer(Trainer):
167
+ def __init__(self, *args, **kwargs):
168
+ self.regularization_coefficient = kwargs.pop("regularization_coefficient", 10)
169
+ self.use_sparse_regularization = kwargs.pop("use_sparse_regularization", False)
170
+ self.use_spm_loss = False
171
+ self.freeze_original_weights = False
172
+ self.regularization_type = kwargs.pop("regularization_type", "L1 positive activation")
173
+ assert self.regularization_type in [
174
+ "L2 activation",
175
+ "L1 positive activation",
176
+ ], f"Invalid regularization type: {self.regularization_type}"
177
+ self.sparse_layers = []
178
+ self.sparse_decoder_layers = []
179
+ super(SparseTrainer, self).__init__(*args, **kwargs)
180
+
181
+ def initialize_sparse_silu_layers(self, model):
182
+ self.sparse_layers = [m for m in model.modules() if isinstance(m, MistralSparseSiluMLP)]
183
+
184
+ def initialize_sparse_decoder_layers(self, model):
185
+ self.sparse_decoder_layers = [m for m in model.modules() if isinstance(m, SparseMistralDecoderLayer)]
186
+
187
+ def training_step(self, model: nn.Module, inputs: Dict[str, Union[torch.Tensor, Any]]) -> torch.Tensor:
188
+ """
189
+ Override the huggingface's training_step function to add a regularization term.
190
+ A regularization term is computed with intermediate values, which are freed after "backward()."
191
+ You need to set `retain_graph=True` inside `backward` function to keep the values.
192
+ """
193
+ model.train()
194
+ inputs = self._prepare_inputs(inputs)
195
+
196
+ with self.compute_loss_context_manager():
197
+ loss = self.compute_loss(model, inputs)
198
+
199
+ if self.args.n_gpu > 1:
200
+ loss = loss.mean() # mean() to average on multi-gpu parallel training
201
+ if not self.freeze_original_weights:
202
+ if loss is not None:
203
+ self.accelerator.backward(loss, retain_graph=False)
204
+
205
+ if self.use_sparse_regularization:
206
+ regularization_loss = self.compute_regularization(model)
207
+ if self.args.n_gpu > 1:
208
+ regularization_loss = regularization_loss.mean()
209
+ if regularization_loss is not None:
210
+ self.accelerator.backward(regularization_loss, retain_graph=True)
211
+ loss += regularization_loss
212
+
213
+ if self.use_spm_loss:
214
+ spm_loss = self.compute_spm_loss(model)
215
+ if self.args.n_gpu > 1:
216
+ spm_loss = spm_loss.mean()
217
+ if spm_loss is not None:
218
+ self.accelerator.backward(spm_loss, retain_graph=False)
219
+ loss += spm_loss
220
+
221
+ return loss.detach() / self.args.gradient_accumulation_steps
222
+
223
+ def compute_regularization(self, model):
224
+ """
225
+ Compute a sparse regularization loss for SiLU
226
+ """
227
+ loss = 0
228
+ if len(self.sparse_layers) == 0:
229
+ self.initialize_sparse_silu_layers(model)
230
+ num_layers = len(self.sparse_layers)
231
+
232
+ for module in self.sparse_layers:
233
+ if module.activation_norm is not None:
234
+ loss += module.activation_norm
235
+
236
+ loss /= num_layers
237
+ loss *= self.regularization_coefficient
238
+
239
+ if self.state.global_step % 20 == 0 and loss != 0:
240
+ print("Negative relularizer loss: ", loss.item())
241
+ return loss
242
+
243
+ def compute_spm_loss(self, model):
244
+ loss = 0
245
+ if len(self.sparse_decoder_layers) == 0:
246
+ self.initialize_sparse_decoder_layers(model)
247
+ for module in self.sparse_decoder_layers:
248
+ if module.distill_loss != None:
249
+ loss += module.distill_loss
250
+ if self.state.global_step % 20 == 0 and loss != 0:
251
+ print("Sparse Predictor Distillation loss: ", loss.item())
252
+ return loss
253
+
254
+
255
+ class SparseSiLU(nn.SiLU):
256
+ def __init__(self, threshold):
257
+ super(SparseSiLU, self).__init__()
258
+ self.threshold = threshold
259
+ self.m = nn.Threshold(self.threshold, 0)
260
+
261
+ def set_new_threshold(self, threshold):
262
+ self.threshold = threshold
263
+ self.m = nn.Threshold(threshold, 0)
264
+
265
+ def forward(self, x):
266
+ act = super(SparseSiLU, self).forward(x)
267
+ return self.m(act) - self.m(-act)
268
+
269
+
270
+ class MistralSparseSiluMLP(MistralMLP):
271
+ def __init__(self, config, *args, **kwargs):
272
+ super().__init__(config)
273
+ self.swish_outputs = None
274
+ self.relu = nn.ReLU()
275
+
276
+ self.kill_sparse_swish_outputs = False
277
+ self.dead_percentage = 0
278
+ self.is_stats = False
279
+ self.visit_counts = 0
280
+
281
+ # Hyperparameters to tune
282
+ self.dead_threshold = kwargs.pop("dead_threshold", 0)
283
+ self.use_sparse_regularization = kwargs.pop("use_sparse_regularization", True)
284
+ self.regularization_type = kwargs.pop("regularization_type", "L1 regularization")
285
+ self.regularization_threshold = kwargs.pop("regularization_threshold", 0.5)
286
+ self.use_relu = kwargs.pop("use_relu", False)
287
+ self.activation_norm = None
288
+
289
+ # Activation Histograms
290
+ self.is_collect_histogram = False
291
+ num_bins = 1000
292
+ self.pre_activation_list = []
293
+ self.post_activation_list = []
294
+
295
+ self.histogram_bins = torch.linspace(-1, 1, num_bins - 2)
296
+ self.histogram_bins = torch.cat([torch.tensor([-torch.inf]), self.histogram_bins, torch.tensor([torch.inf])])
297
+ self.pre_act_hist_counts = torch.zeros(num_bins - 1)
298
+ self.post_act_hist_counts = torch.zeros(num_bins - 1)
299
+ self.t = 0
300
+ self.count = 0
301
+ self.agg_sparsity = 0
302
+
303
+ # Sparse activation function
304
+ self.sparse_act_fn = SparseSiLU(threshold=self.dead_threshold)
305
+
306
+ def activate_stats(self, is_collect_histogram: bool = True):
307
+ self.is_stats = True
308
+ self.dead_percentage = 0
309
+ self.visit_counts = 0
310
+ self.is_collect_histogram = is_collect_histogram
311
+ self.histogram_counts = torch.zeros(2000) # .to(self.down_proj.weight.device)
312
+
313
+ def deactivate_stats(self):
314
+ self.is_stats = False
315
+
316
+ def collect_stats(self, pre_activation, post_activation):
317
+ start_time = time.time()
318
+ pre_activation = pre_activation.float().cpu().detach()
319
+ post_activation = post_activation.float().cpu().detach()
320
+ self.pre_act_hist_counts += torch.histogram(pre_activation, bins=self.histogram_bins)[0]
321
+ self.post_act_hist_counts += torch.histogram(torch.abs(post_activation), bins=self.histogram_bins)[0]
322
+ self.t += time.time() - start_time
323
+ if self.visit_counts % 30 == 0:
324
+ print(f"Time taken to collect stats: {self.t}s.")
325
+
326
+ def forward(
327
+ self,
328
+ x,
329
+ sp_mask: torch.tensor = None,
330
+ ):
331
+ """
332
+ If kill_sparse_swish_outputs is set to False, this layer functions exactly like a normal MLP layer.
333
+ """
334
+ if sp_mask != None: # When sparse mask is given
335
+ return self.down_proj(
336
+ self.sparse_act_fn(self.gate_proj(x) * sp_mask) * self.up_proj(x)
337
+ ) # Todo: This doesn't accelerate runtime (instead slowing down)
338
+
339
+ elif self.use_relu:
340
+ post_act = self.relu(self.gate_proj(x))
341
+ self.count += 1
342
+ if self.count <= 1:
343
+ ds_print("USING RELU!!!!")
344
+
345
+ if self.is_stats:
346
+ dead_neurons = post_act == 0
347
+ dead_percentage = dead_neurons.float().mean()
348
+ agg_sparsity = dead_neurons.all(dim=0).float().mean()
349
+
350
+ self.dead_percentage = (self.dead_percentage * self.visit_counts + dead_percentage) / (self.visit_counts + 1)
351
+ self.agg_sparsity = (self.agg_sparsity * self.visit_counts + agg_sparsity) / (self.visit_counts + 1)
352
+ self.visit_counts += 1
353
+
354
+ return self.down_proj(post_act * self.up_proj(x))
355
+
356
+ else:
357
+ self.count += 1
358
+ if self.count <= 1:
359
+ ds_print("USING SparseSILU!!!!")
360
+ pre_act = self.gate_proj(x)
361
+ post_act = self.act_fn(pre_act)
362
+ if self.kill_sparse_swish_outputs:
363
+ dead_neurons = post_act.abs() <= self.dead_threshold
364
+ # print("pre act sparsity: ", (pre_act==0).float().mean())
365
+
366
+ dead_percentage = dead_neurons.float().mean()
367
+ agg_sparsity = dead_neurons.all(dim=0).float().mean()
368
+
369
+ if self.is_stats:
370
+ self.dead_percentage = (self.dead_percentage * self.visit_counts + dead_percentage) / (self.visit_counts + 1)
371
+ self.agg_sparsity = (self.agg_sparsity * self.visit_counts + agg_sparsity) / (self.visit_counts + 1)
372
+ self.visit_counts += 1
373
+
374
+ self.a = dead_percentage
375
+
376
+ # print(self.agg_sparsity)
377
+
378
+ # Collect histogram stats
379
+ if self.is_collect_histogram and pre_act.eq(0).float().mean() < 0.99: # Padded dataset
380
+ self.collect_stats(pre_act, post_act)
381
+
382
+ post_act[dead_neurons] = 0
383
+
384
+ out = self.down_proj(post_act * self.up_proj(x))
385
+ if self.use_sparse_regularization:
386
+ if self.regularization_type == "L1 regularization":
387
+ self.activation_norm = torch.abs(post_act)[post_act < self.regularization_threshold].mean()
388
+ elif self.regularization_type == "L2 regularization":
389
+ self.activation_norm = torch.sqrt(torch.square(post_act)[post_act < self.regularization_threshold]).mean()
390
+
391
+ return out
392
+
393
+
394
+ class SparseMistralDecoderLayer(MistralDecoderLayer):
395
+ def __init__(
396
+ self,
397
+ config: MistralConfig,
398
+ layer_idx: int,
399
+ decoder_layer: MistralDecoderLayer,
400
+ init_svd: bool = True,
401
+ *args,
402
+ **kwargs,
403
+ ):
404
+ assert isinstance(decoder_layer.mlp, MistralSparseSiluMLP), f"{type(decoder_layer.mlp)} should MistralSparseSiluMLP."
405
+
406
+ super().__init__(config, layer_idx)
407
+ self.hidden_size = config.hidden_size
408
+ self.intermediate_size = config.intermediate_size
409
+
410
+ self.init_svd = init_svd
411
+ self.self_attn = decoder_layer.self_attn
412
+
413
+ self.mlp = decoder_layer.mlp
414
+ self.input_layernorm = decoder_layer.input_layernorm
415
+ self.post_attention_layernorm = decoder_layer.post_attention_layernorm
416
+
417
+ # Sparse predictor for mlp (initialized with SVD decomposed matrix)
418
+ self.low_rank = kwargs.pop("low_rank", 64)
419
+ self.sparse_act_func = decoder_layer.mlp.sparse_act_fn
420
+
421
+ print(f"Setting {layer_idx}th mlp layer's sparse predictor... svd init: {init_svd}")
422
+ self.sp_mlp = low_rank_approximation(
423
+ decoder_layer.mlp.gate_proj,
424
+ act_func=self.sparse_act_func,
425
+ init_svd=init_svd,
426
+ )
427
+ self.use_async = kwargs.pop("use_async", False)
428
+ self.use_sparse_predictor = False
429
+ self.distill_loss = None
430
+
431
+ def forward(
432
+ self,
433
+ hidden_states: torch.Tensor,
434
+ attention_mask: Optional[torch.Tensor] = None,
435
+ position_ids: Optional[torch.LongTensor] = None,
436
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
437
+ output_attentions: Optional[bool] = False,
438
+ use_cache: Optional[bool] = False,
439
+ **kwargs,
440
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
441
+ print("hidden_states shape: ", hidden_states.shape)
442
+ if "padding_mask" in kwargs:
443
+ warnings.warn(
444
+ "Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
445
+ )
446
+
447
+ residual = hidden_states
448
+ sp_mask = None
449
+
450
+ if self.use_async:
451
+ sp_mask = self.sp_mlp(hidden_states)
452
+
453
+ hidden_states = self.input_layernorm(hidden_states)
454
+
455
+ # Self Attention
456
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
457
+ hidden_states=hidden_states,
458
+ attention_mask=attention_mask,
459
+ position_ids=position_ids,
460
+ past_key_value=past_key_value,
461
+ output_attentions=output_attentions,
462
+ use_cache=use_cache,
463
+ )
464
+ hidden_states = residual + hidden_states
465
+
466
+ # Fully Connected
467
+ residual = hidden_states
468
+ hidden_states = self.post_attention_layernorm(hidden_states)
469
+
470
+ if not self.use_async:
471
+ sp_mask = self.sp_mlp(hidden_states)
472
+
473
+ # Compute distillation loss
474
+ gating_output = self.mlp.sparse_act_fn(self.mlp.gate_proj(hidden_states))
475
+ loss_func = MSELoss()
476
+ self.distill_loss = loss_func(sp_mask, gating_output)
477
+
478
+ # Convert sp mask into binary form
479
+ sp_mask = sp_mask > 0
480
+
481
+ if self.training:
482
+ sp_mask = None
483
+ # if not self.use_sparse_predictor:
484
+ # sp_mask = None
485
+
486
+ hidden_states = self.mlp(hidden_states, sp_mask)
487
+ hidden_states = residual + hidden_states
488
+
489
+ outputs = (hidden_states,)
490
+
491
+ if output_attentions:
492
+ outputs += (self_attn_weights,)
493
+
494
+ if use_cache:
495
+ outputs += (present_key_value,)
496
+
497
+ return outputs
498
+
499
+
500
+ class SparseMistralConfig(MistralConfig):
501
+ model_type = "sparse_mistral"
502
+
503
+ def __init__(self, **kwargs):
504
+ super().__init__(**kwargs)
505
+
506
+
507
+ class SparseMistralforCausalLM(MistralForCausalLM):
508
+ config_class = SparseMistralConfig
509
+
510
+ def __init__(self, config):
511
+ super().__init__(config)
512
+ self.config = config
513
+ if config.use_sparse_model:
514
+ self.apply_sparse_mlp()
515
+ if config.thresholds is not None:
516
+ for idx, m in enumerate(self.model.layers):
517
+ if isinstance(m.mlp, MistralSparseSiluMLP):
518
+ m.mlp.dead_threshold = config.thresholds[idx]
519
+ m.mlp.sparse_act_fn.set_new_threshold(m.mlp.dead_threshold)
520
+ m.mlp.kill_sparse_swish_outputs = True
521
+ m.mlp.use_relu = config.use_relu
522
+ if config.use_sparse_predictor:
523
+ self.apply_sparse_predictor(init_svd=config.init_svd)
524
+
525
+ def apply_sparse_mlp(self):
526
+ apply_mistral_sparse_silu_mlp(
527
+ self,
528
+ config=self.config,
529
+ use_sparse_regularization=self.config.use_sparse_regularization,
530
+ )
531
+
532
+ def apply_sparse_predictor(self, init_svd: bool = True):
533
+ apply_mistral_sparse_decoder_layer(self, config=self.config, init_svd=init_svd)
534
+
535
+
536
+ class GracefulRegularizationScheduler(TrainerCallback):
537
+ def __init__(
538
+ self,
539
+ num_warmup_steps=40,
540
+ is_enabled: bool = False,
541
+ model_name: str = "mistral",
542
+ test_dataset: Dataset = None,
543
+ targeted_sparsity: float = 0.5,
544
+ keep_regularization_with_kill: bool = False,
545
+ ):
546
+ """Scheduler for regularizing the model first before applying the dead threshold.
547
+
548
+ :param num_warmup_steps: number of training steps required to reach the dead threshold, defaults to 40
549
+ :param increment_ratio: by how much to increase the dead threshold.
550
+ For example, 0.5 means "increase the threshold by 0.5 * desired threshold
551
+ """
552
+ self.num_warmup_steps = num_warmup_steps
553
+ self.is_enabled = is_enabled
554
+ self.model_name = model_name
555
+ self.test_dataset = test_dataset
556
+ self.targeted_sparsity = targeted_sparsity
557
+ self.keep_regularization_with_kill = keep_regularization_with_kill
558
+ self.act_hist_path = f"/matx/u/vxbrando/histograms/warm_up_reg_{targeted_sparsity}/act_hist.pt"
559
+ if self.is_enabled:
560
+ print("GracefulRegularizationScheduler is enabled.")
561
+ self.trainer = None
562
+
563
+ def set_trainer(self, trainer):
564
+ self.trainer = trainer
565
+
566
+ def on_step_end(self, args, state, control, **kwargs):
567
+ if not self.is_enabled:
568
+ return
569
+
570
+ model = kwargs["model"]
571
+ if isinstance(model, PeftModel):
572
+ base_model = model.get_base_model()
573
+ else:
574
+ base_model = model
575
+
576
+ if state.global_step == 1:
577
+ ds_print("Setting an initial reg threshold to 0.1")
578
+ set_regularization_threshold(base_model, 0.1)
579
+
580
+ # if state.global_step >= self.num_warmup_steps and state.global_step % 50 == 0:
581
+ if state.global_step == self.num_warmup_steps:
582
+ activate_stats(base_model)
583
+ enable_sparse_silu(base_model)
584
+ self.trainer.evaluate()
585
+ save_act_hist(base_model, self.act_hist_path)
586
+ set_sparse_threshold(base_model, self.targeted_sparsity, True)
587
+ deactivate_stats(base_model)
588
+ self.trainer.use_sparse_regularization = self.keep_regularization_with_kill
589
+ # set_layer_specific_regularization(model.get_base_model())
590
+ print_dead_neuron_stats(model.get_base_model())
591
+
592
+ if state.global_step % 2000 == 0:
593
+ if is_mainprocess():
594
+ ds_print(
595
+ f"Saving to /scr/lukeai/{self.model_name}_{state.global_step}.pt",
596
+ )
597
+ torch.save(
598
+ model.state_dict(),
599
+ f"/scr/lukeai/{self.model_name}_{state.global_step}.pt",
600
+ )
601
+
602
+
603
+ class GradualSparsificationScheduler(TrainerCallback):
604
+ def __init__(
605
+ self,
606
+ num_warmup_steps=40,
607
+ increment_ratio=0.5,
608
+ is_enabled: bool = False,
609
+ model_name: str = "mistral",
610
+ ):
611
+ """Scheduler for gradually increasing a dead threshold until it reaches the desired threshold.
612
+
613
+ :param num_warmup_steps: number of training steps required to reach the dead threshold, defaults to 40
614
+ :param increment_ratio: by how much to increase the dead threshold.
615
+ For example, 0.5 means "increase the threshold by 0.5 * desired threshold
616
+ """
617
+ self.num_warmup_steps = num_warmup_steps
618
+ self.increment_ratio = increment_ratio
619
+ self.step_size = int(num_warmup_steps * increment_ratio)
620
+ self.is_enabled = is_enabled
621
+ self.model_name = model_name
622
+
623
+ def on_step_end(self, args, state, control, **kwargs):
624
+ model = kwargs["model"]
625
+
626
+ if not self.is_enabled:
627
+ if state.global_step <= 10:
628
+ for module in model.modules():
629
+ if isinstance(module, MistralSparseSiluMLP):
630
+ module.current_dead_threshold = module.dead_threshold
631
+ return
632
+
633
+ current_dead_threshold = 0
634
+ desired_dead_threshold = 0
635
+
636
+ if is_mainprocess():
637
+ ds_print(state.global_step)
638
+
639
+ if state.global_step % self.step_size == 2:
640
+ for module in model.modules():
641
+ if isinstance(module, MistralSparseSiluMLP):
642
+ desired_dead_threshold = copy.deepcopy(module.dead_threshold)
643
+ current_dead_threshold = module.current_dead_threshold
644
+ current_dead_threshold += self.increment_ratio * desired_dead_threshold
645
+ module.current_dead_threshold = min(desired_dead_threshold, current_dead_threshold)
646
+
647
+ if is_running_deepspeed and is_mainprocess():
648
+ ds_print(
649
+ state.global_step,
650
+ current_dead_threshold,
651
+ desired_dead_threshold,
652
+ )
653
+
654
+ if state.global_step % 2000 == 0:
655
+ if is_running_deepspeed and is_mainprocess():
656
+ ds_print(
657
+ f"Saving to /matx/u/lukeai/{self.model_name}_{state.global_step - 2}.pt",
658
+ )
659
+ torch.save(
660
+ model.state_dict(),
661
+ f"/matx/u/lukeai/{self.model_name}_{state.global_step - 2}.pt",
662
+ )
663
+
664
+
665
+ def get_sparse_mistral_config(
666
+ config: MistralConfig,
667
+ use_sparse_model=False,
668
+ use_sparse_predictor=False,
669
+ use_sparse_regularization=False,
670
+ thresholds=None,
671
+ ):
672
+ new_config = SparseMistralConfig()
673
+ new_config.__dict__.update(config.__dict__)
674
+ config = new_config
675
+ config.use_sparse_model = use_sparse_model
676
+ config.use_sparse_predictor = use_sparse_predictor
677
+ config.use_sparse_regularization = use_sparse_regularization
678
+ config.thresholds = thresholds
679
+
680
+ return config
681
+
682
+
683
+ def apply_mistral_sparse_silu_mlp(
684
+ model,
685
+ config,
686
+ use_sparse_regularization: bool = False,
687
+ ):
688
+ # counts = 0
689
+ for layer in model.model.layers:
690
+ # counts += 1
691
+ # if counts < 4:
692
+ # continue
693
+ original_mlp = layer.mlp
694
+ new_mlp = MistralSparseSiluMLP(config, use_sparse_regularization=use_sparse_regularization)
695
+ new_mlp.gate_proj = original_mlp.gate_proj
696
+ new_mlp.up_proj = original_mlp.up_proj
697
+ new_mlp.down_proj = original_mlp.down_proj
698
+ layer.mlp = new_mlp
699
+
700
+
701
+ def apply_mistral_sparse_decoder_layer(
702
+ model,
703
+ config,
704
+ init_svd: bool = True,
705
+ ):
706
+ assert isinstance(model.model, MistralModel), "model.model must be a MistralModel."
707
+ new_layers = []
708
+ for layer_idx, layer in enumerate(model.model.layers):
709
+ if isinstance(layer.mlp, MistralSparseSiluMLP):
710
+ new_layers.append(
711
+ SparseMistralDecoderLayer(
712
+ config=config,
713
+ layer_idx=layer_idx,
714
+ decoder_layer=layer,
715
+ init_svd=init_svd,
716
+ )
717
+ )
718
+ print(f"{layer_idx}th mlp layer activation: {layer.mlp.sparse_act_fn}")
719
+ else:
720
+ new_layers.append(layer)
721
+ model.model.layers = nn.ModuleList(new_layers)
722
+
723
+
724
+ def enable_sparse_predictor(
725
+ model,
726
+ ):
727
+ for layer_idx, layer in enumerate(model.model.layers):
728
+ if isinstance(layer, MistralDecoderLayer):
729
+ layer.use_sparse_predictor = True
730
+
731
+
732
+ def disable_sparse_predictor(
733
+ model,
734
+ ):
735
+ for layer_idx, layer in enumerate(model.model.layers):
736
+ if isinstance(layer, MistralDecoderLayer):
737
+ layer.use_sparse_predictor = False
738
+
739
+
740
+ def activate_stats(model, is_collect_histogram: bool = True):
741
+ for layer in model.model.layers:
742
+ if isinstance(layer.mlp, MistralSparseSiluMLP):
743
+ layer.mlp.activate_stats(is_collect_histogram=is_collect_histogram)
744
+
745
+
746
+ def deactivate_stats(model):
747
+ for layer in model.model.layers:
748
+ if isinstance(layer.mlp, MistralSparseSiluMLP):
749
+ layer.mlp.deactivate_stats()
750
+
751
+
752
+ def enable_sparse_silu(model):
753
+ ds_print("Enabling SparseSilu")
754
+ for i, layer in enumerate(model.model.layers):
755
+ if isinstance(layer.mlp, MistralSparseSiluMLP):
756
+ layer.mlp.kill_sparse_swish_outputs = True
757
+
758
+
759
+ def print_dead_neuron_stats(model):
760
+ total_sparsity = 0
761
+ counts = 0
762
+ for i, layer in enumerate(model.model.layers):
763
+ if isinstance(layer.mlp, MistralSparseSiluMLP):
764
+ dead_percentage = layer.mlp.dead_percentage * 100
765
+ agg_sparsity = layer.mlp.agg_sparsity * 100
766
+ ds_print(f"layer {i} sparsity: {dead_percentage:.3f}%")
767
+ ds_print(f"layer {i} agg sparsity: {agg_sparsity:.3f}%")
768
+ total_sparsity += dead_percentage
769
+ counts += 1
770
+
771
+ ds_print(f"Total sparsity: {total_sparsity/counts: .3f}%")
772
+ return total_sparsity / counts
773
+
774
+
775
+ def get_sparse_layers(model: MistralModel):
776
+ sparse_layers = [m.mlp for m in model.layers() if isinstance(m.mlp, MistralSparseSiluMLP)]
777
+ return sparse_layers
778
+
779
+
780
+ def get_threshold(bin_edges: torch.tensor, histogram_counts: torch.tensor, sparsity_level: float): # Only for L1 Regularization
781
+ assert len(bin_edges.shape) == len(histogram_counts.shape) == 1, "bin_edges and histogram are expected to be 1-dimensional."
782
+ histogram_counts /= histogram_counts.sum()
783
+ threshold_idx = torch.searchsorted(histogram_counts.cumsum(0), sparsity_level, side="right")
784
+
785
+ return bin_edges[threshold_idx]
786
+
787
+
788
+ def set_regularization_threshold(model, threshold: float = 0.1):
789
+ for i, layer in enumerate(model.model.layers):
790
+ if (
791
+ isinstance(layer.mlp, MistralSparseSiluMLP) and layer.mlp.is_stats
792
+ ): # Can set the threshold only the relevant statistics is collected.
793
+ layer.mlp.regularization_threshold = threshold # TODO: find better param
794
+
795
+
796
+ def set_sparse_threshold(model, sparsity_level: float, use_relu: bool = False):
797
+ for i, layer in enumerate(model.model.layers):
798
+ if (
799
+ isinstance(layer.mlp, MistralSparseSiluMLP) and layer.mlp.is_stats
800
+ ): # Can set the threshold only the relevant statistics is collected.
801
+ if use_relu:
802
+ layer.mlp.sparse_act_fn = nn.ReLU()
803
+ layer.mlp.use_relu = True
804
+ else:
805
+ layer.mlp.dead_threshold = get_threshold(
806
+ layer.mlp.histogram_bins,
807
+ layer.mlp.post_act_hist_counts,
808
+ sparsity_level,
809
+ )
810
+ layer.mlp.sparse_act_fn.set_new_threshold(layer.mlp.dead_threshold)
811
+ layer.mlp.regularization_threshold = layer.mlp.dead_threshold * 1.2 # TODO: find better param
812
+
813
+
814
+ def plot_histogram(
815
+ bin_edges,
816
+ histogram_counts: torch.tensor,
817
+ title: str = "Activation Distribution",
818
+ fig_dir: str = "figures",
819
+ ):
820
+ plt.bar(bin_edges[:-1], histogram_counts, width=np.diff(bin_edges), edgecolor="black")
821
+ plt.title(title)
822
+ plt.xlabel("Activation Value")
823
+ plt.ylabel("Frequency")
824
+ os.makedirs(fig_dir, exist_ok=True)
825
+ plt.savefig(f"{fig_dir}/{title}.png")
826
+ # plt.show()
827
+ plt.clf()
828
+
829
+
830
+ def plot_act(model, fig_dir: str = "figures"):
831
+ for i, layer in enumerate(model.model.layers):
832
+ if (
833
+ isinstance(layer.mlp, MistralSparseSiluMLP) and layer.mlp.is_stats
834
+ ): # Can set the threshold only the relevant statistics is collected.
835
+ plot_title = f"Layer: {i} Pre-Activation Distribution"
836
+ plot_histogram(layer.mlp.histogram_bins, layer.mlp.pre_act_hist_counts, plot_title)
837
+
838
+ plot_title = f"Layer: {i} Post-Activation Absolute Distribution"
839
+ plot_histogram(layer.mlp.histogram_bins, layer.mlp.post_act_hist_counts, plot_title)
840
+
841
+
842
+ def save_act_hist(model, filename="/scr/jay/models/mistral/pre_finetune/cola_act_hist.pt"):
843
+ os.makedirs(os.path.dirname(filename), exist_ok=True)
844
+ act_dict = {}
845
+ for i, layer in enumerate(model.model.layers):
846
+ if (
847
+ isinstance(layer.mlp, MistralSparseSiluMLP) and layer.mlp.is_stats
848
+ ): # Can set the threshold only the relevant statistics is collected.
849
+ act_dict[i] = (
850
+ layer.mlp.histogram_bins,
851
+ layer.mlp.pre_act_hist_counts,
852
+ layer.mlp.post_act_hist_counts,
853
+ )
854
+ print("Saving activation histograms...\n\n\n")
855
+ torch.save(act_dict, filename)
856
+
857
+
858
+ def load_act_hist(model, filename="/scr/jay/models/mistral/pre_finetune/cola_act_hist.pt"):
859
+ assert os.path.exists(filename), f"{filename} does not exist when loading pre/post-activation histogram of SparseMistralSiluMLP."
860
+ print("Loading activation histograms...\n\n\n")
861
+
862
+ act_dict = torch.load(filename)
863
+ for i, layer in enumerate(model.model.layers):
864
+ if (
865
+ isinstance(layer.mlp, MistralSparseSiluMLP) and layer.mlp.is_stats
866
+ ): # Can set the threshold only the relevant statistics is collected.
867
+ (
868
+ layer.mlp.histogram_bins,
869
+ layer.mlp.pre_act_hist_counts,
870
+ layer.mlp.post_act_hist_counts,
871
+ ) = act_dict[i]
872
+
873
+
874
+ def enable_last_k_modules(model, start_module_idx: int):
875
+ assert 32 > start_module_idx >= 0
876
+ new_modules = []
877
+ new_idx = 0
878
+ for idx in range(start_module_idx, len(model.model.original_layers)):
879
+ module = model.model.original_layers[idx]
880
+ module.layer_idx = new_idx
881
+ module.self_attn.layer_idx = new_idx
882
+ new_modules.append(module)
883
+ new_idx += 1
884
+ print(module.layer_idx)
885
+
886
+ model.model.layers = nn.ModuleList(new_modules)
887
+
888
+
889
+ def enable_first_k_modules(model, end_module_idx: int):
890
+ assert 32 > end_module_idx >= 0
891
+ new_modules = []
892
+ new_idx = 0
893
+ for idx in range(0, end_module_idx + 1):
894
+ module = model.model.original_layers[idx]
895
+ module.layer_idx = new_idx
896
+ module.self_attn.layer_idx = new_idx
897
+ new_modules.append(module)
898
+ new_idx += 1
899
+ print(module.layer_idx)
900
+
901
+ model.model.layers = nn.ModuleList(new_modules)
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "</s>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ }
29
+ },
30
+ "additional_special_tokens": [],
31
+ "bos_token": "<s>",
32
+ "clean_up_tokenization_spaces": false,
33
+ "eos_token": "</s>",
34
+ "legacy": true,
35
+ "model_max_length": 1000000000000000019884624838656,
36
+ "pad_token": "</s>",
37
+ "sp_model_kwargs": {},
38
+ "spaces_between_special_tokens": false,
39
+ "tokenizer_class": "LlamaTokenizer",
40
+ "unk_token": "<unk>",
41
+ "use_default_system_prompt": false
42
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:322a1d7ab709fd32015d4e41516cc47ad6a8cc36e1beeafbf8c431cda5ee2da2
3
+ size 4728