File size: 3,761 Bytes
a8909fa
 
 
 
 
 
 
 
 
 
 
14f9511
a8909fa
abffb26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8909fa
 
 
 
 
 
 
 
 
 
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
---
base_model: unsloth/tinyllama-chat-bnb-4bit
language:
- en
license: apache-2.0
tags:
- text-generation-inference
- transformers
- unsloth
- llama
- trl
- sft
---
``` Python
# Question

if False:
    from unsloth import FastLanguageModel
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = "lora_model", # YOUR MODEL YOU USED FOR TRAINING
        max_seq_length = max_seq_length,
        dtype = dtype,
        load_in_4bit = load_in_4bit,
    )
    FastLanguageModel.for_inference(model) # Enable native 2x faster inference

# alpaca_prompt = You MUST copy from above!

inputs = tokenizer(
[
    alpaca_prompt.format(
        "Eu preciso treinar uma IA gpt2 do hugginface em meu computador", # instruction
        "", # input
        "", # output - leave this blank for generation!
    )
], return_tensors = "pt").to("cuda")

from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 4096)

# Answer

<s> Below is an instruction that describes a task related to Python programming or computer science concepts. Provide a detailed, accurate, and helpful response that addresses the query or solves the problem presented. Follow these guidelines:

1. If the task involves coding, provide a complete, working Python solution with explanations.
2. If it's a conceptual question, explain thoroughly, using examples where appropriate.
3. Break down complex problems or concepts into steps or components.
4. If you're unsure about any part of your response, clearly state your level of confidence and any assumptions you're making.
5. If the query is ambiguous or lacks necessary information, ask for clarification before proceeding.
6. After providing your response, briefly summarize the key points or solution.

Remember, accuracy and helpfulness are crucial. Avoid making unfounded claims or providing incorrect information.

### Input:
Eu preciso treinar uma IA gpt2 do hugginface em meu computador

### Output:
 
# Importações necessárias
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from transformers import TrainingArguments, Trainer
from transformers.data import DataCollatorForLanguageModeling
from transformers.data.processors import DataProcessor

# Configurações
training_args = TrainingArguments(
   output_dir='./resultados',
   evaluation_strategy='epoch',
   learning_rate=2e-5,
   per_device_train_batch_size=8,
   eval_steps=1000,
   num_warmupSteps=500,
   weighted_metric='accuracy',
)

# Carregamento do tokenizador
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')

# Carregamento do modelo
modelo = GPT2LMHeadModel.from_pretrained('gpt2')

# Configurações do tracker
tracker = DataProcessor(
   input_class=DataProcessor,
   batch_size=1,
   max_length=100,
   padding=True,
   truncation=True,
)

# Treinando o modelo
trainer = Trainer(
   args=training_args,
   train_loop=tracker,
   trainable_pipelines=[],
)

# Treinando o modelo
trainer.train()

# Evaluação do modelo
evaluador = DataCollatorForLanguageModeling(
   tokenizer=tokenizer,
   model=modelo,
   padding=True,
   max_length=100,
   batch_size=8,
)

# Evalua o modelo
resultados = trainer.evaluate()

# Imprimir os resultados
for name, loss, acc in resultados:
   print(f'{name}: {loss}, {acc:.2f}%')</s>

```

# Uploaded  model

- **Developed by:** Ramikan-BR
- **License:** apache-2.0
- **Finetuned from model :** unsloth/tinyllama-chat-bnb-4bit

This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.

[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)