Views
No views yet
bitsandbytes) together with LoRA adapters on the base model, allowing low‑VRAM training and fast inference.yes, no, maybe)pqa_labeled)yes, no, maybe).yes, no, or maybe.1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2from peft import PeftModel
3from bitsandbytes.config import BitsAndBytesConfig
4import torch
5
6base_model_id = "google/flan-t5-small"
7adapter_id = "MileStanislavov/flan-t5-small-pubmedqa-lora"
8
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_use_double_quant=True,
13 bnb_4bit_compute_dtype=torch.float16,
14)
15
16tokenizer = AutoTokenizer.from_pretrained(base_model_id)
17base_model = AutoModelForSeq2SeqLM.from_pretrained(base_model_id, quantization_config=bnb_config)
18model = PeftModel.from_pretrained(base_model, adapter_id)
19
20def predict_yes_no_maybe(question, context):
21 prompt = f"question: {question} context: {context}"
22 inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
23 outputs = model.generate(**inputs, max_new_tokens=4, num_beams=4, do_sample=False)
24 text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip().lower().replace(".", "")
25 return text if text in {"yes", "no", "maybe"} else "maybe"merge_and_unload(), load the merged model directly:1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model = AutoModelForSeq2SeqLM.from_pretrained("your-username/flan-t5-small-pubmedqa-merged")
4tokenizer = AutoTokenizer.from_pretrained("your-username/flan-t5-small-pubmedqa-merged")pqa_labeledquestion: <q> context: <context> (truncated to 512 tokens)["q", "k", "v", "o", "wi_0", "wi_1", "wo"] (T5 attention and feed‑forward projections)float16 or bfloat162e-4