Upload 11 files
Browse files- config.json +31 -0
- generation_config.json +7 -0
- merges.txt +0 -0
- pytorch_model.bin +3 -0
- run.py +128 -0
- runs/Aug10_20-51-17_coalabserver/events.out.tfevents.1691680887.coalabserver.1729318.0 +3 -0
- special_tokens_map.json +30 -0
- tokenizer.json +0 -0
- tokenizer_config.json +40 -0
- training_args.bin +3 -0
- vocab.json +0 -0
config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "facebook/opt-350m",
|
| 3 |
+
"_remove_final_layer_norm": false,
|
| 4 |
+
"activation_dropout": 0.0,
|
| 5 |
+
"activation_function": "relu",
|
| 6 |
+
"architectures": [
|
| 7 |
+
"OPTForCausalLM"
|
| 8 |
+
],
|
| 9 |
+
"attention_dropout": 0.0,
|
| 10 |
+
"bos_token_id": 2,
|
| 11 |
+
"do_layer_norm_before": false,
|
| 12 |
+
"dropout": 0.1,
|
| 13 |
+
"enable_bias": true,
|
| 14 |
+
"eos_token_id": 2,
|
| 15 |
+
"ffn_dim": 4096,
|
| 16 |
+
"hidden_size": 1024,
|
| 17 |
+
"init_std": 0.02,
|
| 18 |
+
"layer_norm_elementwise_affine": true,
|
| 19 |
+
"layerdrop": 0.0,
|
| 20 |
+
"max_position_embeddings": 2048,
|
| 21 |
+
"model_type": "opt",
|
| 22 |
+
"num_attention_heads": 16,
|
| 23 |
+
"num_hidden_layers": 24,
|
| 24 |
+
"pad_token_id": 1,
|
| 25 |
+
"prefix": "</s>",
|
| 26 |
+
"torch_dtype": "float32",
|
| 27 |
+
"transformers_version": "4.30.2",
|
| 28 |
+
"use_cache": true,
|
| 29 |
+
"vocab_size": 50272,
|
| 30 |
+
"word_embed_proj_dim": 512
|
| 31 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 2,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"pad_token_id": 1,
|
| 6 |
+
"transformers_version": "4.30.2"
|
| 7 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9bdc0f6367beb73dcde585f6cc516c7a38274144593c3962af90a886d67a7ce3
|
| 3 |
+
size 1324917277
|
run.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
from dataclasses import dataclass, field
|
| 16 |
+
from typing import Optional
|
| 17 |
+
|
| 18 |
+
import torch
|
| 19 |
+
from datasets import load_dataset
|
| 20 |
+
from peft import LoraConfig
|
| 21 |
+
from tqdm import tqdm
|
| 22 |
+
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, HfArgumentParser, TrainingArguments
|
| 23 |
+
|
| 24 |
+
from trl import SFTTrainer
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
tqdm.pandas()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Define and parse arguments.
|
| 31 |
+
@dataclass
|
| 32 |
+
class ScriptArguments:
|
| 33 |
+
"""
|
| 34 |
+
The name of the Casual LM model we wish to fine with SFTTrainer
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
model_name: Optional[str] = field(default="facebook/opt-350m", metadata={"help": "the model name"})
|
| 38 |
+
dataset_name: Optional[str] = field(
|
| 39 |
+
default="timdettmers/openassistant-guanaco", metadata={"help": "the dataset name"}
|
| 40 |
+
)
|
| 41 |
+
dataset_text_field: Optional[str] = field(default="text", metadata={"help": "the text field of the dataset"})
|
| 42 |
+
log_with: Optional[str] = field(default=None, metadata={"help": "use 'wandb' to log with wandb"})
|
| 43 |
+
learning_rate: Optional[float] = field(default=1.41e-5, metadata={"help": "the learning rate"})
|
| 44 |
+
batch_size: Optional[int] = field(default=8, metadata={"help": "the batch size"}) # 64 original
|
| 45 |
+
seq_length: Optional[int] = field(default=512, metadata={"help": "Input sequence length"})
|
| 46 |
+
gradient_accumulation_steps: Optional[int] = field(
|
| 47 |
+
default=2, metadata={"help": "the number of gradient accumulation steps"}
|
| 48 |
+
)
|
| 49 |
+
load_in_8bit: Optional[bool] = field(default=False, metadata={"help": "load the model in 8 bits precision"})
|
| 50 |
+
load_in_4bit: Optional[bool] = field(default=False, metadata={"help": "load the model in 4 bits precision"})
|
| 51 |
+
use_peft: Optional[bool] = field(default=False, metadata={"help": "Wether to use PEFT or not to train adapters"})
|
| 52 |
+
trust_remote_code: Optional[bool] = field(default=True, metadata={"help": "Enable `trust_remote_code`"})
|
| 53 |
+
output_dir: Optional[str] = field(default="./", metadata={"help": "the output directory"})
|
| 54 |
+
peft_lora_r: Optional[int] = field(default=8, metadata={"help": "the r parameter of the LoRA adapters"})
|
| 55 |
+
peft_lora_alpha: Optional[int] = field(default=2, metadata={"help": "the alpha parameter of the LoRA adapters"})
|
| 56 |
+
logging_steps: Optional[int] = field(default=1, metadata={"help": "the number of logging steps"})
|
| 57 |
+
use_auth_token: Optional[bool] = field(default=True, metadata={"help": "Use HF auth token to access the model"})
|
| 58 |
+
num_train_epochs: Optional[int] = field(default=2, metadata={"help": "the number of training epochs"})
|
| 59 |
+
max_steps: Optional[int] = field(default=-1, metadata={"help": "the number of training steps"})
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
parser = HfArgumentParser(ScriptArguments)
|
| 63 |
+
script_args = parser.parse_args_into_dataclasses()[0]
|
| 64 |
+
|
| 65 |
+
# Step 1: Load the model
|
| 66 |
+
if script_args.load_in_8bit and script_args.load_in_4bit:
|
| 67 |
+
raise ValueError("You can't load the model in 8 bits and 4 bits at the same time")
|
| 68 |
+
elif script_args.load_in_8bit or script_args.load_in_4bit:
|
| 69 |
+
quantization_config = BitsAndBytesConfig(
|
| 70 |
+
load_in_8bit=script_args.load_in_8bit, load_in_4bit=script_args.load_in_4bit
|
| 71 |
+
)
|
| 72 |
+
# This means: fit the entire model on the GPU:0
|
| 73 |
+
device_map = {"": 0}
|
| 74 |
+
torch_dtype = torch.bfloat16
|
| 75 |
+
else:
|
| 76 |
+
device_map = None
|
| 77 |
+
quantization_config = None
|
| 78 |
+
torch_dtype = None
|
| 79 |
+
|
| 80 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 81 |
+
script_args.model_name,
|
| 82 |
+
quantization_config=quantization_config,
|
| 83 |
+
device_map=device_map,
|
| 84 |
+
trust_remote_code=script_args.trust_remote_code,
|
| 85 |
+
torch_dtype=torch_dtype,
|
| 86 |
+
use_auth_token=script_args.use_auth_token,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Step 2: Load the dataset
|
| 90 |
+
dataset = load_dataset(script_args.dataset_name, split="train")
|
| 91 |
+
|
| 92 |
+
# Step 3: Define the training arguments
|
| 93 |
+
training_args = TrainingArguments(
|
| 94 |
+
output_dir=script_args.output_dir,
|
| 95 |
+
per_device_train_batch_size=script_args.batch_size,
|
| 96 |
+
gradient_accumulation_steps=script_args.gradient_accumulation_steps,
|
| 97 |
+
learning_rate=script_args.learning_rate,
|
| 98 |
+
logging_steps=script_args.logging_steps,
|
| 99 |
+
num_train_epochs=script_args.num_train_epochs,
|
| 100 |
+
max_steps=script_args.max_steps,
|
| 101 |
+
report_to=script_args.log_with,
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# Step 4: Define the LoraConfig
|
| 105 |
+
if script_args.use_peft:
|
| 106 |
+
peft_config = LoraConfig(
|
| 107 |
+
r=script_args.peft_lora_r,
|
| 108 |
+
lora_alpha=script_args.peft_lora_alpha,
|
| 109 |
+
bias="none",
|
| 110 |
+
task_type="CAUSAL_LM",
|
| 111 |
+
)
|
| 112 |
+
else:
|
| 113 |
+
peft_config = None
|
| 114 |
+
|
| 115 |
+
# Step 5: Define the Trainer
|
| 116 |
+
trainer = SFTTrainer(
|
| 117 |
+
model=model,
|
| 118 |
+
args=training_args,
|
| 119 |
+
max_seq_length=script_args.seq_length,
|
| 120 |
+
train_dataset=dataset,
|
| 121 |
+
dataset_text_field=script_args.dataset_text_field,
|
| 122 |
+
peft_config=peft_config,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
trainer.train()
|
| 126 |
+
|
| 127 |
+
# Step 6: Save the model
|
| 128 |
+
trainer.save_model(script_args.output_dir)
|
runs/Aug10_20-51-17_coalabserver/events.out.tfevents.1691680887.coalabserver.1729318.0
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:12c426a36bd9563e1f716ccb0339dc03c9c6dc5062a547e5b4f82f68a3d093bb
|
| 3 |
+
size 197127
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "</s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "</s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<pad>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": true,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "</s>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": true,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": true,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"bos_token": {
|
| 5 |
+
"__type": "AddedToken",
|
| 6 |
+
"content": "</s>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": true,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"clean_up_tokenization_spaces": true,
|
| 13 |
+
"eos_token": {
|
| 14 |
+
"__type": "AddedToken",
|
| 15 |
+
"content": "</s>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": true,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false
|
| 20 |
+
},
|
| 21 |
+
"errors": "replace",
|
| 22 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 23 |
+
"pad_token": {
|
| 24 |
+
"__type": "AddedToken",
|
| 25 |
+
"content": "<pad>",
|
| 26 |
+
"lstrip": false,
|
| 27 |
+
"normalized": true,
|
| 28 |
+
"rstrip": false,
|
| 29 |
+
"single_word": false
|
| 30 |
+
},
|
| 31 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 32 |
+
"unk_token": {
|
| 33 |
+
"__type": "AddedToken",
|
| 34 |
+
"content": "</s>",
|
| 35 |
+
"lstrip": false,
|
| 36 |
+
"normalized": true,
|
| 37 |
+
"rstrip": false,
|
| 38 |
+
"single_word": false
|
| 39 |
+
}
|
| 40 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:335121ffe87b7016aa5fd6bf5ae4639f01b9fb9a5624b64502fe3a37561c6fb9
|
| 3 |
+
size 3899
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|