Views
No views yet
Instruction / Input / Answer) to align with instruction-following behavior.google/gemma-3-270M1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5model_name = "google/gemma-3-270m"
6adapter_dir = "kunj/gemma3-270m-bioinstruct-lora" # replace with your HF repo
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8if tokenizer.pad_token is None:
9 tokenizer.pad_token = tokenizer.eos_token
10
11base = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
12model = PeftModel.from_pretrained(base, adapter_dir)
13model.eval()
14
15prompt = "Instruction: Summarize this clinical note.\nInput: Patient with hypertension and diabetes admitted with dyspnea. Echocardiogram shows EF 30%.\nAnswer: "
16
17enc = tokenizer(prompt, return_tensors="pt").to(model.device)
18with torch.no_grad():
19 out = model.generate(**enc, max_new_tokens=128)
20print(tokenizer.decode(out[0][enc['input_ids'].shape[1]:], skip_special_tokens=True))1vllm serve kunj/gemma3-270m-bioinstruct-lora \
2 --dtype bfloat16 \
3 --max-model-len 2048Instruction, Input, and Answer fields.