Sahibsingh12 commited on
Commit
63220d9
·
verified ·
1 Parent(s): 1678bcb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +222 -188
README.md CHANGED
@@ -1,202 +1,236 @@
1
  ---
2
  base_model: google/gemma-3-1b-it
3
- library_name: peft
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
200
- ### Framework versions
201
-
202
- - PEFT 0.14.0
 
 
 
 
 
 
1
  ---
2
  base_model: google/gemma-3-1b-it
3
+ library_name: transformers
4
+ model_name: Sahibsingh12/gemma3-1b-thinking
5
+ tags:
6
+ - generated_from_trainer
7
+ - trl
8
+ - grpo
9
+ - peft
10
+ - adapter
11
+ licence: license
12
+ datasets:
13
+ - openai/gsm8k
14
  ---
15
 
16
+ ## Model Information
17
 
18
+ This project uses `Sahibsingh12/gemma3-1b-thinking`, which is a PEFT (Parameter-Efficient Fine-Tuning) adapter for `google/gemma-3-1b-it`. Unlike a full model, this is a lightweight adapter that works alongside the base model, making it easier to distribute and use with limited resources.
19
 
20
+ The model was trained using [TRL](https://github.com/huggingface/trl) with GRPO, a method introduced in [DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models](https://huggingface.co/papers/2402.03300).
21
 
22
+ ### Training Approach
23
 
24
+ This adapter was fine-tuned with Reinforcement Learning to enhance reasoning capabilities:
25
 
26
+ - Used reasoning chains from [OpenAI's GSM8K dataset](https://huggingface.co/datasets/openai/gsm8k)
27
+ - Implemented GRPO reward functions
28
+ - Based on [Will Brown's approach](https://gist.github.com/willccbb/4676755236bb08cab5f4e54a0475d6fb)
29
+ - Training implementation from [Ben Burtenshaw's Colab](https://x.com/ben_burtenshaw/status/1900202583056068663)
30
 
31
+ The adapter is available on HuggingFace: [vinhnx90/gemma3-1b-thinking](https://huggingface.co/vinhnx90/gemma3-1b-thinking)
32
 
33
+ ### Training Details
34
 
35
+ - **Base Model**: google/gemma-3-1b-it
36
+ - **Library**: transformers
37
+ - **Training Method**: GRPO (from DeepSeekMath paper)
38
+ - **PEFT Method**: LoRA (Low-Rank Adaptation)
39
+ - **Framework Versions**:
40
+ - TRL: 0.16.0.dev0
41
+ - Transformers: 4.50.0.dev0
42
+ - PEFT: 0.9.0
43
+ - Pytorch: 2.5.1+cu124
44
+ - Datasets: 3.3.2
45
+ - Tokenizers: 0.21.0
46
+
47
+ ## Requirements
48
+
49
+ ```
50
+ torch
51
+ transformers
52
+ peft
53
+ ```
54
 
55
+ ## Installation
 
 
 
 
 
 
56
 
57
+ 1. Clone this repository or download the script
58
+ 2. Install the required packages:
59
+
60
+ ```bash
61
+ pip install torch transformers peft
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### Running with PEFT Adapter
67
+
68
+ Since this is a PEFT adapter, you need to load both the base model and the adapter:
69
+
70
+ ```python
71
+ from transformers import AutoModelForCausalLM, AutoTokenizer
72
+ from peft import PeftModel, PeftConfig
73
+
74
+ # Load the base model and tokenizer
75
+ base_model_id = "google/gemma-3-1b-it"
76
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id)
77
+ model = AutoModelForCausalLM.from_pretrained(
78
+ base_model_id,
79
+ device_map="auto", # Automatically determine the device
80
+ torch_dtype="auto" # Use the appropriate precision
81
+ )
82
+
83
+ # Load the PEFT adapter
84
+ adapter_model_id = "Sahibsingh12/gemma3-1b-thinking"
85
+ model = PeftModel.from_pretrained(model, adapter_model_id)
86
+
87
+ # Generate text
88
+ prompt = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
89
+ inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
90
+ outputs = model.generate(
91
+ inputs,
92
+ max_new_tokens=128,
93
+ do_sample=True,
94
+ temperature=0.7,
95
+ top_p=0.9,
96
+ )
97
+
98
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
99
+ print(response)
100
+ ```
101
+
102
+ ### Chat Format Example
103
+
104
+ For chat-formatted inputs:
105
+
106
+ ```python
107
+ from transformers import AutoModelForCausalLM, AutoTokenizer
108
+ from peft import PeftModel
109
+
110
+ # Load the base model and tokenizer
111
+ base_model_id = "google/gemma-3-1b-it"
112
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id)
113
+ model = AutoModelForCausalLM.from_pretrained(
114
+ base_model_id,
115
+ device_map="auto",
116
+ torch_dtype="auto"
117
+ )
118
+
119
+ # Load the PEFT adapter
120
+ adapter_model_id = "Sahibsingh12/gemma3-1b-thinking"
121
+ model = PeftModel.from_pretrained(model, adapter_model_id)
122
+
123
+ # Prepare chat messages
124
+ messages = [
125
+ {"role": "user", "content": "Calculate the area of a circle with radius 5cm"}
126
+ ]
127
+
128
+ # Format messages for the model
129
+ prompt = tokenizer.apply_chat_template(
130
+ messages,
131
+ tokenize=False,
132
+ add_generation_prompt=True
133
+ )
134
+
135
+ # Generate response
136
+ inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
137
+ outputs = model.generate(
138
+ inputs,
139
+ max_new_tokens=256,
140
+ do_sample=True,
141
+ temperature=0.7,
142
+ )
143
+
144
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
145
+ print(response)
146
+ ```
147
+
148
+ ### Using the Pipeline API
149
+
150
+ For a simpler approach (note: this may download the full adapter model):
151
+
152
+ ```python
153
+ from transformers import pipeline
154
+
155
+ # Initialize the pipeline with the adapter model
156
+ generator = pipeline(
157
+ "text-generation",
158
+ model="Sahibsingh12/gemma3-1b-thinking",
159
+ model_kwargs={"device_map": "auto", "torch_dtype": "auto"}
160
+ )
161
+
162
+ # Generate text
163
+ question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
164
+ output = generator(
165
+ [{"role": "user", "content": question}],
166
+ max_new_tokens=128,
167
+ do_sample=True,
168
+ temperature=0.7,
169
+ return_full_text=False
170
+ )[0]
171
+
172
+ print(output["generated_text"])
173
+ ```
174
+
175
+ ## Available Command-Line Arguments
176
+
177
+ If you use the command-line script, the following arguments are available:
178
+
179
+ | Argument | Description | Default |
180
+ |----------|-------------|---------|
181
+ | `--prompt` | Input text for generation | "If you had a time machine..." |
182
+ | `--base-model` | Hugging Face base model name | "google/gemma-3-1b-it" |
183
+ | `--adapter` | Hugging Face adapter model name | "vinhnx90/gemma3-1b-thinking" |
184
+ | `--device` | Computing device (cpu, cuda, mps, or auto) | "auto" |
185
+ | `--max-tokens` | Maximum number of new tokens to generate | 128 |
186
+ | `--temperature` | Sampling temperature | 0.7 |
187
+ | `--top-p` | Top-p sampling parameter | 0.9 |
188
+
189
+ ## Citations
190
+
191
+ ### Implementation References
192
+
193
+ - **Will Brown's Approach**: [GitHub Gist](https://gist.github.com/willccbb/4676755236bb08cab5f4e54a0475d6fb)
194
+ - **Ben Burtenshaw's Implementation**: [Twitter/X Post](https://x.com/ben_burtenshaw/status/1900202583056068663)
195
+
196
+ ### GRPO
197
+ ```bibtex
198
+ @article{zhihong2024deepseekmath,
199
+ title = {{DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}},
200
+ author = {Zhihong Shao and Peiyi Wang and Qihao Zhu and Runxin Xu and Junxiao Song and Mingchuan Zhang and Y. K. Li and Y. Wu and Daya Guo},
201
+ year = 2024,
202
+ eprint = {arXiv:2402.03300},
203
+ }
204
+ ```
205
+
206
+ ### TRL
207
+ ```bibtex
208
+ @misc{vonwerra2022trl,
209
+ title = {{TRL: Transformer Reinforcement Learning}},
210
+ author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
211
+ year = 2020,
212
+ journal = {GitHub repository},
213
+ publisher = {GitHub},
214
+ howpublished = {\url{https://github.com/huggingface/trl}}
215
+ }
216
+ ```
217
+
218
+ ### PEFT
219
+ ```bibtex
220
+ @misc{peft,
221
+ title = {{PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware}},
222
+ author = {Younes Belkada and Thomas Wang and Yasmine Manar and Ajay Brahmakshatriya and Huu Nguyen and Yongwei Zhou and Soumya Batra and Neil Band and Romi Ponciano and Suraj Patil and Colin Raffel and Siddhartha Kamalakara and Enrico Shippole and Vesselin Popov and Lewis Tunstall and Brian Mugo and Patrick von Platen and Clémentine Fourrier and Surya Dantuluri and Luke Vilnis and Adam P. Saxton},
223
+ year = 2023,
224
+ journal = {GitHub repository},
225
+ publisher = {GitHub},
226
+ howpublished = {\url{https://github.com/huggingface/peft}}
227
+ }
228
+ ```
229
+
230
+ ## License
231
+
232
+ This project is licensed under the same license as the base model.
233
+
234
+ ## Contributing
235
+
236
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.