aifeifei798 commited on
Commit
9fae77c
·
verified ·
1 Parent(s): 3be04c1

Upload 2 files

Browse files
Files changed (2) hide show
  1. Llama-3.2-3B-Instruct-lyrics.jpg +0 -0
  2. README.md +350 -0
Llama-3.2-3B-Instruct-lyrics.jpg ADDED
README.md ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - de
5
+ - fr
6
+ - it
7
+ - pt
8
+ - hi
9
+ - es
10
+ - th
11
+ - zh
12
+ - ko
13
+ - ja
14
+ license: llama3.2
15
+ pipeline_tag: text-generation
16
+ tags:
17
+ - roleplay
18
+ - llama3
19
+ - sillytavern
20
+ - idol
21
+ - facebook
22
+ - meta
23
+ - pytorch
24
+ - llama
25
+ - llama-3
26
+ extra_gated_fields:
27
+ First Name: text
28
+ Last Name: text
29
+ Date of birth: date_picker
30
+ Country: country
31
+ Affiliation: text
32
+ Job title:
33
+ type: select
34
+ options:
35
+ - Student
36
+ - Research Graduate
37
+ - AI researcher
38
+ - AI developer/engineer
39
+ - Reporter
40
+ - Other
41
+ ---
42
+ # Llama-3.2-3B-Instruct-lyrics
43
+ ![image/png](https://huggingface.co/aifeifei798/Llama-3.2-3B-Instruct-lyrics/resolve/main/Llama-3.2-3B-Instruct-lyrics.jpg)
44
+ ## "transformers_version" >= "4.43.1"
45
+ ## Model Information
46
+ - write song on my phone
47
+
48
+
49
+ ## virtual idol Twitter
50
+ - https://x.com/aifeifei799
51
+
52
+ ## Datasets credits:
53
+ - Koyd111/alpaca-hiphop-lyrics
54
+
55
+ ## Program:
56
+ - unsloth
57
+
58
+ ### Test Prograpm
59
+
60
+ '''python
61
+ from unsloth import FastLanguageModel
62
+ from unsloth import PatchFastRL
63
+ PatchFastRL("GRPO", FastLanguageModel)
64
+ import torch
65
+ max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
66
+ dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
67
+ load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
68
+
69
+ 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.
70
+
71
+ ### Instruction:
72
+ {}
73
+
74
+ ### Input:
75
+ {}
76
+
77
+ ### Response:
78
+ {}"""
79
+
80
+ model, tokenizer = FastLanguageModel.from_pretrained(
81
+ model_name = "./Llama-3.2-3B-Instruct-lyrics", # or choose "unsloth/Llama-3.2-1B-Instruct"
82
+ max_seq_length = max_seq_length,
83
+ dtype = dtype,
84
+ # load_in_4bit = load_in_4bit,
85
+ # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
86
+ )
87
+
88
+ if False:
89
+ from unsloth import FastLanguageModel
90
+ model, tokenizer = FastLanguageModel.from_pretrained(
91
+ model_name = "Llama-3.2-1B-Instruct-bnb-4bit-lora", # YOUR MODEL YOU USED FOR TRAINING
92
+ max_seq_length = max_seq_length,
93
+ dtype = dtype,
94
+ load_in_4bit = load_in_4bit,
95
+ )
96
+ FastLanguageModel.for_inference(model) # Enable native 2x faster inference
97
+
98
+ # alpaca_prompt = You MUST copy from above!
99
+
100
+ inputs = tokenizer(
101
+ [
102
+ alpaca_prompt.format(
103
+ "", # instruction
104
+ """ new write a pop love song.
105
+ song name:
106
+ Style of Music(five components: genre, instrument, mood, gender, and timbre. ):
107
+ [Intro]
108
+ [Verse 1]
109
+ [Chorus]
110
+ [Verse 2]
111
+ [Chorus]
112
+ [Bridge]
113
+ [Chorus]
114
+ [Outro] """, # input
115
+ "", # output - leave this blank for generation!
116
+ )
117
+ ], return_tensors = "pt").to("cuda")
118
+
119
+ from transformers import TextStreamer
120
+ text_streamer = TextStreamer(tokenizer)
121
+ _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 1024)
122
+
123
+ #model.save_pretrained_merged("Llama-3.2-1B-Instruct-bnb-4bit-end", tokenizer)
124
+
125
+
126
+ '''
127
+
128
+ ### Trainer Prograpm
129
+
130
+ '''python
131
+ from unsloth import FastLanguageModel
132
+ import torch
133
+ max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
134
+ dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
135
+ load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
136
+
137
+ # 4bit pre quantized models we support for 4x faster downloading + no OOMs.
138
+ fourbit_models = [
139
+ "unsloth/Meta-Llama-3.1-8B-bnb-4bit", # Llama-3.1 2x faster
140
+ "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
141
+ "unsloth/Meta-Llama-3.1-70B-bnb-4bit",
142
+ "unsloth/Meta-Llama-3.1-405B-bnb-4bit", # 4bit for 405b!
143
+ "unsloth/Mistral-Small-Instruct-2409", # Mistral 22b 2x faster!
144
+ "unsloth/mistral-7b-instruct-v0.3-bnb-4bit",
145
+ "unsloth/Phi-3.5-mini-instruct", # Phi-3.5 2x faster!
146
+ "unsloth/Phi-3-medium-4k-instruct",
147
+ "unsloth/gemma-2-9b-bnb-4bit",
148
+ "unsloth/gemma-2-27b-bnb-4bit", # Gemma 2x faster!
149
+
150
+ "unsloth/Llama-3.2-1B-bnb-4bit", # NEW! Llama 3.2 models
151
+ "unsloth/Llama-3.2-1B-Instruct-bnb-4bit",
152
+ "unsloth/Llama-3.2-3B-bnb-4bit",
153
+ "unsloth/Llama-3.2-3B-Instruct-bnb-4bit",
154
+
155
+ "unsloth/Llama-3.3-70B-Instruct-bnb-4bit" # NEW! Llama 3.3 70B!
156
+ ] # More models at https://huggingface.co/unsloth
157
+
158
+ model, tokenizer = FastLanguageModel.from_pretrained(
159
+ model_name = "./Llama-3.2-3B-Instruct-unsloth-bnb-4bit", # or choose "unsloth/Llama-3.2-1B-Instruct"
160
+ max_seq_length = max_seq_length,
161
+ dtype = dtype,
162
+ load_in_4bit = load_in_4bit,
163
+ # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
164
+ )
165
+
166
+ model = FastLanguageModel.get_peft_model(
167
+ model,
168
+ r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
169
+ target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
170
+ "gate_proj", "up_proj", "down_proj",],
171
+ lora_alpha = 16,
172
+ lora_dropout = 0, # Supports any, but = 0 is optimized
173
+ bias = "none", # Supports any, but = "none" is optimized
174
+ # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
175
+ use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
176
+ random_state = 3407,
177
+ use_rslora = False, # We support rank stabilized LoRA
178
+ loftq_config = None, # And LoftQ
179
+ )
180
+
181
+ from unsloth.chat_templates import get_chat_template
182
+
183
+ tokenizer = get_chat_template(
184
+ tokenizer,
185
+ chat_template = "llama-3.2",
186
+ )
187
+
188
+ 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.
189
+
190
+ ### Instruction:
191
+ {}
192
+
193
+ ### Input:
194
+ {}
195
+
196
+ ### Response:
197
+ {}"""
198
+
199
+ EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
200
+ def formatting_prompts_func(examples):
201
+ instructions = examples["instruction"]
202
+ inputs = examples["input"]
203
+ outputs = examples["output"]
204
+ texts = []
205
+ for instruction, input, output in zip(instructions, inputs, outputs):
206
+ # Must add EOS_TOKEN, otherwise your generation will go on forever!
207
+ text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
208
+ texts.append(text)
209
+ return { "text" : texts, }
210
+ pass
211
+
212
+ from datasets import load_dataset
213
+ dataset = load_dataset("Koyd111/alpaca-hiphop-lyrics", split = "train")
214
+ dataset = dataset.map(formatting_prompts_func, batched = True,)
215
+ print(dataset[5])
216
+
217
+ from trl import SFTTrainer
218
+ from transformers import TrainingArguments, DataCollatorForSeq2Seq
219
+ from unsloth import is_bfloat16_supported
220
+
221
+ trainer = SFTTrainer(
222
+ model = model,
223
+ tokenizer = tokenizer,
224
+ train_dataset = dataset,
225
+ dataset_text_field = "text",
226
+ max_seq_length = max_seq_length,
227
+ dataset_num_proc = 16,
228
+ packing = False, # Can make training 5x faster for short sequences.
229
+ args = TrainingArguments(
230
+ per_device_train_batch_size = 2,
231
+ gradient_accumulation_steps = 4,
232
+ warmup_steps = 5,
233
+ # num_train_epochs = 1, # Set this for 1 full training run.
234
+ max_steps = 60,
235
+ learning_rate = 2e-4,
236
+ fp16 = not is_bfloat16_supported(),
237
+ bf16 = is_bfloat16_supported(),
238
+ logging_steps = 1,
239
+ optim = "adamw_8bit",
240
+ weight_decay = 0.01,
241
+ lr_scheduler_type = "linear",
242
+ seed = 3407,
243
+ output_dir = "outputs",
244
+ report_to = "none", # Use this for WandB etc
245
+ ),
246
+ )
247
+
248
+ trainer_stats = trainer.train()
249
+
250
+ # alpaca_prompt = Copied from above
251
+ FastLanguageModel.for_inference(model) # Enable native 2x faster inference
252
+ inputs = tokenizer(
253
+ [
254
+ alpaca_prompt.format(
255
+ "Continue the fibonnaci sequence.", # instruction
256
+ "1, 1, 2, 3, 5, 8", # input
257
+ "", # output - leave this blank for generation!
258
+ )
259
+ ], return_tensors = "pt").to("cuda")
260
+
261
+ # alpaca_prompt = Copied from above
262
+ FastLanguageModel.for_inference(model) # Enable native 2x faster inference
263
+ inputs = tokenizer(
264
+ [
265
+ alpaca_prompt.format(
266
+ "Continue the fibonnaci sequence.", # instruction
267
+ "1, 1, 2, 3, 5, 8", # input
268
+ "", # output - leave this blank for generation!
269
+ )
270
+ ], return_tensors = "pt").to("cuda")
271
+
272
+ from transformers import TextStreamer
273
+ text_streamer = TextStreamer(tokenizer)
274
+ _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128)
275
+
276
+ outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
277
+ tokenizer.batch_decode(outputs)
278
+
279
+ model.save_pretrained("Llama-3.2-3B-Instruct-lyrics-lora") # Local saving
280
+ tokenizer.save_pretrained("Llama-3.2-3B-Instruct-lyrics-lora")
281
+ model.save_pretrained_merged("Llama-3.2-3B-Instruct-lyrics", tokenizer)
282
+ '''
283
+
284
+ ## Questions
285
+ - This model is solely for learning and testing purposes, and errors in output are inevitable. We do not take responsibility for the output results. If the output content is to be used, it must be modified; if not modified, we will assume it has been altered.
286
+ - For commercial licensing, please refer to the Llama 3.2 agreement.
287
+
288
+ # Llama-3.2-3B-Instruct-unsloth-bnb-4bit Information
289
+ <div>
290
+ <p style="margin-bottom: 0;">
291
+ <strong>See <a href="https://huggingface.co/collections/unsloth/llama-32-66f46afde4ca573864321a22">our collection</a> for versions of Llama 3.2 including GGUF & 4-bit formats.</strong>
292
+ </p>
293
+ <p style="margin-bottom: 0;">
294
+ <em>Unsloth's <a href="https://unsloth.ai/blog/dynamic-4bit">Dynamic 4-bit Quants</a> is selectively quantized, greatly improving accuracy over standard 4-bit.</em>
295
+ </p>
296
+ <div style="display: flex; gap: 5px; align-items: center; ">
297
+ <a href="https://github.com/unslothai/unsloth/">
298
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133">
299
+ </a>
300
+ <a href="https://discord.gg/unsloth">
301
+ <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173">
302
+ </a>
303
+ <a href="https://docs.unsloth.ai/">
304
+ <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143">
305
+ </a>
306
+ </div>
307
+ <h1 style="margin-top: 0rem;">Fine-tune LLMs 2-5x faster with 70% less memory via Unsloth!</h2>
308
+ </div>
309
+ We have a free Google Colab Tesla T4 notebook for Llama 3.2 (3B) here: https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.1_(8B)-Alpaca.ipynb
310
+ # unsloth/Llama-3.2-3B-unsloth-bnb-4bit
311
+ For more details on the model, please go to Meta's original [model card](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct)
312
+ ## ✨ Finetune for Free
313
+ All notebooks are **beginner friendly**! Add your dataset, click "Run All", and you'll get a 2x faster finetuned model which can be exported to GGUF, vLLM or uploaded to Hugging Face.
314
+ | Unsloth supports | Free Notebooks | Performance | Memory use |
315
+ |-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|
316
+ | **Llama-3.2 (3B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(1B_and_3B)-Conversational.ipynb) | 2.4x faster | 58% less |
317
+ | **Llama-3.2 (11B vision)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(11B)-Vision.ipynb) | 2x faster | 60% less |
318
+ | **Qwen2 VL (7B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2_VL_(7B)-Vision.ipynb) | 1.8x faster | 60% less |
319
+ | **Qwen2.5 (7B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2.5_(7B)-Alpaca.ipynb) | 2x faster | 60% less |
320
+ | **Llama-3.1 (8B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.1_(8B)-Alpaca.ipynb) | 2.4x faster | 58% less |
321
+ | **Phi-3.5 (mini)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Phi_3.5_Mini-Conversational.ipynb) | 2x faster | 50% less |
322
+ | **Gemma 2 (9B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma2_(9B)-Alpaca.ipynb) | 2.4x faster | 58% less |
323
+ | **Mistral (7B)** | [▶️ Start on Colab](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_(7B)-Conversational.ipynb) | 2.2x faster | 62% less |
324
+ [<img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="200"/>](https://docs.unsloth.ai)
325
+ - This [Llama 3.2 conversational notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_(1B_and_3B)-Conversational.ipynb) is useful for ShareGPT ChatML / Vicuna templates.
326
+ - This [text completion notebook](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_(7B)-Text_Completion.ipynb) is for raw text. This [DPO notebook](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) replicates Zephyr.
327
+ - \* Kaggle has 2x T4s, but we use 1. Due to overhead, 1x T4 is 5x faster.
328
+
329
+ ## Special Thanks
330
+ A huge thank you to the Meta and Llama team for creating and releasing these models.
331
+
332
+ ## Model Information
333
+
334
+ The Meta Llama 3.2 collection of multilingual large language models (LLMs) is a collection of pretrained and instruction-tuned generative models in 1B and 3B sizes (text in/text out). The Llama 3.2 instruction-tuned text only models are optimized for multilingual dialogue use cases, including agentic retrieval and summarization tasks. They outperform many of the available open source and closed chat models on common industry benchmarks.
335
+
336
+ **Model developer**: Meta
337
+
338
+ **Model Architecture:** Llama 3.2 is an auto-regressive language model that uses an optimized transformer architecture. The tuned versions use supervised fine-tuning (SFT) and reinforcement learning with human feedback (RLHF) to align with human preferences for helpfulness and safety.
339
+
340
+ **Supported languages:** English, German, French, Italian, Portuguese, Hindi, Spanish, and Thai are officially supported. Llama 3.2 has been trained on a broader collection of languages than these 8 supported languages. Developers may fine-tune Llama 3.2 models for languages beyond these supported languages, provided they comply with the Llama 3.2 Community License and the Acceptable Use Policy. Developers are always expected to ensure that their deployments, including those that involve additional languages, are completed safely and responsibly.
341
+
342
+ **Llama 3.2 family of models** Token counts refer to pretraining data only. All model versions use Grouped-Query Attention (GQA) for improved inference scalability.
343
+
344
+ **Model Release Date:** Sept 25, 2024
345
+
346
+ **Status:** This is a static model trained on an offline dataset. Future versions may be released that improve model capabilities and safety.
347
+
348
+ **License:** Use of Llama 3.2 is governed by the [Llama 3.2 Community License](https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/LICENSE) (a custom, commercial license agreement).
349
+
350
+ Where to send questions or comments about the model Instructions on how to provide feedback or comments on the model can be found in the model [README](https://github.com/meta-llama/llama3). For more technical information about generation parameters and recipes for how to use Llama 3.1 in applications, please go [here](https://github.com/meta-llama/llama-recipes).