Out repository flan-alpaca-lora contains the details to train flan-t5 with Alpaca instructions and low-rank adaptation.
You can use the following code easily.
Usage:
import transformers
from peft import PeftModel
import torch
model_name = "google/flan-t5-xxl"; peft_model_id = "reasonwang/flan-alpaca-lora-xxl"
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
base_model = transformers.AutoModelForSeq2SeqLM.from_pretrained(model_name, use_cache=False, load_in_8bit=True, torch_dtype=torch.float16, device_map={"": 0})
peft_model = PeftModel.from_pretrained(base_model, peft_model_id, device_map={"": 0})
inputs = tokenizer("List a few tips to get good scores in math.", return_tensors="pt")
for k, v in inputs.items():
inputs[k] = v.to("cuda")
outputs = peft_model.generate(**inputs, max_length=128, do_sample=True)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))