openlifescienceai/medmcqa
Viewer • Updated • 193k • 31.4k • 223
How to use Pk3112/medmcqa-lora-llama3-8b-instruct with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("unsloth/llama-3-8b-instruct-bnb-4bit")
model = PeftModel.from_pretrained(base_model, "Pk3112/medmcqa-lora-llama3-8b-instruct")How to use Pk3112/medmcqa-lora-llama3-8b-instruct with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Pk3112/medmcqa-lora-llama3-8b-instruct to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Pk3112/medmcqa-lora-llama3-8b-instruct to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Pk3112/medmcqa-lora-llama3-8b-instruct to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="Pk3112/medmcqa-lora-llama3-8b-instruct",
max_seq_length=2048,
)Adapter weights only for meta-llama/Meta-Llama-3-8B-Instruct, fine-tuned to answer medical multiple-choice questions (A/B/C/D).
Subjects used for fine-tuning and evaluation: Biochemistry and Physiology.
Educational use only. Not medical advice.
Access note: Llama-3 base is a public gated model on HF.
Accept the base model license on its page and use a fine-grained token that allows public gated repos.
import os, re
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
BASE = "meta-llama/Meta-Llama-3-8B-Instruct"
ADAPTER = "Pk3112/medmcqa-lora-llama3-8b-instruct"
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN") # required if not logged in
tok = AutoTokenizer.from_pretrained(BASE, use_fast=True, token=hf_token)
base = AutoModelForCausalLM.from_pretrained(BASE, device_map="auto", token=hf_token)
model = PeftModel.from_pretrained(base, ADAPTER, token=hf_token).eval()
prompt = (
"Question: Which vitamin is absorbed in the ileum?\n"
"A. Vitamin D\nB. Vitamin B12\nC. Iron\nD. Fat\n\n"
"Answer:"
)
inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=8, do_sample=False)
text = tok.decode(out[0], skip_special_tokens=True)
m = re.search(r"Answer:\s*([A-D])\b", text)
print(f"Answer: {m.group(1)}" if m else text.strip())
Tip: For rich explanations, increase max_new_tokens. For answer-only, keep it small and stop after the letter to reduce latency.
| Model | Internal val acc (%) | Original val acc (%) | TTFT (ms) | Gen time (ms) | In/Out tokens |
|---|---|---|---|---|---|
| Llama-3-8B (LoRA) | 83.83 | 65.20 | 567 | 14874 | 148 / 80 |
r=32, alpha=64, dropout=0.0; targets q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj768Answer: <A/B/C/D>)subject_name (Biochemistry, Physiology)adapter_model.safetensorsadapter_config.jsonmeta-llama/Meta-Llama-3-8B-Instruct (public gated on HF)openlifescienceai/medmcqa — follow dataset licenseBase model
meta-llama/Meta-Llama-3-8B-Instruct