Update README.md
Browse files
README.md
CHANGED
@@ -1,210 +1,78 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
---
|
|
|
6 |
datasets:
|
7 |
-
-
|
8 |
-
- NickyNicky/10k_prompts_ranked_all_chatml_json_gemma
|
9 |
-
- NickyNicky/10k_prompts_ranked_all
|
10 |
-
model:
|
11 |
-
- NickyNicky/gemma-2b-it_oasst2_chatML_Cluster_2_V1
|
12 |
language:
|
13 |
- en
|
14 |
-
|
15 |
-
library_name: transformers
|
16 |
-
|
17 |
widget:
|
18 |
-
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
---
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
## train/loss 0.5407
|
59 |
-
|
60 |
-
![image/png](https://cdn-uploads.huggingface.co/production/uploads/641b435ba5f876fe30c5ae0a/n3HVaz58rb-nOR0Bc64LO.png)
|
61 |
-
|
62 |
-
|
63 |
-
##
|
64 |
-
|
65 |
-
|
66 |
-
```Python
|
67 |
-
!python -m pip install --upgrade pip
|
68 |
-
!pip install "torch>=2.1.1" -U
|
69 |
-
!pip install torchaudio==2.2.0
|
70 |
-
!pip install -q datasets trl peft bitsandbytes sentencepiece wandb
|
71 |
-
!pip install -q accelerate safetensors deepspeed
|
72 |
-
!pip install -q scipy ninja -U
|
73 |
-
!pip install -q -U transformers==4.38.0
|
74 |
-
!pip install flash-attn==2.5.5 --no-build-isolation
|
75 |
-
```
|
76 |
-
|
77 |
-
|
78 |
-
## Version
|
79 |
-
```py
|
80 |
-
import torch
|
81 |
-
torch.__version__
|
82 |
-
#OUTPUTS: ('2.2.0+cu121' )
|
83 |
-
```
|
84 |
-
|
85 |
-
## How to use
|
86 |
-
```py
|
87 |
-
|
88 |
-
from transformers import (
|
89 |
-
AutoModelForCausalLM,
|
90 |
-
AutoTokenizer,
|
91 |
-
BitsAndBytesConfig,
|
92 |
-
HfArgumentParser,
|
93 |
-
TrainingArguments,
|
94 |
-
pipeline,
|
95 |
-
logging,
|
96 |
-
GenerationConfig,
|
97 |
-
TextIteratorStreamer,
|
98 |
-
)
|
99 |
-
|
100 |
-
from transformers import StoppingCriteria, StoppingCriteriaList
|
101 |
-
|
102 |
import torch
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
model = AutoModelForCausalLM.from_pretrained(model_id,
|
107 |
-
device_map="auto",
|
108 |
-
trust_remote_code=True,
|
109 |
-
torch_dtype=torch.bfloat16,
|
110 |
-
attn_implementation="flash_attention_2",
|
111 |
-
# load_in_4bit=True,
|
112 |
-
# low_cpu_mem_usage= True,
|
113 |
-
|
114 |
-
)
|
115 |
-
|
116 |
-
max_length=2100
|
117 |
-
print("max_length",max_length)
|
118 |
-
|
119 |
-
|
120 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id,
|
121 |
-
# use_fast = False,
|
122 |
-
max_length=max_length,)
|
123 |
-
|
124 |
-
|
125 |
-
class ListOfTokensStoppingCriteria(StoppingCriteria):
|
126 |
-
"""
|
127 |
-
Clase para definir un criterio de parada basado en una lista de tokens específicos.
|
128 |
-
"""
|
129 |
-
def __init__(self, tokenizer, stop_tokens):
|
130 |
-
self.tokenizer = tokenizer
|
131 |
-
# Codifica cada token de parada y guarda sus IDs en una lista
|
132 |
-
self.stop_token_ids_list = [tokenizer.encode(stop_token, add_special_tokens=False) for stop_token in stop_tokens]
|
133 |
-
|
134 |
-
def __call__(self, input_ids, scores, **kwargs):
|
135 |
-
# Verifica si los últimos tokens generados coinciden con alguno de los conjuntos de tokens de parada
|
136 |
-
for stop_token_ids in self.stop_token_ids_list:
|
137 |
-
len_stop_tokens = len(stop_token_ids)
|
138 |
-
if len(input_ids[0]) >= len_stop_tokens:
|
139 |
-
if input_ids[0, -len_stop_tokens:].tolist() == stop_token_ids:
|
140 |
-
return True
|
141 |
-
return False
|
142 |
-
|
143 |
-
# Uso del criterio de parada personalizado
|
144 |
-
stop_tokens = ["<end_of_turn>"] # Lista de tokens de parada
|
145 |
-
|
146 |
-
# Inicializa tu criterio de parada con el tokenizer y la lista de tokens de parada
|
147 |
-
stopping_criteria = ListOfTokensStoppingCriteria(tokenizer, stop_tokens)
|
148 |
-
|
149 |
-
# Añade tu criterio de parada a una StoppingCriteriaList
|
150 |
-
stopping_criteria_list = StoppingCriteriaList([stopping_criteria])
|
151 |
-
|
152 |
-
|
153 |
-
prompt="""What were the main contributions of Eratosthenes to the development of mathematics in ancient Greece?"""
|
154 |
-
|
155 |
-
#EXAMPLE #1
|
156 |
-
input_text = f'''<bos><start_of_turn>system
|
157 |
-
You are a prompt evaluator response format json.
|
158 |
-
ngrams_length: "8" | cluster_length: "15".
|
159 |
-
lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
|
160 |
-
<start_of_turn>user
|
161 |
-
### |detect_prompt|:
|
162 |
-
{prompt}<end_of_turn>
|
163 |
-
<start_of_turn>model
|
164 |
-
'''
|
165 |
-
|
166 |
-
### OUTPUT EXAMPLE
|
167 |
-
'''
|
168 |
-
{
|
169 |
-
"ngrams_length": "8",
|
170 |
-
"ngrams": ["main", "contribution", "eratosthenes", "development", "mathematic", "ancient", "greece", "ancient greece"],
|
171 |
-
"cluster_length": "15",
|
172 |
-
"cluster": ["quantum", "magnetic", "star", "metal", "planet", "gravity", "force", "universe", "distance", "compound", "gravitational", "quantum computing", "solar", "sun", "earth"],
|
173 |
-
"cluster_desc": ["Astrophysics", "Quantum Computing"],
|
174 |
-
"avg_rating": "5.0",
|
175 |
-
"kind": "synthetic"
|
176 |
-
|
177 |
-
}<end_of_turn><eos>
|
178 |
-
'''
|
179 |
-
|
180 |
-
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
#top_p=0.9,
|
190 |
-
top_k=45,
|
191 |
-
repetition_penalty=1., #1.1
|
192 |
-
do_sample=True,
|
193 |
-
)
|
194 |
-
outputs = model.generate(generation_config=generation_config,
|
195 |
-
input_ids=inputs,
|
196 |
-
stopping_criteria=stopping_criteria_list,)
|
197 |
-
tokenizer.decode(outputs[0], skip_special_tokens=False) #True
|
198 |
-
```
|
199 |
|
|
|
|
|
|
|
200 |
|
201 |
-
## code
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
```
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: mit
|
3 |
datasets:
|
4 |
+
- Vezora/Tested-143k-Python-Alpaca
|
|
|
|
|
|
|
|
|
5 |
language:
|
6 |
- en
|
|
|
|
|
|
|
7 |
widget:
|
8 |
+
- example_title: Python!
|
9 |
+
text: >-
|
10 |
+
<start_of_turn>user based on given instruction create a solution\n\nhere are
|
11 |
+
the instruction write a python class to create linked list
|
12 |
+
<end_of_turn>\n<start_of_turn>model
|
13 |
+
tags:
|
14 |
+
- code
|
15 |
+
inference:
|
16 |
+
parameters:
|
17 |
+
max_new_tokens: 250
|
18 |
+
do_sample: false
|
19 |
+
pipeline_tag: question-answering
|
20 |
---
|
21 |
+
# Gemma-2B Fine-Tuned Python Model
|
22 |
+
|
23 |
+
## Overview
|
24 |
+
Gemma-2B Fine-Tuned Python Model is a deep learning model based on the Gemma-2B architecture, fine-tuned specifically for Python programming tasks. This model is designed to understand Python code and assist developers by providing suggestions, completing code snippets, or offering corrections to improve code quality and efficiency.
|
25 |
+
|
26 |
+
## Model Details
|
27 |
+
- **Model Name**: Gemma-2B Fine-Tuned Python Model
|
28 |
+
- **Model Type**: Deep Learning Model
|
29 |
+
- **Base Model**: Gemma-2B
|
30 |
+
- **Language**: Python
|
31 |
+
- **Task**: Python Code Understanding and Assistance
|
32 |
+
|
33 |
+
## Example Use Cases
|
34 |
+
- Code completion: Automatically completing code snippets based on partial inputs.
|
35 |
+
- Syntax correction: Identifying and suggesting corrections for syntax errors in Python code.
|
36 |
+
- Code quality improvement: Providing suggestions to enhance code readability, efficiency, and maintainability.
|
37 |
+
- Debugging assistance: Offering insights and suggestions to debug Python code by identifying potential errors or inefficiencies.
|
38 |
+
|
39 |
+
## How to Use
|
40 |
+
1. **Install Gemma Python Package**:
|
41 |
+
```bash
|
42 |
+
pip install -q -U transformers==4.38.0
|
43 |
+
pip install torch
|
44 |
+
```
|
45 |
+
|
46 |
+
## Inference
|
47 |
+
1. **How to use the model in our notebook**:
|
48 |
+
```python
|
49 |
+
# Load model directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
import torch
|
51 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
52 |
|
53 |
+
tokenizer = AutoTokenizer.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")
|
54 |
+
model = AutoModelForCausalLM.from_pretrained("suriya7/Gemma-2B-Finetuned-Python-Model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
query = input('enter a query:')
|
57 |
+
prompt_template = f"""
|
58 |
+
<start_of_turn>user based on given instruction create a solution\n\nhere are the instruction {query}
|
59 |
+
<end_of_turn>\n<start_of_turn>model
|
60 |
+
"""
|
61 |
+
prompt = prompt_template
|
62 |
+
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).input_ids
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
65 |
+
model.to(device)
|
66 |
+
inputs = encodeds.to(device)
|
67 |
|
|
|
68 |
|
69 |
+
# Increase max_new_tokens if needed
|
70 |
+
generated_ids = model.generate(inputs, max_new_tokens=1000, do_sample=False, pad_token_id=tokenizer.eos_token_id)
|
71 |
+
ans = ''
|
72 |
+
for i in tokenizer.decode(generated_ids[0], skip_special_tokens=True).split('<end_of_turn>')[:2]:
|
73 |
+
ans += i
|
74 |
|
75 |
+
# Extract only the model's answer
|
76 |
+
model_answer = ans.split("model")[1].strip()
|
77 |
+
print(model_answer)
|
78 |
```
|