File size: 6,136 Bytes
09fa62a
 
 
 
6dcd428
9dded33
09fa62a
 
 
 
 
9dded33
 
09fa62a
 
 
8357034
09fa62a
 
 
 
 
 
 
 
 
 
d248fe1
09fa62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0f6805
e2fbb96
09fa62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e2fbb96
09fa62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0f6805
ba7bbbc
09fa62a
ba7bbbc
09fa62a
 
 
7ec0e4f
09fa62a
 
 
e2fbb96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210




---
datasets:
- DIBT/10k_prompts_ranked
- NickyNicky/10k_prompts_ranked_all_chatml_json_gemma
- NickyNicky/10k_prompts_ranked_all
model:
- NickyNicky/gemma-2b-it_oasst2_chatML_Cluster_2_V1
language:
- en

library_name: transformers

widget:
- text: |
    <bos><start_of_turn>system
    You are a prompt evaluator response format json.
    ngrams_length: "8" | cluster_length: "15".
    lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
    <start_of_turn>user
    ### |detect_prompt|:
    What were the main contributions of Eratosthenes to the development of mathematics in ancient Greece?<end_of_turn>
    <start_of_turn>model\n
license: apache-2.0  
---


![image/png](https://cdn-uploads.huggingface.co/production/uploads/641b435ba5f876fe30c5ae0a/WlTKZRULBsCGcZ8L71ViI.png)


```
reference data model:

  datasets:
      link: https://huggingface.co/datasets/NickyNicky/oasst2_clusters

  model:
    - google/gemma-2b-it
      Link:
        https://huggingface.co/google/gemma-2b-it

    base fine tune: NickyNicky/gemma-2b-it_oasst2_chatML_Cluster_2_V1

  Epoch: 2

  future experts: test

  Eval model:
    - link:
        soon

```


## train/loss 0.5407

![image/png](https://cdn-uploads.huggingface.co/production/uploads/641b435ba5f876fe30c5ae0a/n3HVaz58rb-nOR0Bc64LO.png)


## 


```Python
!python -m pip install --upgrade pip
!pip install "torch>=2.1.1" -U
!pip install torchaudio==2.2.0
!pip install -q datasets trl peft bitsandbytes sentencepiece wandb
!pip install -q accelerate safetensors deepspeed
!pip install -q scipy ninja -U
!pip install -q -U transformers==4.38.0
!pip install flash-attn==2.5.5 --no-build-isolation
```


## Version
```py
import torch
torch.__version__
#OUTPUTS: ('2.2.0+cu121' )
```

## How to use
```py

from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    HfArgumentParser,
    TrainingArguments,
    pipeline,
    logging,
    GenerationConfig,
    TextIteratorStreamer,
)

from transformers import StoppingCriteria, StoppingCriteriaList

import torch

# model_id='NickyNicky/gemma-2b-it_oasst2_chatML_Cluster2_aya_multilingual'
model_id= "NickyNicky/gemma-2b-it_oasst2_chatML_Cluster2_aya_multilingual_10k_prompts_ranked_all_json_V1"
model = AutoModelForCausalLM.from_pretrained(model_id,
                                             device_map="auto",
                                             trust_remote_code=True,
                                             torch_dtype=torch.bfloat16,
                                             attn_implementation="flash_attention_2",
                                             # load_in_4bit=True,
                                             # low_cpu_mem_usage= True,

                                             )

max_length=2100
print("max_length",max_length)


tokenizer = AutoTokenizer.from_pretrained(model_id,
                                          # use_fast = False,
                                          max_length=max_length,)


class ListOfTokensStoppingCriteria(StoppingCriteria):
    """
    Clase para definir un criterio de parada basado en una lista de tokens específicos.
    """
    def __init__(self, tokenizer, stop_tokens):
        self.tokenizer = tokenizer
        # Codifica cada token de parada y guarda sus IDs en una lista
        self.stop_token_ids_list = [tokenizer.encode(stop_token, add_special_tokens=False) for stop_token in stop_tokens]

    def __call__(self, input_ids, scores, **kwargs):
        # Verifica si los últimos tokens generados coinciden con alguno de los conjuntos de tokens de parada
        for stop_token_ids in self.stop_token_ids_list:
            len_stop_tokens = len(stop_token_ids)
            if len(input_ids[0]) >= len_stop_tokens:
                if input_ids[0, -len_stop_tokens:].tolist() == stop_token_ids:
                    return True
        return False

# Uso del criterio de parada personalizado
stop_tokens = ["<end_of_turn>"]  # Lista de tokens de parada

# Inicializa tu criterio de parada con el tokenizer y la lista de tokens de parada
stopping_criteria = ListOfTokensStoppingCriteria(tokenizer, stop_tokens)

# Añade tu criterio de parada a una StoppingCriteriaList
stopping_criteria_list = StoppingCriteriaList([stopping_criteria])


prompt="""What were the main contributions of Eratosthenes to the development of mathematics in ancient Greece?"""

#EXAMPLE #1
input_text = f'''<bos><start_of_turn>system
You are a prompt evaluator response format json.
ngrams_length: "8" | cluster_length: "15".
lista de codigos linguisticos disponibles: ["en", "en"].<end_of_turn>
<start_of_turn>user
### |detect_prompt|:
{prompt}<end_of_turn>
<start_of_turn>model
'''

### OUTPUT EXAMPLE
'''
{
    "ngrams_length": "8",
    "ngrams": ["main", "contribution", "eratosthenes", "development", "mathematic", "ancient", "greece", "ancient greece"],
    "cluster_length": "15",
    "cluster": ["quantum", "magnetic", "star", "metal", "planet", "gravity", "force", "universe", "distance", "compound", "gravitational", "quantum computing", "solar", "sun", "earth"],
    "cluster_desc": ["Astrophysics", "Quantum Computing"],
    "avg_rating": "5.0",
    "kind": "synthetic"
    
}<end_of_turn><eos>
'''



inputs = tokenizer.encode(input_text,
                          return_tensors="pt",
                          add_special_tokens=False).to("cuda:0")
max_new_tokens=700
generation_config = GenerationConfig(
              max_new_tokens=max_new_tokens,
              temperature=0.32,
              #top_p=0.9,
              top_k=45,
              repetition_penalty=1.,  #1.1
              do_sample=True,
          )
outputs = model.generate(generation_config=generation_config,
                         input_ids=inputs,
                         stopping_criteria=stopping_criteria_list,)
tokenizer.decode(outputs[0], skip_special_tokens=False) #True
```


## code

```
https://colab.research.google.com/drive/1z26uLnTZWZ994G_dgyghNzh4hF2eEA6Z?usp=sharing
```

## generated dataset model NickyNicky/prompts_ranked_808.
```
https://huggingface.co/datasets/NickyNicky/prompts_ranked_808
```