Image-Text-to-Text
Transformers
gemma3_text
gemma3
medical
radiology
clinical-reasoning
dermatology
pathology
ophthalmology
chest-x-ray
arxiv:2303.15343
arxiv:2507.05201
arxiv:2405.03162
arxiv:2106.14463
arxiv:2412.03555
arxiv:2501.19393
arxiv:2009.13081
arxiv:2102.09542
arxiv:2411.15640
arxiv:2404.05590
arxiv:2501.18362
oflm
openflowlm
npu2
q4nx
conversational
Instructions to use OpenFlowLM/Medgemma-4B-NPU2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenFlowLM/Medgemma-4B-NPU2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="OpenFlowLM/Medgemma-4B-NPU2") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("OpenFlowLM/Medgemma-4B-NPU2") model = AutoModelForMultimodalLM.from_pretrained("OpenFlowLM/Medgemma-4B-NPU2", 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 = tokenizer.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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenFlowLM/Medgemma-4B-NPU2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenFlowLM/Medgemma-4B-NPU2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenFlowLM/Medgemma-4B-NPU2", "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/OpenFlowLM/Medgemma-4B-NPU2
- SGLang
How to use OpenFlowLM/Medgemma-4B-NPU2 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 "OpenFlowLM/Medgemma-4B-NPU2" \ --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": "OpenFlowLM/Medgemma-4B-NPU2", "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 "OpenFlowLM/Medgemma-4B-NPU2" \ --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": "OpenFlowLM/Medgemma-4B-NPU2", "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 OpenFlowLM/Medgemma-4B-NPU2 with Docker Model Runner:
docker model run hf.co/OpenFlowLM/Medgemma-4B-NPU2
Commit ·
3ecb5f0
0
Parent(s):
Duplicate from Atomic-Germ/Medgemma-4B-NPU2
Browse files- .gitattributes +38 -0
- README.md +95 -0
- chat_template.jinja +47 -0
- config.json +41 -0
- model.q4nx +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +0 -0
- vision_weight.q4nx +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
model.q4nx filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
vision_weight.q4nx filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
base_model:
|
| 4 |
+
- Atomic-Germ/Medgemma-4B-NPU2
|
| 5 |
+
base_model_relation: quantized
|
| 6 |
+
quantized_by: Atomic-Germ
|
| 7 |
+
pipeline_tag: image-text-to-text
|
| 8 |
+
oflm-family: gemma3
|
| 9 |
+
tags:
|
| 10 |
+
- transformers
|
| 11 |
+
- gemma3
|
| 12 |
+
- image-text-to-text
|
| 13 |
+
- medical
|
| 14 |
+
- radiology
|
| 15 |
+
- clinical-reasoning
|
| 16 |
+
- dermatology
|
| 17 |
+
- pathology
|
| 18 |
+
- ophthalmology
|
| 19 |
+
- chest-x-ray
|
| 20 |
+
- arxiv:2303.15343
|
| 21 |
+
- arxiv:2507.05201
|
| 22 |
+
- arxiv:2405.03162
|
| 23 |
+
- arxiv:2106.14463
|
| 24 |
+
- arxiv:2412.03555
|
| 25 |
+
- arxiv:2501.19393
|
| 26 |
+
- arxiv:2009.13081
|
| 27 |
+
- arxiv:2102.09542
|
| 28 |
+
- arxiv:2411.15640
|
| 29 |
+
- arxiv:2404.05590
|
| 30 |
+
- arxiv:2501.18362
|
| 31 |
+
- base_model:google/gemma-3-4b-pt
|
| 32 |
+
- base_model:finetune:google/gemma-3-4b-pt
|
| 33 |
+
- license:other
|
| 34 |
+
- endpoints_compatible
|
| 35 |
+
- region:us
|
| 36 |
+
- oflm
|
| 37 |
+
- openflowlm
|
| 38 |
+
- npu2
|
| 39 |
+
- q4nx
|
| 40 |
+
---
|
| 41 |
+
# Medgemma-4B-NPU2
|
| 42 |
+
|
| 43 |
+
**OpenFlowLM Q4NX conversion of [`Atomic-Germ/Medgemma-4B-NPU2`](https://huggingface.co/Atomic-Germ/Medgemma-4B-NPU2)** for AMD XDNA NPU inference.
|
| 44 |
+
|
| 45 |
+
This repository contains a quantized **Q4NX** port of the model, compiled for the OpenFlowLM (OFLM) runtime. It is **not** a GGUF file.
|
| 46 |
+
|
| 47 |
+
| Item | Value |
|
| 48 |
+
|------|-------|
|
| 49 |
+
| Source model | [`Atomic-Germ/Medgemma-4B-NPU2`](https://huggingface.co/Atomic-Germ/Medgemma-4B-NPU2) |
|
| 50 |
+
| Source GGUF | `medgemma-4b-it.i1-Q4_1.gguf` |
|
| 51 |
+
| Weights | `model.q4nx` (3.51 GB) |
|
| 52 |
+
| Modality | language |
|
| 53 |
+
| OFLM version | `0.1.0` |
|
| 54 |
+
| Converted | 2026-10-01 |
|
| 55 |
+
|
| 56 |
+
## Reproduce this conversion
|
| 57 |
+
|
| 58 |
+
This container was produced by exactly this command, so a fine-tune of the
|
| 59 |
+
same base can be packed the same way:
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
oflm pack -i /home/atomic-germ/.cache/huggingface/hub/models--mradermacher--medgemma-4b-it-i1-GGUF/snapshots/e72473b68139c8f77427dd21270eff3b2b80c1f9/medgemma-4b-it.i1-Q4_1.gguf -o /home/atomic-germ/Projects/OpenFlowLM-Next/Medgemma-4B-NPU2 -s Atomic-Germ/Medgemma-4B-NPU2
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
## Install and run
|
| 67 |
+
|
| 68 |
+
This repository works with `oflm-add`, a small installer that copies the model
|
| 69 |
+
into the OpenFlowLM user directory and registers the tag. It never
|
| 70 |
+
modifies the system OpenFlowLM install.
|
| 71 |
+
|
| 72 |
+
`pip install oflm-add` or `uv tool install oflm-add`
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
uv tool install oflm-add
|
| 76 |
+
oflm-add Atomic-Germ/Medgemma-4B-NPU2 --family qwen3.5 --xclbin-from Medgemma-4B-NPU2
|
| 77 |
+
OFLM_CONFIG_PATH="$HOME/.config/oflm/model_list.json" OFLM_XCLBIN_PATH="$HOME/.config/oflm" oflm run Medgemma-4B-NPU2
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## Files
|
| 81 |
+
|
| 82 |
+
| File | Description |
|
| 83 |
+
|------|-------------|
|
| 84 |
+
| `model.q4nx` | Quantized weights (Q8_0 / Q4_1 / BF16) |
|
| 85 |
+
| `config.json` | OFLM runtime configuration |
|
| 86 |
+
| `tokenizer.json` | Tokenizer vocabulary |
|
| 87 |
+
| `tokenizer_config.json` | Tokenizer configuration |
|
| 88 |
+
| `chat_template.jinja` | Chat template |
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## Source model card
|
| 94 |
+
|
| 95 |
+
See the original model card: [Atomic-Germ/Medgemma-4B-NPU2](https://huggingface.co/Atomic-Germ/Medgemma-4B-NPU2)
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{ bos_token }}
|
| 2 |
+
{%- if messages[0]['role'] == 'system' -%}
|
| 3 |
+
{%- if messages[0]['content'] is string -%}
|
| 4 |
+
{%- set first_user_prefix = messages[0]['content'] + '
|
| 5 |
+
|
| 6 |
+
' -%}
|
| 7 |
+
{%- else -%}
|
| 8 |
+
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
|
| 9 |
+
|
| 10 |
+
' -%}
|
| 11 |
+
{%- endif -%}
|
| 12 |
+
{%- set loop_messages = messages[1:] -%}
|
| 13 |
+
{%- else -%}
|
| 14 |
+
{%- set first_user_prefix = "" -%}
|
| 15 |
+
{%- set loop_messages = messages -%}
|
| 16 |
+
{%- endif -%}
|
| 17 |
+
{%- for message in loop_messages -%}
|
| 18 |
+
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
|
| 19 |
+
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
|
| 20 |
+
{%- endif -%}
|
| 21 |
+
{%- if (message['role'] == 'assistant') -%}
|
| 22 |
+
{%- set role = "model" -%}
|
| 23 |
+
{%- else -%}
|
| 24 |
+
{%- set role = message['role'] -%}
|
| 25 |
+
{%- endif -%}
|
| 26 |
+
{{ '<start_of_turn>' + role + '
|
| 27 |
+
' + (first_user_prefix if loop.first else "") }}
|
| 28 |
+
{%- if message['content'] is string -%}
|
| 29 |
+
{{ message['content'] | trim }}
|
| 30 |
+
{%- elif message['content'] is iterable -%}
|
| 31 |
+
{%- for item in message['content'] -%}
|
| 32 |
+
{%- if item['type'] == 'image' -%}
|
| 33 |
+
{{ '<start_of_image>' }}
|
| 34 |
+
{%- elif item['type'] == 'text' -%}
|
| 35 |
+
{{ item['text'] | trim }}
|
| 36 |
+
{%- endif -%}
|
| 37 |
+
{%- endfor -%}
|
| 38 |
+
{%- else -%}
|
| 39 |
+
{{ raise_exception("Invalid content type") }}
|
| 40 |
+
{%- endif -%}
|
| 41 |
+
{{ '<end_of_turn>
|
| 42 |
+
' }}
|
| 43 |
+
{%- endfor -%}
|
| 44 |
+
{%- if add_generation_prompt -%}
|
| 45 |
+
{{'<start_of_turn>model
|
| 46 |
+
'}}
|
| 47 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Gemma3ForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"boi_token_index": 255999,
|
| 6 |
+
"eoi_token_index": 256000,
|
| 7 |
+
"image_token_index": 262144,
|
| 8 |
+
"initializer_range": 0.02,
|
| 9 |
+
"mm_tokens_per_image": 256,
|
| 10 |
+
"model_type": "gemma3_text",
|
| 11 |
+
"torch_dtype": "bfloat16",
|
| 12 |
+
"transformers_version": "4.52.0.dev0",
|
| 13 |
+
"attention_bias": false,
|
| 14 |
+
"attention_dropout": 0.0,
|
| 15 |
+
"attn_logit_softcapping": null,
|
| 16 |
+
"cache_implementation": "hybrid",
|
| 17 |
+
"final_logit_softcapping": null,
|
| 18 |
+
"head_dim": 256,
|
| 19 |
+
"hidden_activation": "gelu_pytorch_tanh",
|
| 20 |
+
"hidden_size": 2560,
|
| 21 |
+
"intermediate_size": 10240,
|
| 22 |
+
"max_position_embeddings": 131072,
|
| 23 |
+
"num_attention_heads": 8,
|
| 24 |
+
"num_hidden_layers": 34,
|
| 25 |
+
"num_key_value_heads": 4,
|
| 26 |
+
"query_pre_attn_scalar": 256,
|
| 27 |
+
"rms_norm_eps": 1e-06,
|
| 28 |
+
"rope_local_base_freq": 10000,
|
| 29 |
+
"rope_scaling": {
|
| 30 |
+
"factor": 8.0,
|
| 31 |
+
"rope_type": "linear"
|
| 32 |
+
},
|
| 33 |
+
"rope_theta": 1000000,
|
| 34 |
+
"sliding_window": 1024,
|
| 35 |
+
"sliding_window_pattern": 6,
|
| 36 |
+
"use_cache": true,
|
| 37 |
+
"vocab_size": 262208,
|
| 38 |
+
"eos_token_id": 248044,
|
| 39 |
+
"oflm_version": "0.1.0",
|
| 40 |
+
"oflm_packed_with": "oflm pack -i /home/atomic-germ/.cache/huggingface/hub/models--mradermacher--medgemma-4b-it-i1-GGUF/snapshots/e72473b68139c8f77427dd21270eff3b2b80c1f9/medgemma-4b-it.i1-Q4_1.gguf -o /home/atomic-germ/Projects/OpenFlowLM-Next/Medgemma-4B-NPU2 -s Atomic-Germ/Medgemma-4B-NPU2"
|
| 41 |
+
}
|
model.q4nx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7ba7000665c097d859f9aa056704cda5e7a534be79812c1beb4969cd45269000
|
| 3 |
+
size 3768226744
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d4046bf0505a327dd5a0abbb427ecd4fc82f99c2ceaa170bc61ecde12809b0c
|
| 3 |
+
size 33384570
|
tokenizer_config.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
vision_weight.q4nx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:415579eff318b7113d568d43d5e921d9d74141eeacd0704dad0c66a8ecd911df
|
| 3 |
+
size 973721768
|