Instructions to use naazimsnh02/Shifa-4B-SFT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use naazimsnh02/Shifa-4B-SFT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="naazimsnh02/Shifa-4B-SFT") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("naazimsnh02/Shifa-4B-SFT") model = AutoModelForMultimodalLM.from_pretrained("naazimsnh02/Shifa-4B-SFT", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use naazimsnh02/Shifa-4B-SFT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "naazimsnh02/Shifa-4B-SFT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naazimsnh02/Shifa-4B-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/naazimsnh02/Shifa-4B-SFT
- SGLang
How to use naazimsnh02/Shifa-4B-SFT with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "naazimsnh02/Shifa-4B-SFT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naazimsnh02/Shifa-4B-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "naazimsnh02/Shifa-4B-SFT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naazimsnh02/Shifa-4B-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use naazimsnh02/Shifa-4B-SFT with Docker Model Runner:
docker model run hf.co/naazimsnh02/Shifa-4B-SFT
Shifa-4B
Shifa-4B is a 4-billion parameter medical reasoning model built on Qwen3.5-4B. It is fine-tuned to reason step-by-step through medical questions using chain-of-thought inside <think>...</think> blocks, then deliver a clear final answer.
This is the merged full-weight model (LoRA adapters baked in, fp16) — ready for direct inference with no adapter loading required. The vision encoder is preserved from the base model, so Shifa-4B can process both text and image inputs.
For the lightweight LoRA adapter only, see naazimsnh02/Shifa-4B-SFT-SFT-LoRA.
Benchmark Results (Stage-1 SFT)
| Benchmark | Shifa-4B | MedGemma-4B-IT | Delta |
|---|---|---|---|
| MedQA (USMLE, 4-opt) | 0.702 | 0.691 | +0.011 |
| MedMCQA | 0.508 | 0.598 | -0.090 |
| PubMedQA | 0.374 | 0.682 | -0.308 |
MedGemma targets are from the google/medgemma-4b-it model card. Evaluated on 500 samples per benchmark using greedy decoding.
Quickstart
Text-only
from transformers import AutoModelForCausalLM, AutoProcessor
import torch
model = AutoModelForCausalLM.from_pretrained(
"naazimsnh02/Shifa-4B-SFT",
torch_dtype=torch.bfloat16,
device_map="auto",
)
processor = AutoProcessor.from_pretrained("naazimsnh02/Shifa-4B-SFT")
messages = [
{"role": "user", "content": "A 55-year-old woman with diabetes presents with a painless foot ulcer. Describe the pathophysiology and management approach."},
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
tokenizer = processor.tokenizer
inputs = tokenizer([text], return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
print(tokenizer.decode(output[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
With Images (multimodal)
from transformers import AutoModelForCausalLM, AutoProcessor
from PIL import Image
import torch
model = AutoModelForCausalLM.from_pretrained(
"naazimsnh02/Shifa-4B-SFT",
torch_dtype=torch.bfloat16,
device_map="auto",
)
processor = AutoProcessor.from_pretrained("naazimsnh02/Shifa-4B-SFT")
image = Image.open("chest_xray.png")
messages = [
{"role": "user", "content": [
{"type": "image", "image": image},
{"type": "text", "text": "What findings do you observe in this chest X-ray?"},
]},
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=[text], images=[image], return_tensors="pt", padding=True).to(model.device)
output = model.generate(**inputs, max_new_tokens=512, do_sample=False)
print(processor.batch_decode(output[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0])
Training Details
Data
~395K examples blended from three medical reasoning datasets plus a general-instruction mix:
| Source | Samples | Description |
|---|---|---|
| FreedomIntelligence/medical-o1-reasoning-SFT | ~20K | HuatuoGPT-o1 gold chain-of-thought traces |
| OpenMed/Medical-Reasoning-SFT-GPT-OSS-120B | 200K | High-effort reasoning from GPT-OSS-120B |
| Intelligent-Internet/II-Medical-Reasoning-SFT | 150K | Sampled for scale and diversity |
| HuggingFaceH4/ultrachat_200k | ~28K (7%) | General instruction mix to prevent catastrophic forgetting |
Approach
- Stage-1: Supervised Fine-Tuning — QLoRA on language layers only (vision tower frozen), training the model to produce
<think>reasoning chains followed by a final answer. Response-only loss masking ensures the model learns from assistant turns only. - Stage-2: GRPO (planned) — Reinforcement learning with verifiable MCQ rewards on MedQA + MedMCQA to strengthen overall medical reasoning accuracy. The final GRPO model will be published at naazimsnh02/Shifa-4B.
Hyperparameters
| Parameter | Value |
|---|---|
| Method | QLoRA (4-bit NF4) → merged to fp16 |
| LoRA rank (r) | 32, alpha = 64 |
| Target modules | All attention + MLP (language layers only) |
| Batch size | 4 × 4 gradient accumulation (effective 16) |
| Learning rate | 1e-4 (cosine schedule) |
| Max sequence length | 4096 |
| Training steps | 10,000 (~2 epochs) |
| Optimizer | AdamW 8-bit |
| Final training loss | ~0.59 |
| Training time | ~21.7 hours on 1× A100-SXM4-80GB |
Framework
Architecture
Shifa-4B inherits Qwen3.5-4B's full architecture:
- Language model: 4B parameter decoder-only transformer
- Vision encoder: Preserved and frozen from base model (supports image inputs)
- Hybrid thinking: Native
<think>/</think>tokens for chain-of-thought reasoning
Limitations
- Not intended for clinical use or medical decision-making. This is a research model.
- Performance on PubMedQA (literature-based reasoning) is limited and under investigation.
- Vision capabilities are inherited from the base model — the vision encoder was not fine-tuned for medical imaging.
- The model inherits biases and limitations from its base model and training data.
- Benchmark scores are from 500-sample evaluations; full-set evaluations may differ.
Citation
If you use Shifa-4B in your research, please cite the base model and training datasets:
@misc{shifa4b2026,
title={Shifa-4B: Medical Reasoning Model},
author={Naazim},
year={2026},
url={https://huggingface.co/naazimsnh02/Shifa-4B}
}
License
Apache 2.0 — same as the base model (Qwen3.5-4B).
- Downloads last month
- 4
Model tree for naazimsnh02/Shifa-4B-SFT
Datasets used to train naazimsnh02/Shifa-4B-SFT
FreedomIntelligence/medical-o1-reasoning-SFT
Intelligent-Internet/II-Medical-Reasoning-SFT
Collection including naazimsnh02/Shifa-4B-SFT
Evaluation results
- Accuracy on MedQA (USMLE, 4-opt)test set self-reported0.702
- Accuracy on MedMCQAvalidation set self-reported0.508
- Accuracy on PubMedQAtest set self-reported0.374