|
--- |
|
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) |
|
|