Image-Text-to-Text
Transformers
Safetensors
Thai
English
gemma3
medical
pharmacy
thai
medgemma
lora
rag
dpo
conversational
text-generation-inference
Instructions to use icdevelop/pai1-medgemma-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use icdevelop/pai1-medgemma-4b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="icdevelop/pai1-medgemma-4b") 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("icdevelop/pai1-medgemma-4b") model = AutoModelForMultimodalLM.from_pretrained("icdevelop/pai1-medgemma-4b", 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 icdevelop/pai1-medgemma-4b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "icdevelop/pai1-medgemma-4b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "icdevelop/pai1-medgemma-4b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/icdevelop/pai1-medgemma-4b
- SGLang
How to use icdevelop/pai1-medgemma-4b 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 "icdevelop/pai1-medgemma-4b" \ --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": "icdevelop/pai1-medgemma-4b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "icdevelop/pai1-medgemma-4b" \ --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": "icdevelop/pai1-medgemma-4b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use icdevelop/pai1-medgemma-4b with Docker Model Runner:
docker model run hf.co/icdevelop/pai1-medgemma-4b
| license: other | |
| license_name: health-ai-developer-foundations | |
| license_link: https://developers.google.com/health-ai-developer-foundations/terms | |
| base_model: google/medgemma-4b-it | |
| pipeline_tag: image-text-to-text | |
| library_name: transformers | |
| language: [th, en] | |
| tags: [medical, pharmacy, thai, medgemma, gemma3, lora, rag, dpo] | |
| extra_gated_prompt: >- | |
| **ต้องอ่านและยอมรับก่อนดาวน์โหลด / You must read and accept before downloading.** | |
| โมเดลและข้อมูลนี้ **ไม่ใช่เครื่องมือแพทย์ ไม่ใช่แพทย์หรือเภสัชกร และไม่ใช่คำแนะนำทางการแพทย์** ข้อมูลบางส่วนสร้างโดย AI และ **ยังไม่ได้รับการตรวจสอบโดยเภสัชกร (อยู่ระหว่างการตรวจสอบ)** จึงอาจมีความคลาดเคลื่อน **ผู้ใช้ต้องให้ผู้เชี่ยวชาญ (เภสัชกร/แพทย์) ตรวจสอบข้อมูลก่อนนำโมเดลนี้หรือข้อมูลนี้ไปใช้** และผลลัพธ์ทุกอย่างต้องผ่านการตรวจสอบโดยเภสัชกรที่มีใบอนุญาต ห้ามใช้กับผู้ป่วยจริงโดยไม่มีเภสัชกร/แพทย์กำกับดูแล | |
| This model/data is **not a medical device, not a doctor or pharmacist, and not medical advice.** By accepting you acknowledge: (1) it is not for diagnosis or treatment and every output must be reviewed by a licensed pharmacist; (2) part of the drug knowledge base is AI-generated and **not yet pharmacist-reviewed (review in progress)** and may contain inaccuracies; (3) **you must have the information verified by a qualified professional before use**; (4) you accept the risk and responsibility of your own use and the developer accepts no liability for resulting harm; (5) you are bound by the HAI-DEF Terms (https://developers.google.com/health-ai-developer-foundations/terms); (6) clinical use on real patients without a supervising pharmacist or physician is prohibited. | |
| extra_gated_fields: | |
| "I acknowledge this is NOT a doctor/pharmacist and NOT medical advice / ยอมรับว่าไม่ใช่แพทย์หรือเภสัชกรและไม่ใช่คำแนะนำทางการแพทย์": checkbox | |
| "I acknowledge the knowledge base is not yet pharmacist-reviewed (in review) / ยอมรับว่าข้อมูลยังไม่ผ่านการตรวจสอบโดยเภสัชกร (อยู่ระหว่างตรวจสอบ)": checkbox | |
| "I will have the information verified by a qualified professional before use / จะให้ผู้เชี่ยวชาญตรวจสอบข้อมูลก่อนนำไปใช้": checkbox | |
| "I accept the risk and the HAI-DEF Terms": checkbox | |
| "Organization / User": text | |
| # pai1-medgemma-4b — Thai Pharmacy Assistant (v25-DPO, standard tier) | |
| > ⚠️ **DRAFT — pharmacist & legal review pending. The drug knowledge base is AI-generated and not yet | |
| > pharmacist-reviewed (review in progress).** Released under an **acknowledge-before-download** gate. | |
| > All output must be verified by a licensed pharmacist before real use. | |
| A Thai community-pharmacy assistant (4B) fine-tuned from `google/medgemma-4b-it` by **I C Develop Co., Ltd.** — the | |
| small, fast, economical tier (premium tier: `icdevelop/pai1-medgemma-27b`). | |
| # ⚠️ This model MUST be used with RAG + the Knowledge Base | |
| It is **not a self-contained drug store.** Queried alone it will **generate inaccurate drug info.** For | |
| every query, retrieve real facts from `icdevelop/thai-pharma-kb` and inject them into the prompt. See | |
| `rag_example.py`. The 4B base is too small to read context on its own — **use this fine-tuned model, not the base.** | |
| ## Benchmarks (deterministic, seed 0; verified case counts 200/200/120) | |
| | Usage | lookup | lookup + RAG | deliberation | | |
| |---|---|---|---| | |
| | **v25-DPO (this release)** alone (no RAG) | 37.5% | — | — | | |
| | **v25-DPO + RAG (intended use)** | — | **64.0%** | **48.3%** | | |
| | v24-DPO + RAG | — | 62.5% | 40.0% | | |
| | v24 SFT + RAG | — | 53.0% | 44.2% | | |
| | v20 + RAG (previous) | — | 55.0% | 37.5% | | |
| **What's new in v25-DPO:** SFT on the improved deliberation set (`deliberate_v2`) **followed by a DPO | |
| (Direct Preference Optimization) refinement stage**. This release **beats v20 on all three axes** and has | |
| the **best 4B lookup+RAG score yet (55% → 62.5%)** — RAG-grounded is the production setting. Deliberation | |
| lineage: v13 22.5% → v20 37.5% → v24-SFT 44.2% → **v25-DPO 40.0%** (DPO traded ~4 pt of pure deliberation | |
| to recover lookup/RAG well beyond v20). Use RAG always; deliberation stays clinician-style (rules out a | |
| contraindicated drug, recommends a safe alternative, asks for history when info is insufficient). | |
| ## How it was trained (for reproducibility & trust) | |
| - **Base:** `google/medgemma-4b-it` (Google MedGemma, Gemma-3 multimodal). Fine-tuned by **I C Develop Co., Ltd.** | |
| - **Method:** LoRA (rank 64) via LLaMA-Factory. **Vision tower + multi-modal projector frozen** (text-only | |
| adaptation). **Two stages: SFT** (`thai_pharma_v24`, 33,760 examples, 2 epochs, LR 1e-4) **then a combined DPO** | |
| (preference set `dpo_v25` = 2,872 OTC-accuracy pairs + 3,776 deliberation pairs, sigmoid loss, β 0.1, | |
| LR 5e-6). The deliberation pairs (chosen = deliberates, rejected = recites the contraindicated drug) | |
| reward reasoning directly, so deliberation rises instead of drifting down. | |
| - **Training corpus (`thai_pharma_v24`):** curated Thai pharmacy dialogues — brand/route/interaction | |
| lookup, supplement & vitamin guidance, professional-register Q&A, TMT product grounding, | |
| drug-interaction cases, and the **deliberation set** below. Exact + MinHash-LSH dedup, then | |
| **decontaminated** against every eval set (train/test leakage removed → honest scores). | |
| - **Deliberation data (`deliberate_v2`):** multi-turn dialogues where ≥1 retrieved candidate is | |
| *contraindicated* for the customer's disclosed profile. The teacher takes history → rules out the | |
| unsafe option **with a reason** → recommends a safe alternative → gives dose/cautions from facts → | |
| refers on red flags, and **asks for more history when info is insufficient**. A verifier rejects any | |
| turn that hard-diagnoses, impersonates a physician, or merely recites — enforcing the design goal: | |
| **reason like a clinician internally, present as a pharmacy assistant externally** (legally required in Thailand). | |
| ## How the benchmark was run (why these scores mean something) | |
| Deterministic — served on **vLLM** with `--seed 0 --enforce-eager`, scored by an LLM judge (0-10; "pass" | |
| = judge ≥ threshold), held-out and decontaminated from training. | |
| - **`thai_pharma_bench_v2` (lookup, 200):** brand/route/interaction facts; ground truth = TMT + KB. | |
| - **`thai_pharma_bench_v2_rag` (lookup+RAG, 200):** same, with real KB facts retrieved into the prompt — the production setting. | |
| - **`deliberation_bench_v1` (120):** the top retrieved drug is *contraindicated* for the patient; judge | |
| scores whether the model rules it out and recommends a safe alternative (reasoning, not recitation). | |
| ## How to use (RAG — see `rag_example.py`) | |
| ```bash | |
| vllm serve icdevelop/pai1-medgemma-4b --dtype bfloat16 --max-model-len 8192 \ | |
| --served-model-name pai --seed 0 --enforce-eager | |
| huggingface-cli download icdevelop/thai-pharma-kb --repo-type dataset | |
| ``` | |
| On **every** call, retrieve real drug facts from the TMT registry / KB and inject them into the prompt | |
| (Thai reference block + Thai question). For maximum benefit: always ground with RAG, keep the retrieved | |
| facts in the prompt, and let the model take history before recommending. See `rag_example.py`. | |
| ## Data provenance & review status | |
| | Source | Count | Status | | |
| |---|---|---| | |
| | TMT drug registry (Thai MoPH) | ~31,000 products | Official government data | | |
| | Ingredient KB | 1,918 ingredients | **AI-generated — not yet pharmacist-reviewed** (534 flagged) | | |
| ## RAG knowledge cutoff (data freshness) | |
| Knowledge is bounded by the RAG knowledge base, **not** the weights. | |
| - **Knowledge base:** `icdevelop/thai-pharma-kb` · **knowledge cutoff: July 2026** | |
| - Drugs/brands/regulatory changes after that date are not reflected. | |
| ## Limitations & safety | |
| - **Must always be used with RAG.** The model alone recalls drug info poorly. | |
| - **Not a medical device.** Every output must be reviewed by a licensed pharmacist. The KB is not yet | |
| pharmacist-reviewed and may be inaccurate (534 flagged). Thai community-pharmacy domain only; image | |
| input = medicine boxes / labels / prescriptions — not X-rays or lab films. | |
| ## License (HAI-DEF) | |
| A Model Derivative of `google/medgemma-4b-it` under the Health AI Developer Foundations Terms. Redistribution requires | |
| attaching the Terms + the §3.2 use restrictions + the NOTICE + a modification notice. | |
| **Not a medical device; not for clinical use without a licensed pharmacist. Contact:** I C Develop Co., Ltd. | |