Ramikan-BR commited on
Commit
abffb26
1 Parent(s): 27c09c4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +105 -0
README.md CHANGED
@@ -11,6 +11,111 @@ tags:
11
  - trl
12
  - sft
13
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # Uploaded model
16
 
 
11
  - trl
12
  - sft
13
  ---
14
+ ``` Python
15
+ # Question
16
+
17
+ if False:
18
+ from unsloth import FastLanguageModel
19
+ model, tokenizer = FastLanguageModel.from_pretrained(
20
+ model_name = "lora_model", # YOUR MODEL YOU USED FOR TRAINING
21
+ max_seq_length = max_seq_length,
22
+ dtype = dtype,
23
+ load_in_4bit = load_in_4bit,
24
+ )
25
+ FastLanguageModel.for_inference(model) # Enable native 2x faster inference
26
+
27
+ # alpaca_prompt = You MUST copy from above!
28
+
29
+ inputs = tokenizer(
30
+ [
31
+ alpaca_prompt.format(
32
+ "Eu preciso treinar uma IA gpt2 do hugginface em meu computador", # instruction
33
+ "", # input
34
+ "", # output - leave this blank for generation!
35
+ )
36
+ ], return_tensors = "pt").to("cuda")
37
+
38
+ from transformers import TextStreamer
39
+ text_streamer = TextStreamer(tokenizer)
40
+ _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 4096)
41
+
42
+ # Answer
43
+
44
+ <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:
45
+
46
+ 1. If the task involves coding, provide a complete, working Python solution with explanations.
47
+ 2. If it's a conceptual question, explain thoroughly, using examples where appropriate.
48
+ 3. Break down complex problems or concepts into steps or components.
49
+ 4. If you're unsure about any part of your response, clearly state your level of confidence and any assumptions you're making.
50
+ 5. If the query is ambiguous or lacks necessary information, ask for clarification before proceeding.
51
+ 6. After providing your response, briefly summarize the key points or solution.
52
+
53
+ Remember, accuracy and helpfulness are crucial. Avoid making unfounded claims or providing incorrect information.
54
+
55
+ ### Input:
56
+ Eu preciso treinar uma IA gpt2 do hugginface em meu computador
57
+
58
+ ### Output:
59
+
60
+ # Importações necessárias
61
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
62
+ from transformers import TrainingArguments, Trainer
63
+ from transformers.data import DataCollatorForLanguageModeling
64
+ from transformers.data.processors import DataProcessor
65
+
66
+ # Configurações
67
+ training_args = TrainingArguments(
68
+ output_dir='./resultados',
69
+ evaluation_strategy='epoch',
70
+ learning_rate=2e-5,
71
+ per_device_train_batch_size=8,
72
+ eval_steps=1000,
73
+ num_warmupSteps=500,
74
+ weighted_metric='accuracy',
75
+ )
76
+
77
+ # Carregamento do tokenizador
78
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
79
+
80
+ # Carregamento do modelo
81
+ modelo = GPT2LMHeadModel.from_pretrained('gpt2')
82
+
83
+ # Configurações do tracker
84
+ tracker = DataProcessor(
85
+ input_class=DataProcessor,
86
+ batch_size=1,
87
+ max_length=100,
88
+ padding=True,
89
+ truncation=True,
90
+ )
91
+
92
+ # Treinando o modelo
93
+ trainer = Trainer(
94
+ args=training_args,
95
+ train_loop=tracker,
96
+ trainable_pipelines=[],
97
+ )
98
+
99
+ # Treinando o modelo
100
+ trainer.train()
101
+
102
+ # Evaluação do modelo
103
+ evaluador = DataCollatorForLanguageModeling(
104
+ tokenizer=tokenizer,
105
+ model=modelo,
106
+ padding=True,
107
+ max_length=100,
108
+ batch_size=8,
109
+ )
110
+
111
+ # Evalua o modelo
112
+ resultados = trainer.evaluate()
113
+
114
+ # Imprimir os resultados
115
+ for name, loss, acc in resultados:
116
+ print(f'{name}: {loss}, {acc:.2f}%')</s>
117
+
118
+ ```
119
 
120
  # Uploaded model
121