HashTag766 commited on
Commit
074f273
·
verified ·
1 Parent(s): 0d9eb3b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +123 -0
README.md CHANGED
@@ -31,6 +31,129 @@ datasets:
31
  - **License:** apache-2.0
32
  - **Finetuned from model :** SaintHoney/PersonalManV1.0
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
35
 
36
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
31
  - **License:** apache-2.0
32
  - **Finetuned from model :** SaintHoney/PersonalManV1.0
33
 
34
+ ## The code used for finetuning
35
+
36
+ ```python
37
+ %%capture
38
+ !pip install pip3-autoremove
39
+ !pip-autoremove torch torchvision torchaudio -y
40
+ !pip install torch torchvision torchaudio xformers --index-url https://download.pytorch.org/whl/cu121
41
+ !pip install unsloth
42
+
43
+ ---------------------------------------------------------------------------------------------
44
+
45
+ from kaggle_secrets import UserSecretsClient
46
+ user_secrets = UserSecretsClient() # from kaggle_secrets import UserSecretsClient
47
+ hugging_face_token = user_secrets.get_secret("HF-Token")
48
+
49
+ # Login to Hugging Face
50
+ from huggingface_hub import login # Lets you login to API
51
+ login(hugging_face_token) # from huggingface_hub import login
52
+
53
+ ---------------------------------------------------------------------------------------------
54
+
55
+ from unsloth import FastLanguageModel
56
+ import torch
57
+ max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
58
+ dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
59
+ load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
60
+
61
+ model, tokenizer = FastLanguageModel.from_pretrained(
62
+ model_name = "SaintHoney/PersonalManV1.0",
63
+ max_seq_length = max_seq_length,
64
+ dtype = dtype,
65
+ load_in_4bit = load_in_4bit,
66
+ )
67
+
68
+ ---------------------------------------------------------------------------------------------
69
+
70
+ model = FastLanguageModel.get_peft_model(
71
+ model,
72
+ r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
73
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
74
+ "gate_proj", "up_proj", "down_proj",],
75
+ lora_alpha = 16,
76
+ lora_dropout = 0, # Supports any, but = 0 is optimized
77
+ bias = "none", # Supports any, but = "none" is optimized
78
+ # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
79
+ use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
80
+ random_state = 3407,
81
+ use_rslora = False, # We support rank stabilized LoRA
82
+ loftq_config = None, # And LoftQ
83
+ )
84
+
85
+ ---------------------------------------------------------------------------------------------
86
+
87
+ alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
88
+
89
+ ### Instruction:
90
+ {}
91
+
92
+ ### Input:
93
+ {}
94
+
95
+ ### Response:
96
+ {}"""
97
+
98
+ EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
99
+ def formatting_prompts_func(examples):
100
+ instructions = examples["instruction"]
101
+ inputs = examples["input"]
102
+ outputs = examples["output"]
103
+ texts = []
104
+ for instruction, input, output in zip(instructions, inputs, outputs):
105
+ # Must add EOS_TOKEN, otherwise your generation will go on forever!
106
+ text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
107
+ texts.append(text)
108
+ return { "text" : texts, }
109
+ pass
110
+
111
+ from datasets import load_dataset
112
+ dataset = load_dataset("HashTag766/SMART-Goals-Validation", split = "train") # specify here the number of examples from dataset
113
+ dataset = dataset.map(formatting_prompts_func, batched = True,)
114
+
115
+ ---------------------------------------------------------------------------------------------
116
+
117
+ from trl import SFTTrainer
118
+ from transformers import TrainingArguments, DataCollatorForSeq2Seq
119
+ from unsloth import is_bfloat16_supported
120
+
121
+ trainer = SFTTrainer(
122
+ model = model,
123
+ tokenizer = tokenizer,
124
+ train_dataset = dataset,
125
+ dataset_text_field = "text",
126
+ max_seq_length = max_seq_length,
127
+ data_collator = DataCollatorForSeq2Seq(tokenizer = tokenizer),
128
+ dataset_num_proc = 2,
129
+ packing = False, # Can make training 5x faster for short sequences.
130
+ args = TrainingArguments(
131
+ per_device_train_batch_size = 2,
132
+ gradient_accumulation_steps = 4,
133
+ warmup_steps = 5,
134
+ num_train_epochs = 3, # Set this for 1 full training run.
135
+ # max_steps = 60,
136
+ learning_rate = 2e-4,
137
+ fp16 = not is_bfloat16_supported(),
138
+ bf16 = is_bfloat16_supported(),
139
+ logging_steps = 1,
140
+ optim = "adamw_8bit",
141
+ weight_decay = 0.01,
142
+ lr_scheduler_type = "linear",
143
+ seed = 3407,
144
+ output_dir = "outputs",
145
+ report_to = "none", # Use this for WandB etc
146
+ ),
147
+ )
148
+
149
+ trainer_stats = trainer.train()
150
+ ---------------------------------------------------------------------------------------------
151
+
152
+ model.push_to_hub("hf/model...", token = "...") # Online saving
153
+ tokenizer.push_to_hub("hf/model...", token = "...") # Online saving
154
+
155
+ ```
156
+
157
  This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
158
 
159
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)