README.md
Browse files
README.md
CHANGED
@@ -3,199 +3,202 @@ library_name: transformers
|
|
3 |
tags:
|
4 |
- trl
|
5 |
- sft
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
---
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
11 |
-
|
12 |
|
|
|
13 |
|
14 |
## Model Details
|
15 |
|
16 |
### Model Description
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
21 |
-
|
22 |
-
- **Developed by:** [More Information Needed]
|
23 |
-
- **Funded by [optional]:** [More Information Needed]
|
24 |
-
- **Shared by [optional]:** [More Information Needed]
|
25 |
-
- **Model type:** [More Information Needed]
|
26 |
-
- **Language(s) (NLP):** [More Information Needed]
|
27 |
-
- **License:** [More Information Needed]
|
28 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
|
34 |
-
- **Repository:** [
|
35 |
-
- **
|
36 |
-
- **
|
37 |
|
38 |
## Uses
|
39 |
|
40 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
41 |
-
|
42 |
### Direct Use
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
[More Information Needed]
|
47 |
|
48 |
-
|
|
|
|
|
49 |
|
50 |
-
|
51 |
|
52 |
-
|
|
|
|
|
|
|
53 |
|
54 |
### Out-of-Scope Use
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
63 |
-
|
64 |
-
[More Information Needed]
|
65 |
-
|
66 |
-
### Recommendations
|
67 |
-
|
68 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
69 |
-
|
70 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
71 |
|
72 |
## How to Get Started with the Model
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
## Training Details
|
79 |
|
80 |
### Training Data
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
[More Information Needed]
|
85 |
|
86 |
### Training Procedure
|
87 |
|
88 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
89 |
-
|
90 |
-
#### Preprocessing [optional]
|
91 |
-
|
92 |
-
[More Information Needed]
|
93 |
-
|
94 |
-
|
95 |
#### Training Hyperparameters
|
96 |
|
97 |
-
- **Training regime:**
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
## Evaluation
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
### Testing Data, Factors & Metrics
|
110 |
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
#### Factors
|
118 |
-
|
119 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
120 |
-
|
121 |
-
[More Information Needed]
|
122 |
-
|
123 |
-
#### Metrics
|
124 |
-
|
125 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
126 |
-
|
127 |
-
[More Information Needed]
|
128 |
-
|
129 |
-
### Results
|
130 |
-
|
131 |
-
[More Information Needed]
|
132 |
-
|
133 |
-
#### Summary
|
134 |
|
|
|
135 |
|
|
|
136 |
|
137 |
-
|
|
|
|
|
|
|
138 |
|
139 |
-
|
140 |
|
141 |
-
|
|
|
|
|
|
|
142 |
|
143 |
## Environmental Impact
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
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).
|
148 |
|
149 |
-
- **Hardware Type:**
|
150 |
-
- **Hours used:**
|
151 |
-
- **Cloud Provider:**
|
152 |
-
- **Compute Region:**
|
153 |
-
- **Carbon Emitted:**
|
154 |
|
155 |
-
## Technical Specifications
|
156 |
|
157 |
### Model Architecture and Objective
|
158 |
|
159 |
-
|
|
|
|
|
|
|
160 |
|
161 |
### Compute Infrastructure
|
162 |
|
163 |
-
[More Information Needed]
|
164 |
-
|
165 |
#### Hardware
|
166 |
|
167 |
-
|
|
|
168 |
|
169 |
#### Software
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
176 |
-
|
177 |
-
**BibTeX:**
|
178 |
-
|
179 |
-
[More Information Needed]
|
180 |
-
|
181 |
-
**APA:**
|
182 |
-
|
183 |
-
[More Information Needed]
|
184 |
-
|
185 |
-
## Glossary [optional]
|
186 |
-
|
187 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
188 |
-
|
189 |
-
[More Information Needed]
|
190 |
-
|
191 |
-
## More Information [optional]
|
192 |
-
|
193 |
-
[More Information Needed]
|
194 |
|
195 |
-
## Model Card Authors
|
196 |
|
197 |
-
|
198 |
|
199 |
## Model Card Contact
|
200 |
|
201 |
-
|
|
|
3 |
tags:
|
4 |
- trl
|
5 |
- sft
|
6 |
+
- code
|
7 |
+
- competitive-programming
|
8 |
+
- codeforces
|
9 |
+
- lora
|
10 |
+
license: mit
|
11 |
+
datasets:
|
12 |
+
- open-r1/codeforces-cots
|
13 |
+
base_model:
|
14 |
+
- google/gemma-2-2b-it
|
15 |
+
pipeline_tag: text-generation
|
16 |
---
|
17 |
|
18 |
+
# Gemma-2-2b Fine-tuned for Competitive Programming
|
|
|
|
|
|
|
19 |
|
20 |
+
This model is a fine-tuned version of [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it) on the [open-r1/codeforces-cots](https://huggingface.co/datasets/open-r1/codeforces-cots) dataset for competitive programming problem solving.
|
21 |
|
22 |
## Model Details
|
23 |
|
24 |
### Model Description
|
25 |
|
26 |
+
This model has been fine-tuned using LoRA (Low-Rank Adaptation) on competitive programming problems from Codeforces. It's designed to help generate solutions for algorithmic and data structure problems commonly found in competitive programming contests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
- **Developed by:** Aswith77
|
29 |
+
- **Model type:** Causal Language Model (Code Generation)
|
30 |
+
- **Language(s):** Python, C++, Java (primarily Python)
|
31 |
+
- **License:** MIT
|
32 |
+
- **Finetuned from model:** google/gemma-2-2b-it
|
33 |
+
- **Fine-tuning method:** LoRA (Low-Rank Adaptation)
|
34 |
|
35 |
+
### Model Sources
|
36 |
|
37 |
+
- **Repository:** [Hugging Face Model](https://huggingface.co/Aswith77/gemma-2-2b-it-finetune-codeforces-cots)
|
38 |
+
- **Base Model:** [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it)
|
39 |
+
- **Dataset:** [open-r1/codeforces-cots](https://huggingface.co/datasets/open-r1/codeforces-cots)
|
40 |
|
41 |
## Uses
|
42 |
|
|
|
|
|
43 |
### Direct Use
|
44 |
|
45 |
+
This model is intended for generating solutions to competitive programming problems, particularly those similar to Codeforces problems. It can:
|
|
|
|
|
46 |
|
47 |
+
- Generate algorithmic solutions for given problem statements
|
48 |
+
- Help with code completion for competitive programming
|
49 |
+
- Assist in learning algorithmic problem-solving patterns
|
50 |
|
51 |
+
### Downstream Use
|
52 |
|
53 |
+
The model can be further fine-tuned on:
|
54 |
+
- Specific programming languages
|
55 |
+
- Domain-specific algorithmic problems
|
56 |
+
- Educational coding platforms
|
57 |
|
58 |
### Out-of-Scope Use
|
59 |
|
60 |
+
This model should not be used for:
|
61 |
+
- Production code without thorough testing
|
62 |
+
- Security-critical applications
|
63 |
+
- General-purpose software development without validation
|
64 |
+
- Problems requiring real-world system design
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
## How to Get Started with the Model
|
67 |
|
68 |
+
```python
|
69 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
70 |
+
from peft import PeftModel
|
71 |
+
import torch
|
72 |
+
|
73 |
+
# Load the base model
|
74 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
75 |
+
"google/gemma-2-2b-it",
|
76 |
+
torch_dtype=torch.float16,
|
77 |
+
device_map="auto"
|
78 |
+
)
|
79 |
+
|
80 |
+
# Load the fine-tuned LoRA adapters
|
81 |
+
model = PeftModel.from_pretrained(
|
82 |
+
base_model,
|
83 |
+
"Aswith77/gemma-2-2b-it-finetune-codeforces-cots"
|
84 |
+
)
|
85 |
+
|
86 |
+
# Load tokenizer
|
87 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
|
88 |
+
|
89 |
+
# Generate code for a problem
|
90 |
+
problem = """
|
91 |
+
Given an array of integers, find the maximum sum of a contiguous subarray.
|
92 |
+
Input: [-2,1,-3,4,-1,2,1,-5,4]
|
93 |
+
Output: 6 (subarray [4,-1,2,1])
|
94 |
+
"""
|
95 |
+
|
96 |
+
inputs = tokenizer(problem, return_tensors="pt")
|
97 |
+
outputs = model.generate(
|
98 |
+
**inputs,
|
99 |
+
max_length=512,
|
100 |
+
temperature=0.7,
|
101 |
+
do_sample=True,
|
102 |
+
pad_token_id=tokenizer.eos_token_id
|
103 |
+
)
|
104 |
+
|
105 |
+
solution = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
106 |
+
print(solution)
|
107 |
+
```
|
108 |
|
109 |
## Training Details
|
110 |
|
111 |
### Training Data
|
112 |
|
113 |
+
The model was trained on the [open-r1/codeforces-cots](https://huggingface.co/datasets/open-r1/codeforces-cots) dataset, specifically using 1,000 competitive programming problems and their solutions from Codeforces.
|
|
|
|
|
114 |
|
115 |
### Training Procedure
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
#### Training Hyperparameters
|
118 |
|
119 |
+
- **Training regime:** fp16 mixed precision
|
120 |
+
- **Learning rate:** 2e-4
|
121 |
+
- **Batch size:** 1 (per device)
|
122 |
+
- **Gradient accumulation steps:** 2
|
123 |
+
- **Max steps:** 100
|
124 |
+
- **Warmup steps:** 5
|
125 |
+
- **Optimizer:** AdamW 8-bit
|
126 |
+
- **Weight decay:** 0.01
|
127 |
+
- **LoRA rank (r):** 16
|
128 |
+
- **LoRA alpha:** 32
|
129 |
+
- **LoRA dropout:** 0.1
|
130 |
+
- **Target modules:** q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
|
131 |
+
|
132 |
+
#### Speeds, Sizes, Times
|
133 |
+
|
134 |
+
- **Training time:** ~20 minutes
|
135 |
+
- **Hardware:** Tesla T4 GPU (16GB)
|
136 |
+
- **Model size:** ~30MB (LoRA adapters only)
|
137 |
+
- **Final training loss:** 0.3715
|
138 |
+
- **Training samples per second:** 0.338
|
139 |
|
140 |
## Evaluation
|
141 |
|
142 |
+
The model achieved a training loss of 0.3715, showing good convergence from an initial loss of 0.9303. The loss curve demonstrated steady improvement throughout training without signs of overfitting.
|
|
|
|
|
143 |
|
144 |
+
### Training Loss Progression
|
145 |
|
146 |
+
- Initial loss: 0.9303
|
147 |
+
- Final loss: 0.3715
|
148 |
+
- Loss reduction: ~60%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
+
## Bias, Risks, and Limitations
|
151 |
|
152 |
+
### Limitations
|
153 |
|
154 |
+
- **Dataset bias:** Trained primarily on Codeforces problems, may not generalize well to other competitive programming platforms
|
155 |
+
- **Language bias:** Solutions may favor certain programming patterns common in the training data
|
156 |
+
- **Size limitations:** Being a 2B parameter model, it may struggle with very complex algorithmic problems
|
157 |
+
- **Code correctness:** Generated code should always be tested and validated before use
|
158 |
|
159 |
+
### Recommendations
|
160 |
|
161 |
+
- Always test generated solutions with multiple test cases
|
162 |
+
- Use the model as a starting point, not a final solution
|
163 |
+
- Verify algorithmic correctness and time complexity
|
164 |
+
- Consider the model's suggestions as one approach among many possible solutions
|
165 |
|
166 |
## Environmental Impact
|
167 |
|
168 |
+
Training was conducted on a single Tesla T4 GPU for approximately 20 minutes, resulting in minimal environmental impact compared to larger scale training runs.
|
|
|
|
|
169 |
|
170 |
+
- **Hardware Type:** Tesla T4 GPU
|
171 |
+
- **Hours used:** 0.33 hours
|
172 |
+
- **Cloud Provider:** Kaggle
|
173 |
+
- **Compute Region:** Not specified
|
174 |
+
- **Carbon Emitted:** Minimal (estimated < 0.1 kg CO2eq)
|
175 |
|
176 |
+
## Technical Specifications
|
177 |
|
178 |
### Model Architecture and Objective
|
179 |
|
180 |
+
- **Base Architecture:** Gemma-2 (2B parameters)
|
181 |
+
- **Fine-tuning Method:** LoRA (Low-Rank Adaptation)
|
182 |
+
- **Objective:** Causal language modeling with supervised fine-tuning
|
183 |
+
- **Quantization:** 4-bit quantization during training
|
184 |
|
185 |
### Compute Infrastructure
|
186 |
|
|
|
|
|
187 |
#### Hardware
|
188 |
|
189 |
+
- **GPU:** Tesla T4 (16GB VRAM)
|
190 |
+
- **Platform:** Kaggle Notebooks
|
191 |
|
192 |
#### Software
|
193 |
|
194 |
+
- **Framework:** PyTorch, Transformers, PEFT, TRL
|
195 |
+
- **Quantization:** bitsandbytes 4-bit
|
196 |
+
- **Training:** Supervised Fine-Tuning (SFT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
+
## Model Card Authors
|
199 |
|
200 |
+
Created by Aswith77 during fine-tuning experiments with competitive programming datasets.
|
201 |
|
202 |
## Model Card Contact
|
203 |
|
204 |
+
For questions or issues regarding this model, please open an issue in the model repository.
|