> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/models/medgemma-2.md). Agents can also search and read this documentation through its [MCP server](https://unsloth.ai/docs/~gitbook/mcp).

# MedGemma 2 - Run Locally Guide

Learn how to run Google's MedGemma 2 E4B and 26B-A4B medical models locally with Unsloth and llama.cpp.

**MedGemma 2** is Google's family of **medical models built on Gemma 4**. It comes in two variants: **E4B** (dense; accepts **text, images, and audio**) and **26B-A4B** (mixture of experts with about **4B active** parameters; accepts **text and images**). Both support thinking and non-thinking modes.

{% columns %}
{% column %}
This guide covers running MedGemma 2 locally with our Unsloth Dynamic GGUFs in Unsloth Desktop or llama.cpp.

GGUFs: [**MedGemma 2 E4B**](https://huggingface.co/unsloth/medgemma-2-E4B-it-GGUF) and [**MedGemma 2 26B-A4B**](https://huggingface.co/unsloth/medgemma-2-26B-A4B-it-GGUF)

<a href="https://unsloth.ai/docs/models/medgemma-2.md#run-medgemma-2-in-unsloth-desktop" class="button primary">Run MedGemma 2</a><a href="https://unsloth.ai/download" class="button secondary">Download Unsloth</a>
{% endcolumn %}

{% column %}

<figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FdIvTA5q9SozpgiE3UMOu%2Fmedgemma-2-studio-xray.png?alt=media" alt="MedGemma 2 26B-A4B describing a chest X-ray in Unsloth" width="563"><figcaption><p>4-bit MedGemma 2 26B-A4B running in Unsloth</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% hint style="warning" %}
**Not for clinical use.** Outputs must be verified by qualified professionals. Use is subject to the [Health AI Developer Foundations terms of use](https://developers.google.com/health-ai-developer-foundations/terms).
{% endhint %}

### ⚙️ Usage Guide

#### MedGemma 2 Requirements

The recommended quant is **`UD-Q4_K_XL`**: **5.1 GB** for E4B and **17.0 GB** for 26B-A4B.

**Approximate GGUF download sizes** (model weights only)

| Model   | 2-bit    | 3-bit    | 4-bit | 8-bit | BF16  |
| ------- | -------- | -------- | ----- | ----- | ----- |
| E4B     | 3.5-4 GB | 4-5 GB   | 5 GB  | 9 GB  | 15 GB |
| 26B-A4B | 10-11 GB | 11-13 GB | 17 GB | 28 GB | 51 GB |

{% hint style="success" %}
Download sizes are not memory requirements. Allow extra RAM and VRAM (or unified memory) for the context, runtime, and multimodal projector. The F16 projector adds about 1.0 GB for E4B or 1.2 GB for 26B-A4B.
{% endhint %}

#### Recommended Settings

| Temperature | Top-p  | Top-k | Min-p |
| ----------- | ------ | ----- | ----- |
| `1.0`       | `0.95` | `64`  | `0.0` |

* Thinking is **on** by default. Turn it off for short answers, reports and JSON output.
* Use **one image per request** for the most reliable results.

### 🦥 Run MedGemma 2 in Unsloth Desktop <a href="#run-medgemma-2-in-unsloth-desktop" id="run-medgemma-2-in-unsloth-desktop"></a>

{% stepper %}
{% step %}

#### Install Unsloth

Download and launch the [Unsloth Desktop app](https://unsloth.ai/docs/desktop.md) for macOS, Windows or Linux.

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">Download Unsloth</a>

* <i class="fa-apple">:apple:</i> [Download for macOS](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [Download for Windows](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [Download for Linux](https://unsloth.ai/download/linux)

Or, if you prefer to install manually:

{% tabs %}
{% tab title="Native install" %}
**MacOS, Linux, WSL:**

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

**Windows:**

```powershell
irm https://unsloth.ai/install.ps1 | iex
```

{% endtab %}

{% tab title="Docker" %}
The [Unsloth Docker image](https://hub.docker.com/r/unsloth/unsloth) `unsloth/unsloth` is available on Docker. [Read guide.](https://unsloth.ai/docs/get-started/install/docker)
{% endtab %}

{% tab title="Homebrew" %}
Install Unsloth Desktop:

{% code collapsedlinecount="10" %}

```bash
brew install --cask unsloth
```

{% endcode %}

Update Unsloth Desktop:

```bash
brew upgrade --cask unsloth
```

{% endtab %}

{% tab title="WinGet" %}
Install Unsloth Desktop:

```powershell
winget install --id UnslothAI.Unsloth -e
```

Update Unsloth Desktop:

```powershell
winget upgrade --id UnslothAI.Unsloth -e
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### Search and download MedGemma 2

In **Chat**, open **Select model**, or go to **Model hub**. Search for **MedGemma 2** and download `unsloth/medgemma-2-26B-A4B-it-GGUF` or `unsloth/medgemma-2-E4B-it-GGUF` with the `UD-Q4_K_XL` quant. Unsloth also downloads the vision projector for image input.

Click the model name in the chat box to toggle **Thinking** on or off. To attach an image, click **+** and choose **Add photos & files**.

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FdcsdblPB8B7s5FtrcnYg%2Fmedgemma-2-studio-select-model.png?alt=media" alt="Unsloth model picker showing the MedGemma 2 26B-A4B and E4B GGUFs with the UD-Q4_K_XL quant" width="563"><figcaption><p>Both MedGemma 2 models (UD-Q4_K_XL) in the model picker</p></figcaption></figure></div>
{% endstep %}

{% step %}

#### Run and serve MedGemma 2 with the Unsloth API

This example uses the 4-bit `UD-Q4_K_XL` quant (17.0 GB). Change the suffix after the colon to select another quant.

{% code overflow="wrap" %}

```bash
unsloth run --model unsloth/medgemma-2-26B-A4B-it-GGUF:UD-Q4_K_XL \
    --temp 1.0 --top-p 0.95 --top-k 64 --min-p 0.0
```

{% endcode %}

Use the endpoint URL and API key printed in the terminal to connect your client. [Unsloth API guide](https://unsloth.ai/docs/basics/api.md)
{% endstep %}
{% endstepper %}

### 🦙 Run MedGemma 2 in llama.cpp <a href="#run-medgemma-2-in-llama-cpp" id="run-medgemma-2-in-llama-cpp"></a>

{% stepper %}
{% step %}

#### Install llama.cpp

The commands below build [llama.cpp](https://github.com/ggml-org/llama.cpp) on Ubuntu or Debian with NVIDIA CUDA. Install the CUDA toolkit first. For CPU-only builds, use `-DGGML_CUDA=OFF`. On macOS, skip the `apt-get` commands and follow the [llama.cpp build guide](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md). Metal is enabled by default on macOS.

{% code overflow="wrap" %}

```bash
sudo apt-get update
sudo apt-get install -y pciutils build-essential cmake curl libcurl4-openssl-dev
git clone https://github.com/ggml-org/llama.cpp
cmake -S llama.cpp -B llama.cpp/build \
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endcode %}
{% endstep %}

{% step %}

#### Run MedGemma 2

Chat with E4B in the terminal. `-hf` downloads the GGUF and can load the matching multimodal projector when it is available.

```bash
./llama.cpp/llama-cli \
    -hf unsloth/medgemma-2-E4B-it-GGUF:UD-Q4_K_XL \
    --jinja --chat-template-kwargs '{"enable_thinking":false}' \
    --temp 1.0 --top-p 0.95 --top-k 64
```

Serve 26B-A4B with image input on `http://localhost:8001/v1/chat/completions`. Keep **`-b 2048 -ub 2048`** for this 26B-A4B image example. Smaller batches can limit how many image tokens llama.cpp processes.

```bash
./llama.cpp/llama-server \
    -hf unsloth/medgemma-2-26B-A4B-it-GGUF:UD-Q4_K_XL \
    -b 2048 -ub 2048 \
    --jinja --chat-template-kwargs '{"enable_thinking":false}' \
    --temp 1.0 --top-p 0.95 --top-k 64 \
    --port 8001
```

* Remove `--chat-template-kwargs '{"enable_thinking":false}'` to keep thinking on. On `llama-server` you can also set `"chat_template_kwargs": {"enable_thinking": true}` per request. `--reasoning-budget 0` does **not** turn thinking off.
* **E4B audio:** use `llama-mtmd-cli -m <model.gguf> --mmproj <projector.gguf> --jinja --audio clip.wav -p "Transcribe this clip."` with the matching local E4B model and projector files. 26B-A4B does not accept audio.
* To download manually: `hf download unsloth/medgemma-2-26B-A4B-it-GGUF --local-dir unsloth/medgemma-2-26B-A4B-it-GGUF --include "*mmproj-F16*" --include "*UD-Q4_K_XL*"`
  {% endstep %}
  {% endstepper %}

### Usage Examples

All examples ran in Unsloth with `UD-Q4_K_XL`, thinking off and the recommended settings. Inputs are synthetic or public-domain examples. The screenshots show model outputs, not clinical validation.

#### Medical question answering

**E4B**, system prompt `You are a helpful medical assistant.`, prompt `How do you differentiate bacterial from viral pneumonia?`

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FzKq4IeW3mKNEX1SSSXAZ%2Fmedgemma-2-studio-qa.png?alt=media" alt="Unsloth chat with MedGemma 2 E4B answering how to differentiate bacterial from viral pneumonia"><figcaption><p>MedGemma 2 E4B in Unsloth</p></figcaption></figure></div>

{% hint style="warning" %}
The example overstates what worsening on antibiotics can tell you. A response to treatment does not by itself distinguish bacterial from viral pneumonia. See the [IDSA clinical pathway](https://www.idsociety.org/globalassets/idsa/practice-guidelines/community-acquired-pneumonia-in-adults/cap-clinical-pathway-final-online.pdf#page=6). Always review model outputs.
{% endhint %}

#### Chest X-ray description

**26B-A4B**, system prompt `You are an expert radiologist.`, prompt `Describe this X-ray. Use the sections Findings and Impression.`

{% columns %}
{% column width="40%" %}

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FsAb2ksBAKqZCtkJQGf4U%2Fmedgemma-2-chest-xray-example.jpg?alt=media" alt="Frontal (PA) chest X-ray used as the example input"><figcaption><p>Input: <a href="https://commons.wikimedia.org/wiki/File:Chest_Xray_PA_3-8-2010.png">Chest X-ray PA</a> by Stillwaterising, CC0</p></figcaption></figure></div>
{% endcolumn %}

{% column width="60%" %}

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FdIvTA5q9SozpgiE3UMOu%2Fmedgemma-2-studio-xray.png?alt=media" alt="Unsloth chat with MedGemma 2 26B-A4B describing a chest X-ray with Findings and Impression"><figcaption><p>Model output: the X-ray was described as normal</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

#### Skin lesion description

**26B-A4B**, system prompt `You are an expert dermatologist.`, prompt `Describe this skin lesion and list the main differential diagnoses.` This example uses a skin photograph.

{% columns %}
{% column width="40%" %}

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FkhzpUv1zaFob6kCI02DE%2Fmedgemma-2-skin-lesion-example.jpg?alt=media" alt="Close-up photo of a pigmented skin lesion used as the example input"><figcaption><p>Input: <a href="https://commons.wikimedia.org/wiki/File:Melanoma.jpg">Melanoma</a>, National Cancer Institute, public domain</p></figcaption></figure></div>
{% endcolumn %}

{% column width="60%" %}

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpYmTN3gyoPErP22EN9JH%2Fmedgemma-2-studio-skin.png?alt=media" alt="Unsloth chat with MedGemma 2 26B-A4B describing a pigmented skin lesion and listing differential diagnoses"><figcaption><p>The model listed melanoma first, matching the source image label</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

#### Patient-friendly explanation

**26B-A4B**, system prompt `You explain medical reports to patients in plain language at a sixth-grade reading level. Do not add findings that are not in the report. End by suggesting questions to ask their doctor.`

Prompt: `Explain this report: FINDINGS: Patchy opacity in the right lower lobe. No pleural effusion. Heart size normal. IMPRESSION: Right lower lobe opacity, may represent pneumonia in the appropriate clinical setting.`

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fj2GcFPXCcyQHvlQR0Nev%2Fmedgemma-2-studio-patient.png?alt=media" alt="Unsloth chat with MedGemma 2 26B-A4B explaining a chest X-ray report in plain language"><figcaption><p>MedGemma 2 26B-A4B in Unsloth</p></figcaption></figure></div>

#### Structured extraction from a clinical note

**26B-A4B**, thinking off, system prompt `You extract structured data from clinical notes. Only use information stated in the note. Reply with only a JSON object with the keys age, sex, conditions, symptoms, medications (name, dose, frequency), allergies and plan.`

Prompt: `Synthetic note: 58-year-old man with type 2 diabetes and hypertension presents with 3 days of productive cough and fever of 38.6 °C. Takes metformin 1000 mg twice daily and lisinopril 10 mg daily. Allergic to penicillin. Plan: chest X-ray, CBC, follow-up in 48 hours.`

<div data-with-frame="true"><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FF69FNoBZKUvWqgAUAQur%2Fmedgemma-2-studio-json.png?alt=media" alt="Unsloth chat with MedGemma 2 26B-A4B returning a JSON object extracted from a clinical note"><figcaption><p>Valid JSON output</p></figcaption></figure></div>

To constrain output to a JSON schema, serve with `llama-server` and pass a schema in [`response_format`](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md). Validate the returned data in your application.

### Quantization Analysis

These tables compare the listed quants with each model’s BF16 reference using KL divergence (KLD), measured on assistant tokens across five domains. Lower KLD means closer to the reference model’s token probabilities. It does not measure clinical accuracy.

{% tabs %}
{% tab title="E4B" %}

| Quant        | Size (GB) | General chat | Medical | Multilingual | Code / reasoning | Agent / tool use |    Mean |
| ------------ | --------: | -----------: | ------: | -----------: | ---------------: | ---------------: | ------: |
| UD-IQ2\_M    |      3.55 |      0.02196 | 0.03052 |      0.02442 |          0.00669 |          0.01175 | 0.01907 |
| UD-Q2\_K\_XL |      3.72 |      0.01671 | 0.02502 |      0.01936 |          0.00481 |          0.00894 | 0.01497 |
| UD-IQ3\_XXS  |      3.76 |      0.01609 | 0.02408 |      0.01829 |          0.00443 |          0.00881 | 0.01434 |
| UD-Q3\_K\_XL |      4.59 |      0.00539 | 0.00791 |      0.00636 |          0.00165 |          0.00351 | 0.00497 |
| UD-Q4\_K\_XL |      5.13 |      0.00240 | 0.00324 |      0.00292 |          0.00063 |          0.00128 | 0.00209 |
| UD-Q5\_K\_XL |      6.66 |      0.00062 | 0.00083 |      0.00078 |          0.00016 |          0.00036 | 0.00055 |
| UD-Q6\_K\_XL |      7.42 |      0.00042 | 0.00050 |      0.00047 |          0.00011 |          0.00025 | 0.00035 |
| UD-Q8\_K\_XL |      8.71 |      0.00038 | 0.00044 |      0.00043 |          0.00010 |          0.00024 | 0.00032 |

<div><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F3C0ZH9Z5qGj8G77crsGM%2Fmedgemma-2-e4b-kld-general.png?alt=media" alt="MedGemma 2 E4B GGUF General chat KLD vs file size"><figcaption><p>General chat</p></figcaption></figure> <figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FCa3tJSDLXQxO9uHubfgs%2Fmedgemma-2-e4b-kld-medical.png?alt=media" alt="MedGemma 2 E4B GGUF Medical KLD vs file size"><figcaption><p>Medical</p></figcaption></figure></div>

<div><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FKy5yahD7A2P4rdWjx8yp%2Fmedgemma-2-e4b-kld-multilingual.png?alt=media" alt="MedGemma 2 E4B GGUF Multilingual KLD vs file size"><figcaption><p>Multilingual</p></figcaption></figure> <figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F2IpHBBxiVQv5ltDqvoZB%2Fmedgemma-2-e4b-kld-code.png?alt=media" alt="MedGemma 2 E4B GGUF Code / reasoning KLD vs file size"><figcaption><p>Code / reasoning</p></figcaption></figure></div>

<figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FkJthQYc8EspQSYGBffit%2Fmedgemma-2-e4b-kld-agent.png?alt=media" alt="MedGemma 2 E4B GGUF Agent / tool use KLD vs file size"><figcaption><p>Agent / tool use</p></figcaption></figure>
{% endtab %}

{% tab title="26B-A4B" %}

| Quant        | Size (GB) | General chat | Medical | Multilingual | Code / reasoning | Agent / tool use |    Mean |
| ------------ | --------: | -----------: | ------: | -----------: | ---------------: | ---------------: | ------: |
| UD-IQ2\_XXS  |      9.92 |      0.07362 | 0.14824 |      0.08388 |          0.01559 |          0.04808 | 0.07388 |
| UD-IQ2\_M    |     10.01 |      0.07024 | 0.14086 |      0.07996 |          0.01488 |          0.04503 | 0.07019 |
| UD-Q2\_K\_XL |     10.55 |      0.04957 | 0.09676 |      0.05725 |          0.01129 |          0.03401 | 0.04978 |
| UD-IQ3\_XXS  |     11.29 |      0.03249 | 0.06685 |      0.03675 |          0.00760 |          0.02310 | 0.03336 |
| UD-IQ3\_S    |     11.42 |      0.03047 | 0.06365 |      0.03462 |          0.00690 |          0.02094 | 0.03132 |
| UD-Q3\_K\_M  |     12.73 |      0.01547 | 0.03520 |      0.01856 |          0.00347 |          0.01123 | 0.01679 |
| UD-Q3\_K\_XL |     12.91 |      0.01481 | 0.03437 |      0.01742 |          0.00347 |          0.01110 | 0.01623 |
| UD-Q4\_K\_XL |     17.01 |      0.00511 | 0.01190 |      0.00554 |          0.00111 |          0.00420 | 0.00557 |
| UD-Q5\_K\_XL |     21.22 |      0.00276 | 0.00605 |      0.00296 |          0.00052 |          0.00232 | 0.00292 |
| UD-Q6\_K\_XL |     23.30 |      0.00210 | 0.00510 |      0.00235 |          0.00038 |          0.00192 | 0.00237 |
| UD-Q8\_K\_XL |     27.64 |      0.00212 | 0.00510 |      0.00232 |          0.00036 |          0.00200 | 0.00238 |

<div><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FHXDPYSQ0MTwdYrXTXAQb%2Fmedgemma-2-26b-kld-general.png?alt=media" alt="MedGemma 2 26B-A4B GGUF General chat KLD vs file size"><figcaption><p>General chat</p></figcaption></figure> <figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F3PjAya1RwqbWx6ouiaB0%2Fmedgemma-2-26b-kld-medical.png?alt=media" alt="MedGemma 2 26B-A4B GGUF Medical KLD vs file size"><figcaption><p>Medical</p></figcaption></figure></div>

<div><figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FI53t35EeubN4BZT5wEVK%2Fmedgemma-2-26b-kld-multilingual.png?alt=media" alt="MedGemma 2 26B-A4B GGUF Multilingual KLD vs file size"><figcaption><p>Multilingual</p></figcaption></figure> <figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FMp9sUCVg3GgTXQfJuSMs%2Fmedgemma-2-26b-kld-code.png?alt=media" alt="MedGemma 2 26B-A4B GGUF Code / reasoning KLD vs file size"><figcaption><p>Code / reasoning</p></figcaption></figure></div>

<figure><img src="https://3215535692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpuPIkZXfSvyCMY8XMUQs%2Fmedgemma-2-26b-kld-agent.png?alt=media" alt="MedGemma 2 26B-A4B GGUF Agent / tool use KLD vs file size"><figcaption><p>Agent / tool use</p></figcaption></figure>
{% endtab %}
{% endtabs %}

## 🧬 Fine-tune MedGemma 2

Use the [Gemma 4 Fine-tuning Guide](https://unsloth.ai/docs/models/gemma-4/train) for the Unsloth setup and notebooks. Treat the Gemma 4 recipes as starting points and verify MedGemma 2 compatibility for your checkpoint and input type. Set `model_name` to the instruction-tuned MedGemma 2 **Transformers checkpoint** for your variant. Find it under **Base model** on the [E4B GGUF card](https://huggingface.co/unsloth/medgemma-2-E4B-it-GGUF) or [26B-A4B GGUF card](https://huggingface.co/unsloth/medgemma-2-26B-A4B-it-GGUF).

* **E4B:** Pick the text, vision or audio recipe that matches your dataset. Use the [multimodal LoRA example](https://unsloth.ai/docs/models/gemma-4/train#gemma-4-multimodal-lora-example) for image and text pairs, or follow the [audio example format](https://unsloth.ai/docs/models/gemma-4/train#audio-example-format) for audio inputs.
* **26B-A4B:** Follow the [MoE fine-tuning recipe](https://unsloth.ai/docs/models/gemma-4/train#moe-fine-tuning-26b-a4b). Start with **BF16 LoRA** and a short context if memory allows. Use the same [image example format](https://unsloth.ai/docs/models/gemma-4/train#image-example-format) for image and text pairs.

Keep the checkpoint’s chat template and format your training data as `messages` with user inputs and target assistant responses. After training, save your LoRA adapter and follow the [export guide](https://unsloth.ai/docs/models/gemma-4/train#saving-export-fine-tuned-model) to deploy it locally.

##### License

MedGemma 2 is distributed under the [Health AI Developer Foundations terms of use](https://developers.google.com/health-ai-developer-foundations/terms). By downloading or using the files you agree to those terms.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/models/medgemma-2.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
