Views
No views yet
| Property | Value |
|---|---|
| Base Model | microsoft/Phi-4-mini-reasoning |
| Fine-tuning Method | QLoRA (4-bit NF4) |
| LoRA Rank | 8 |
| LoRA Alpha | 16 |
| Target Modules | q_proj, k_proj, v_proj, o_proj |
| Training Steps | 300 |
| Final Training Loss | 1.3847 |
| Loss Reduction | 1.4551 → 1.1983 (−18%) |
| Training Time | ~107 minutes |
| Sequence Length | 1024 |
| Hardware | NVIDIA Tesla T4 (15GB) |
| Framework | HuggingFace Transformers + PEFT + TRL |
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "microsoft/Phi-4-mini-reasoning"
6ADAPTER = "Ganesh01kumar02reddy/phi4-mini-medical-qlora"
7
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.float16,
12 bnb_4bit_use_double_quant=True,
13)
14
15tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
16base_model = AutoModelForCausalLM.from_pretrained(
17 BASE_MODEL,
18 quantization_config=bnb_config,
19 device_map="auto",
20 torch_dtype=torch.float16,
21)
22
23model = PeftModel.from_pretrained(base_model, ADAPTER)
24model.eval()
25
26question = "What are the causes of thrombocytopenia?"
27reasoning = "Consider immune-mediated, drug-induced, and infectious causes."
28
29prompt = (
30 f"<|user|>\n{question}<|end|>\n"
31 f"<|think|>\n{reasoning}<|end|>\n"
32 f"<|assistant|>\n"
33)
34
35inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
36
37with torch.no_grad():
38 output = model.generate(
39 **inputs,
40 max_new_tokens=256,
41 do_sample=False,
42 pad_token_id=tokenizer.eos_token_id,
43 )
44
45answer = tokenizer.decode(output[0][inputs["input_ids"].shape[-1]:],
46 skip_special_tokens=True)
47print(answer)| Step | Description |
|---|---|
| Step 1 | Raw data ingestion + deduplication |
| Step 2 | Quality filtering |
| Step 3 | Length filtering (max 4096 tokens) |
| Step 4 | Train/Val/Test split (70/10/20) |
| Step 5 | Prompt formatting + tokenization + label masking |
| Step 6 | QLoRA fine-tuning on Phi-4-mini-reasoning |
nan due to streaming dataset limitation (does not affect model weights)1@misc{phi4-mini-medical-qlora-2026,
2 author = {Ganesh01kumar02reddy},
3 title = {phi4-mini-medical-qlora},
4 year = {2026},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/Ganesh01kumar02reddy/phi4-mini-medical-qlora}}
7}