AdamLucek commited on
Commit
9d129c9
·
verified ·
1 Parent(s): 9f3d235

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +94 -24
README.md CHANGED
@@ -14,49 +14,119 @@ model-index:
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
  should probably proofread and complete it, then remove this comment. -->
16
 
17
- [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="32"/>](https://wandb.ai/adam-lucek/huggingface/runs/vhp5k2tx)
18
- # gemma-2-9b-it-lora-yt-titles
19
 
20
- This model is a fine-tuned version of [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) on an unknown dataset.
21
- It achieves the following results on the evaluation set:
22
- - Loss: 2.2142
23
 
24
- ## Model description
25
-
26
- More information needed
27
 
28
  ## Intended uses & limitations
29
 
30
- More information needed
31
-
32
- ## Training and evaluation data
33
-
34
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  ## Training procedure
37
 
38
  ### Training hyperparameters
39
 
40
- The following hyperparameters were used during training:
41
- - learning_rate: 5e-05
42
- - train_batch_size: 4
43
- - eval_batch_size: 4
44
- - seed: 42
45
- - gradient_accumulation_steps: 4
46
- - total_train_batch_size: 16
47
- - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
48
- - lr_scheduler_type: cosine
49
- - lr_scheduler_warmup_ratio: 0.1
50
- - num_epochs: 3.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  ### Training results
53
 
 
 
54
  | Training Loss | Epoch | Step | Validation Loss |
55
  |:-------------:|:------:|:----:|:---------------:|
56
  | 2.2556 | 0.7619 | 200 | 2.0945 |
57
  | 2.1866 | 1.5238 | 400 | 2.0988 |
58
  | 2.3421 | 2.2857 | 600 | 2.2142 |
59
 
 
 
60
 
61
  ### Framework versions
62
 
 
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
  should probably proofread and complete it, then remove this comment. -->
16
 
17
+ # LoRA Adapters for Gemma-2-9B-IT on YouTube Titles
 
18
 
19
+ These are LoRA adapters for [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) trained on [AdamLucek/youtube-titles](https://huggingface.co/datasets/AdamLucek/youtube-titles).
 
 
20
 
21
+ Intended task is to tune Gemma 2 9B to generate YouTube title's more similar to popular YouTubers, data was prepped in the instruction tuned token format.
 
 
22
 
23
  ## Intended uses & limitations
24
 
25
+ See original model page [google/gemma-2-9b-it intented usage]https://huggingface.co/google/gemma-2-9b-it#intended-usage) for details about Gemma 2 9B usage, limitations, and ethical considerations.
26
+
27
+ ## Usage
28
+
29
+ The below code will show you how to load and interface with the LoRA model.
30
+
31
+ **Loading the Model & LoRA Adapters**
32
+ ```python
33
+ from peft import PeftConfig, PeftModel
34
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
35
+ import torch
36
+
37
+ # Load the Pre Trained Model
38
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2-9b-it",
39
+ quantization_config=BitsAndBytesConfig(load_in_8bit=True),
40
+ device_map="auto"
41
+ ).eval()
42
+ # Load the Tokenizer
43
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
44
+
45
+ # Attach LoRA Adapters to Pre Trained Model
46
+ model = PeftModel.from_pretrained(model, "AdamLucek/gemma-2-9b-it-lora-yt-titles", adapter_name="youtube_titles")
47
+ ```
48
+ **Inference**
49
+
50
+ ```python
51
+ topic = "huggingface AI models"
52
+ messages = [
53
+ {"role": "user", "content": f"Create a YouTube title about {topic}"}
54
+ ]
55
+
56
+ # Apply chat template and prepare inputs
57
+ text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
58
+ inputs = tokenizer(text, return_tensors="pt")
59
+ inputs = {k: v.to("cuda") for k, v in inputs.items()}
60
+
61
+ # Generate outputs
62
+ outputs = model.generate(
63
+ **inputs,
64
+ max_new_tokens=256,
65
+ do_sample=True,
66
+ top_p=0.95,
67
+ temperature=0.1,
68
+ repetition_penalty=1.2,
69
+ eos_token_id=tokenizer.eos_token_id
70
+ )
71
+
72
+ # Decode outputs
73
+ decoded = tokenizer.decode(outputs[0])
74
+
75
+ print(decoded)
76
+ ```
77
 
78
  ## Training procedure
79
 
80
  ### Training hyperparameters
81
 
82
+ Trained on a single a6000 using the following script
83
+
84
+ ```
85
+ python \
86
+ examples/scripts/sft.py \
87
+ --model_name_or_path="google/gemma-2-9b-it" \
88
+ --dataset_name="AdamLucek/youtube-titles" \
89
+ --dataset_text_field="gemma2_9b_it_format" \
90
+ --per_device_train_batch_size=4 \
91
+ --per_device_eval_batch_size=4 \
92
+ --gradient_accumulation_steps=4 \
93
+ --max_grad_norm=1.0 \
94
+ --learning_rate=5e-5 \
95
+ --weight_decay=0.01 \
96
+ --lr_scheduler_type="cosine" \
97
+ --warmup_ratio=0.1 \
98
+ --report_to="wandb" \
99
+ --bf16 \
100
+ --max_seq_length=2048 \
101
+ --lora_r=16 \
102
+ --lora_alpha=32 \
103
+ --lora_target_modules q_proj k_proj v_proj o_proj \
104
+ --load_in_8bit \
105
+ --use_peft \
106
+ --attn_implementation="eager" \
107
+ --logging_steps=1 \
108
+ --eval_strategy="steps" \
109
+ --eval_steps=200 \
110
+ --save_strategy="steps" \
111
+ --save_steps=250 \
112
+ --output_dir="models/gemma2" \
113
+ --hub_model_id="gemma-2-9b-it-lora-yt-titles" \
114
+ --push_to_hub \
115
+ --num_train_epochs=3
116
+ ```
117
 
118
  ### Training results
119
 
120
+ [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="32"/>](https://wandb.ai/adam-lucek/huggingface/runs/vhp5k2tx)
121
+
122
  | Training Loss | Epoch | Step | Validation Loss |
123
  |:-------------:|:------:|:----:|:---------------:|
124
  | 2.2556 | 0.7619 | 200 | 2.0945 |
125
  | 2.1866 | 1.5238 | 400 | 2.0988 |
126
  | 2.3421 | 2.2857 | 600 | 2.2142 |
127
 
128
+ It achieves the following results on the evaluation set:
129
+ - Loss: 2.2142
130
 
131
  ### Framework versions
132