Abirate/english_quotes
Viewer • Updated • 2.51k • 3.8k • 108
How to use hipnologo/GPT-Neox-20b-QLoRA-FineTune-english_quotes_dataset with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b")
model = PeftModel.from_pretrained(base_model, "hipnologo/GPT-Neox-20b-QLoRA-FineTune-english_quotes_dataset")The following bitsandbytes quantization config was used during training:
This model is a fine-tuned version of the EleutherAI/gpt-neox-20b model using the QLoRa library and the PEFT library.
The code below performs the following steps:
torch and classes from the transformers library.model_id as "hipnologo/GPT-Neox-20b-QLoRA-FineTune-english_quotes_dataset".BitsAndBytesConfig object named bnb_config with the following configuration:load_in_4bit set to Truebnb_4bit_use_double_quant set to Truebnb_4bit_quant_type set to "nf4"bnb_4bit_compute_dtype set to torch.bfloat16AutoTokenizer object named tokenizer by loading the tokenizer for the specified model_id.AutoModelForCausalLM object named model by loading the pre-trained model for the specified model_id and providing the quantization_config as bnb_config. The model is loaded on device cuda:0.text with the value "Twenty years from now".device with the value "cuda:0", representing the device on which the model will be executed.text using the tokenizer and converts it to a PyTorch tensor, assigning it to the inputs variable. The tensor is moved to the specified device.model.generate method by passing the inputs tensor and setting the max_new_tokens parameter to 20. The generated output is assigned to the outputs variable.outputs tensor using the tokenizer to obtain the generated text without special tokens, and assigns it to the generated_text variable.generated_text.import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
# Load the base pre-trained model
base_model_id = "EleutherAI/gpt-neox-20b"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
model = AutoModelForCausalLM.from_pretrained(base_model_id)
# Fine-tuning model
model_id = "hipnologo/GPT-Neox-20b-QLoRA-FineTune-english_quotes_dataset"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
# Load the fine-tuned model
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={"":0})
text = "Twenty years from now"
device = "cuda:0"
inputs = tokenizer(text, return_tensors="pt").to(device)
outputs = model.generate(**inputs, max_new_tokens=20)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
This model is licensed under Apache 2.0. Please see the LICENSE for more information.
Base model
EleutherAI/gpt-neox-20b
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neox-20b") model = PeftModel.from_pretrained(base_model, "hipnologo/GPT-Neox-20b-QLoRA-FineTune-english_quotes_dataset")