Image-Text-to-Text
Transformers
Safetensors
Thai
English
gemma3
medical
pharmacy
thai
medgemma
lora
dpo
rag
conversational
text-generation-inference
Instructions to use icdevelop/pai1-medgemma-27b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use icdevelop/pai1-medgemma-27b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="icdevelop/pai1-medgemma-27b") 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-27b") model = AutoModelForMultimodalLM.from_pretrained("icdevelop/pai1-medgemma-27b", 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-27b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "icdevelop/pai1-medgemma-27b" # 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-27b", "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-27b
- SGLang
How to use icdevelop/pai1-medgemma-27b 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-27b" \ --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-27b", "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-27b" \ --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-27b", "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-27b with Docker Model Runner:
docker model run hf.co/icdevelop/pai1-medgemma-27b
| license: other | |
| license_name: health-ai-developer-foundations | |
| license_link: https://developers.google.com/health-ai-developer-foundations/terms | |
| base_model: google/medgemma-27b-it | |
| pipeline_tag: image-text-to-text | |
| library_name: transformers | |
| language: [th, en] | |
| tags: [medical, pharmacy, thai, medgemma, gemma3, lora, dpo, rag] | |
| 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-27b — Thai Pharmacy Assistant (v26-DPO, premium tier) | |
| > ⚠️ **DRAFT — pharmacist & legal review pending.** The drug knowledge base behind this model is | |
| > partly AI-generated and **not yet fully reviewed by a licensed pharmacist** (534 entries flagged). | |
| > Released under an **acknowledge-before-download** gate. **Every output must be verified by a | |
| > licensed pharmacist before real-world use.** | |
| ## What this model is | |
| `pai1-medgemma-27b` is a **Thai community-pharmacy assistant** fine-tuned from | |
| [`google/medgemma-27b-it`](https://huggingface.co/google/medgemma-27b-it) by **I C Develop Co., Ltd.** | |
| **Its job:** help a pharmacy counter handle over-the-counter (OTC) requests in Thai — take a short | |
| history, rule out drugs that are unsafe for that customer, recommend a suitable OTC option with dose | |
| and cautions, and **refer to a doctor when red-flag symptoms appear**. | |
| **Design principle — reason like a clinician internally, present as a pharmacy assistant externally.** | |
| The model is trained to do the clinical reasoning a good pharmacist does (contraindication checks, | |
| interaction awareness, red-flag triage) while **never claiming to be a physician and never issuing a | |
| diagnosis** — presenting as a doctor is legally prohibited in Thailand. | |
| **Tier:** this is the **premium tier** (higher accuracy). The smaller, faster, cheaper tier is | |
| [`icdevelop/pai1-medgemma-4b`](https://huggingface.co/icdevelop/pai1-medgemma-4b). A smaller **FP8** build (~28 GB, near-identical quality) is at [`icdevelop/pai1-medgemma-27b-fp8`](https://huggingface.co/icdevelop/pai1-medgemma-27b-fp8). | |
| **Multimodal:** inherits MedGemma's image input — intended for **medicine boxes, labels and | |
| prescriptions**, *not* X-rays or lab films. | |
| ## Benchmarks | |
| Version lineage (higher is better; every score below was produced by running **all** cases): | |
| | Task | v20 | v24 | **v26-DPO (this release)** | | |
| |---|---|---|---| | |
| | lookup (no RAG) | 46.5 % | 43.0 % | **50.5 %** | | |
| | lookup + RAG | 64.5 % | 65.3 % | **64.5 %** | | |
| | deliberation | 29.2 % | 37.7 % | **38.3 %** | | |
| **Reading the numbers:** v26-DPO is the strongest on drug-fact recall (**lookup 50.5 %**, +7.5 over | |
| v24) while holding RAG performance and slightly improving clinical deliberation. Deliberation has | |
| risen across the whole line (29.2 → 38.3) thanks to the deliberation training described below. | |
| ### How the benchmark was run (methodology) | |
| All benchmarks are **deterministic** — the model is served on **vLLM** with `--seed 0 --enforce-eager`, | |
| and answers are graded by an LLM judge (0–10). A case counts as **pass** only when the judge passes it | |
| **and** no safety violation (`must_not`) is triggered. All benchmark cases are **held out** and | |
| **decontaminated** from the training corpus, so scores are not inflated by memorisation. | |
| | Benchmark | Cases | What it measures | | |
| |---|---|---| | |
| | `thai_pharma_bench_v2` (lookup) | 200 | Brand / route / interaction facts with **no retrieval**. Ground truth from the Thai TMT registry + KB. Pure drug-fact recall. | | |
| | `thai_pharma_bench_v2_rag` (lookup + RAG) | 200 | Same questions, but real KB facts are retrieved and injected into the prompt — **the intended production setting**. | | |
| | `deliberation_bench_v1` | 120 | The obvious/top retrieved drug is **contraindicated** for the customer's disclosed profile. The judge checks whether the model **rules it out, explains why, and recommends a safe alternative** — reasoning, not recitation. | | |
| Before release, the merged model also passes a **6-prompt generation check** (headache+fever, | |
| greeting, diarrhoea, allergic rhinitis, drug comparison, abdominal pain) verifying coherent Thai | |
| output with no repetition or degeneration. | |
| ## How it was trained | |
| - **Base model:** [`google/medgemma-27b-it`](https://huggingface.co/google/medgemma-27b-it) (Google MedGemma, Gemma-3 multimodal). | |
| - **Stage 1 — LoRA SFT** (rank 32, 2 epochs, bf16, LR 3e-6) on `thai_pharma_v24` (~33 k dialogues). | |
| The **vision tower and multi-modal projector are frozen** — this is a text-domain adaptation, so | |
| image understanding stays exactly as MedGemma trained it. | |
| - **Stage 2 — combined DPO** (β 0.1, `ld_alpha` 0.5 length-desensitisation, LR 1e-6, 100 steps) on | |
| 6,648 preference pairs = 2,872 OTC-accuracy pairs + 3,776 **deliberation** pairs. | |
| - **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, plus the deliberation set below. Exact-dedup + MinHash-LSH near-dedup, then | |
| **decontaminated against every evaluation set**. | |
| - **Deliberation data** (`deliberate_v2`) — the key ingredient: multi-turn dialogues in which at least | |
| one retrieved candidate is *contraindicated* for the customer's disclosed profile (pregnancy, | |
| warfarin, gastric ulcer, driving, …). The target answer must take history → **rule out the unsafe | |
| option with a reason** → recommend a safe alternative → give dose/cautions from the retrieved facts | |
| → refer on red flags, and **ask for more history when information is insufficient** instead of | |
| guessing. A verifier rejects any turn that hard-diagnoses, impersonates a physician, or merely | |
| recites the record. | |
| - **Deliberation preference pairs** (DPO): *chosen* = the clinician-style deliberation, *rejected* = a | |
| fluent but unsafe answer that recommends the contraindicated drug. The pairs are **length-balanced** | |
| (chosen/rejected token ratio ≈ 1.0) so the preference signal is **behaviour, not verbosity**. | |
| ## How to use | |
| ### Recommended: serve with vLLM and ground every answer with RAG | |
| ```bash | |
| vllm serve icdevelop/pai1-medgemma-27b \ | |
| --dtype bfloat16 --max-model-len 8192 \ | |
| --served-model-name pai --seed 0 --enforce-eager | |
| # the knowledge base used for grounding | |
| huggingface-cli download icdevelop/thai-pharma-kb --repo-type dataset | |
| ``` | |
| ### Getting the best results | |
| 1. **Always ground with RAG.** Retrieve the real drug facts (from the TMT registry / KB) for the | |
| drugs in question and inject them into the prompt. Lookup+RAG (64.5 %) is far above no-RAG | |
| behaviour, and grounded answers are what the model was trained to produce. | |
| 2. **Write the reference block and the question in Thai.** The model is purpose-built for Thai | |
| community pharmacy; Thai prompts get noticeably better answers. | |
| 3. **Let it take history.** If the customer's message lacks key details, the model is trained to ask | |
| follow-up questions — allow a multi-turn conversation rather than forcing a single-shot answer. | |
| 4. **Give it more than one candidate drug.** The deliberation training shows its value when the model | |
| must choose between options and exclude the unsafe one. | |
| 5. **Keep a pharmacist in the loop.** Treat every answer as a draft recommendation for a licensed | |
| pharmacist to confirm. | |
| ### Not recommended | |
| - Using it **without retrieval** for factual drug questions (recall is much weaker). | |
| - Asking for a **diagnosis**, or presenting it to end users as a doctor — it is trained to refuse and | |
| refer, and doing so is legally prohibited in Thailand. | |
| - Radiology or laboratory image interpretation — out of scope. | |
| ## Data provenance & review status | |
| | Source | Count | Status | | |
| |---|---|---| | |
| | TMT drug registry (Thai MoPH) | ~31,000 products | Official government data | | |
| | Ingredient knowledge base | 1,918 ingredients | **AI-generated — not yet pharmacist-reviewed** (534 flagged for review) | | |
| ### Knowledge cutoff (data freshness) | |
| The knowledge available to this model is bounded by the **RAG knowledge base**, not by the weights. | |
| - **Knowledge base:** `icdevelop/thai-pharma-kb` · **cutoff: July 2026** | |
| - Drugs, brands, supplements or regulatory changes registered after that date are **not** reflected. | |
| To advance the cutoff, re-pull the TMT registry, rebuild the KB, and update the dataset. | |
| ## Model format | |
| **BF16** — full-precision merged weights, ~52 GB on disk. | |
| ## Limitations & safety | |
| - **Not a medical device.** Not for diagnosis or treatment. Every output must be reviewed by a | |
| licensed pharmacist before it reaches a patient. | |
| - **The knowledge base is not yet pharmacist-reviewed** and may contain inaccuracies (534 entries | |
| flagged). This is why the repository is gated behind an explicit acknowledgement. | |
| - **Thai community-pharmacy domain only.** Image input is limited to medicine boxes, labels and | |
| prescriptions. | |
| - The model can still make mistakes on rare drugs, complex poly-pharmacy and unusual interactions — | |
| RAG grounding reduces but does not eliminate this. | |
| ## License | |
| A Model Derivative of [`google/medgemma-27b-it`](https://huggingface.co/google/medgemma-27b-it) under the | |
| **Health AI Developer Foundations (HAI-DEF) Terms**. Redistribution requires attaching the Terms, the | |
| §3.2 use restrictions, the NOTICE, and a modification notice. | |
| **Not a medical device; not for clinical use without a licensed pharmacist.** | |
| Contact: I C Develop Co., Ltd. | |