All samples were converted to a unified chat template compatible with the Gemma 4 instruction format.
A structured clinical-prompt evaluation across 54 prompts covering 7 medical disciplines yielded:
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5BASE_MODEL = "google/gemma-4-E2B-it"
6ADAPTER_REPO = "fulvio/gemma-4-e2b-medical-qlora-adapter"
7
8# Load base model in 4-bit for 12 GB VRAM
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13 bnb_4bit_use_double_quant=True,
14)
15
16tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
17model = AutoModelForCausalLM.from_pretrained(
18 BASE_MODEL,
19 quantization_config=bnb_config,
20 device_map="auto",
21)
22
23# Load adapter
24model = PeftModel.from_pretrained(model, ADAPTER_REPO)
25
26# Generate
27prompt = """You are a medical AI assistant. Answer the following question accurately.
28
29Question: What are the first-line treatments for acute uncomplicated cystitis in non-pregnant women?
30
31Answer:"""
32
33inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
34outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.7)
35print(tokenizer.decode(outputs[0], skip_special_tokens=True))
If you have loaded and merged the adapter into the base model, you can push the merged weights separately and load them directly:
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3MERGED_REPO = "fulvio/gemma-4-e2b-medical-qlora-merged" # if uploaded
4
5tokenizer = AutoTokenizer.from_pretrained(MERGED_REPO)
6model = AutoModelForCausalLM.from_pretrained(
7 MERGED_REPO,
8 torch_dtype=torch.bfloat16,
9 device_map="auto",
10)
Carbon emissions estimated using the
ML Impact calculator (Lacoste et al., 2019).
If you use this adapter, please cite both the original Gemma model and this fine-tuning work:
1@misc{gemma4e2b_medical_qlora,
2 author = {Fulvio},
3 title = {QLoRA Medical Adapter for Gemma 4 E2B},
4 year = {2025},
5 howpublished = {\\url{https://huggingface.co/fulvio/gemma-4-e2b-medical-qlora-adapter}},
6}
1@article{gemma2024,
2 title = {Gemma: Open Models Based on Gemini Research and Technology},
3 author = {Gemma Team},
4 year = {2024},
5 howpublished = {\\url{https://huggingface.co/google/gemma-4-E2B-it}},
6}
For questions or issues, please open an issue on the Hugging Face repository.