Files
Table with columns: File, What it is| File | What it is |
|---|
adapter_model.safetensors, adapter_config.json | PEFT LoRA adapter (checkpoint-6500 of the stage-2 run). Load on top of microsoft/Phi-3.5-mini-instruct. |
medproqa-phi35-lora-f16.gguf | The same adapter converted to GGUF with llama.cpp's convert_lora_to_gguf.py, for use with llama.cpp / llama-cpp-python on top of a Phi-3.5-mini-instruct GGUF. The demo Space uses it with bartowski/Phi-3.5-mini-instruct-GGUF (Q4_K_M) on CPU. |
Only adapter weights are published; no optimizer or trainer state.
Training
- Base model: Phi-3.5-mini-instruct (3.8B), loaded in 4-bit NF4 (bitsandbytes) during training.
- LoRA: r = 16, alpha = 32, dropout 0.05, target modules
qkv_proj and o_proj, no bias.
- Data: the challenge's
train_easy and train_medium splits (first 64,000 rows of the combined set, 90/10 train/eval split, seed 42).
- Optimisation: HF
Trainer, lr 5e-5, batch size 2 x grad accumulation 8, 2 epochs, FP16, gradient checkpointing, max length 256.
- Checkpoint:
checkpoint-6500 (global step 6500, epoch ~1.81). This is the adapter that the project's
submission.ipynb loads (lora_phi3_stage2/checkpoint-6500) and the one committed to the GitHub repo.
The challenge dataset is distributed through the Kaggle competition and is not redistributed here.
Results
The project README does not report accuracy numbers, so none are claimed here. The README describes
the evaluation: accuracy on the easy / medium / hard test sets, reading the option letter after Answer:.
Training prompt (from medical-llm.ipynb); the model completes it with the option letter:
Question: <question text>Choices:(A) <option A>(B) <option B>(C) <option C>(D) <option D>Answer: <letter>
Usage
import torchfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom peft import PeftModel base_id = "microsoft/Phi-3.5-mini-instruct"tok = AutoTokenizer.from_pretrained(base_id)model = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.float16, device_map="auto")model = PeftModel.from_pretrained(model, "Rik0411/medproqa-phi35-lora").eval() q = "Which vitamin deficiency causes scurvy?"opts = {"A": "Vitamin A", "B": "Vitamin B12", "C": "Vitamin C", "D": "Vitamin D"}prompt = f"Question: {q}\nChoices:\n" + "\n".join(f"({k}) {v}" for k, v in opts.items()) + "\nAnswer:" ids = tok(prompt, return_tensors="pt").to(model.device)with torch.no_grad(): logits = model(**ids).logits[0, -1]letter_ids = {L: tok.encode(" " + L, add_special_tokens=False)[-1] for L in opts}print(max(opts, key=lambda L: logits[letter_ids[L]].item()))
llama-cpp-python (CPU)
from huggingface_hub import hf_hub_downloadfrom llama_cpp import Llama base = hf_hub_download("bartowski/Phi-3.5-mini-instruct-GGUF", "Phi-3.5-mini-instruct-Q4_K_M.gguf")lora = hf_hub_download("Rik0411/medproqa-phi35-lora", "medproqa-phi35-lora-f16.gguf")llm = Llama(model_path=base, lora_path=lora, n_ctx=1024, logits_all=True, verbose=False)# score the next token after "Answer:" for " A" .. " D", as in the demo Space (space/engine.py in the GitHub repo)
Limitations
- Not medical advice. This is a student research / competition project. Do not use it to make or
support any clinical, diagnostic or treatment decision. Ask a qualified clinician.
- It only picks a letter among the options given. It does not know when none of the options is right, and
it can be confidently wrong.
- The adapter was trained on answer letters only. Any explanation shown in the demo is generated afterwards
by the model in chat mode and may not reflect how the answer was chosen; it can be inaccurate.
- Training data comes from a single exam-style competition dataset; it may contain errors, regional
conventions and biases, and performance outside that question style is unknown.
- Observed label shift. On 24 hand-written sanity questions recorded in the demo, the adapter picked the option
immediately before the standard answer in 18 cases (the base model answered all 24 correctly). Spot checks of the
challenge training labels suggest many rows are shifted by one option, which the adapter appears to have learned.
See the demo's recorded runs.
- English only. The demo runs a 4-bit quantized base model, which can differ slightly from FP16 results.
License
Adapter released under MIT, same as the base model microsoft/Phi-3.5-mini-instruct.