Views
No views yet
- Base: microsoft/Phi-3-medium-4k-instruct
- Fine-tuning: Unsloth
- LoRA Implementation: Efficient parameter-efficient fine-tuning
- Hardware: GPU-based training1# Install required dependencies
2pip install transformers torch unsloth
3
4# Optional: Install medical evaluation tools
5pip install -r requirements.txt1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load model and tokenizer
5model_name = "OncogenAI/phi-3-medium-clinical"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 device_map="auto",
10 torch_dtype=torch.float16,
11)
12
13# Prepare input
14prompt = "Clinical Query: Explain the pathophysiology of type 2 diabetes."
15inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
16
17# Generate response
18outputs = model.generate(
19 **inputs,
20 max_length=512,
21 temperature=0.7,
22 top_p=0.95,
23 do_sample=True,
24)
25
26response = tokenizer.decode(outputs[0], skip_special_tokens=True)
27print(response)1from unsloth import FastLanguageModel
2from transformers import TextIteratorStreamer
3from threading import Thread
4
5# Fast loading with Unsloth
6model, tokenizer = FastLanguageModel.from_pretrained(
7 model_name="OncogenAI/phi-3-medium-clinical",
8 max_seq_length=4096,
9 dtype=torch.float16,
10 load_in_4bit=True,
11)
12
13# Streaming inference for long responses
14streamer = TextIteratorStreamer(tokenizer, skip_special_tokens=True)
15generation_kwargs = dict(
16 inputs=inputs,
17 streamer=streamer,
18 max_length=512,
19 temperature=0.7,
20)
21
22thread = Thread(target=model.generate, kwargs=generation_kwargs)
23thread.start()
24
25for text in streamer:
26 print(text, end="", flush=True)1@software{phi3_clinical_2026,
2 author = {OncogenAI},
3 title = {Phi-3-Medium-Clinical: A Medical Domain-Specific Fine-Tuned Model},
4 year = {2026},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/OncogenAI/phi-3-medium-clinical}}
7}1@article{abdin2024phi,
2 title={Phi-3 Technical Report},
3 author={Abdin, Marah and others},
4 journal={arXiv preprint arXiv:2404.14219},
5 year={2024}
6}
7
8@software{unsloth2024,
9 title={Unsloth: Efficient Fine-tuning of Language Models},
10 author={Peng, Daniel Han and others},
11 year={2024},
12 url={https://github.com/unslothai/unsloth}
13}