New AI innovations are happening almost everyday, but AI for healthcare, is still a sector rarely touched by tech innovators. However, Google has taken this initiative to revolutionize the Healthcare sector with its latest MedGemma models launched in the recent Google I/O Connect. These models stand out as modern tools for building intelligent medical applications. MedGemma is a family of models based on the powerful Gemma 3 architecture, fine-tuned to handle the intricacies of both medical text and image data. The MedGemma 4B variant is a multimodal model, combining a SigLIP image encoder, pre-trained on de-identified chest X-rays, dermatology, ophthalmology, and histopathology images, with a robust language model trained on a similarly rich set of medical data.
These models are perfect for developer aiming to build stuff like diagnostic assistant, radiology report generator, or a dermatology triage tool. MedGemma 4B offers a powerful instruction-tuned variant to get started quickly, along with a pre-trained option for deeper experimentation. Meanwhile, the MedGemma 27B model focuses purely on text-based medical reasoning, making it ideal for tasks like clinical summarization, decision support, or answering complex medical queries with precision. Optimized for inference efficiency, it provides impressive performance straight out of the box on a range of healthcare benchmarks.
If you’re a medical researcher, a healthcare AI startup, or an ML engineer looking to explore domain-specific models, MedGemma delivers a solid foundation for innovation, and this guide will show you the complete step-by-step process on how to install and run both variants locally or with GPUs in minutes.
Prerequisites
The minimum system requirements for running this model are:
- GPU: RTX4090 / RTXA6000 / A100
- Storage: 50GB (preferable)
- VRAM: 16GB (4B); 32GB (27B)
- Anaconda installed
Step-by-step process to install and run Google MedGemma 4B & 27B
For the purpose of this tutorial, we’ll use a GPU-powered Virtual Machine by NodeShift since it provides high compute Virtual Machines at a very affordable cost on a scale that meets GDPR, SOC2, and ISO27001 requirements. Also, it offers an intuitive and user-friendly interface, making it easier for beginners to get started with Cloud deployments. However, feel free to use any cloud provider of your choice and follow the same steps for the rest of the tutorial.
Step 1: Setting up a NodeShift Account
Visit app.nodeshift.com and create an account by filling in basic details, or continue signing up with your Google/GitHub account.
If you already have an account, login straight to your dashboard.
Step 2: Create a GPU Node
After accessing your account, you should see a dashboard (see image), now:
- Navigate to the menu on the left side.
- Click on the GPU Nodes option.
- Click on Start to start creating your very first GPU node.
These GPU nodes are GPU-powered virtual machines by NodeShift. These nodes are highly customizable and let you control different environmental configurations for GPUs ranging from H100s to A100s, CPUs, RAM, and storage, according to your needs.
Step 3: Selecting configuration for GPU (model, region, storage)
- For this tutorial, we’ll be using 1x RTX A6000 GPU, however, you can choose any GPU as per the prerequisites.
- Similarly, we’ll opt for 200GB storage by sliding the bar. You can also select the region where you want your GPU to reside from the available ones.
Step 4: Choose GPU Configuration and Authentication method
- After selecting your required configuration options, you’ll see the available GPU nodes in your region and according to (or very close to) your configuration. In our case, we’ll choose a 1x RTX A6000 48GB GPU node with 64vCPUs/63GB RAM/200GB SSD.
2. Next, you’ll need to select an authentication method. Two methods are available: Password and SSH Key. We recommend using SSH keys, as they are a more secure option. To create one, head over to our official documentation.
Step 5: Choose an Image
The final step is to choose an image for the VM, which in our case is Nvidia Cuda.
That’s it! You are now ready to deploy the node. Finalize the configuration summary, and if it looks good, click Create to deploy the node.
Step 6: Connect to active Compute Node using SSH
- As soon as you create the node, it will be deployed in a few seconds or a minute. Once deployed, you will see a status Running in green, meaning that our Compute node is ready to use!
- Once your GPU shows this status, navigate to the three dots on the right, click on Connect with SSH, and copy the SSH details that appear.
As you copy the details, follow the below steps to connect to the running GPU VM via SSH:
- Open your terminal, paste the SSH command, and run it.
2. In some cases, your terminal may take your consent before connecting. Enter ‘yes’.
3. A prompt will request a password. Type the SSH password, and you should be connected.
Output:
Next, If you want to check the GPU details, run the following command in the terminal:
!nvidia-smi
Step 7: Set up the project environment with dependencies
- Create a virtual environment using Anaconda.
conda create -n medgemma python=3.11 -y && conda activate medgemma
Output:
2. Once you’re inside the environment, install necessary dependencies to run the model.
pip install torch torchvision torchaudio einops timm pillow
pip install git+https://github.com/huggingface/transformers
pip install git+https://github.com/huggingface/accelerate
pip install git+https://github.com/huggingface/diffusers
pip install huggingface_hub
pip install sentencepiece bitsandbytes protobuf decord numpy
Output:
3. Install and run jupyter notebook.
conda install -c conda-forge --override-channels notebook -y
conda install -c conda-forge --override-channels ipywidgets -y
jupyter notebook --allow-root
4. Login to Huggin Face CLI.
Since, MedGemma is a gated model, you’ll need to first get access here, and then login to Hugging Face CLI with your HF access token to be able to download the model.
(Enter your HF READ
token when prompted.)
huggingface-cli login
Output:
5. If you’re on a remote machine (e.g., NodeShift GPU), you’ll need to do SSH port forwarding in order to access the jupyter notebook session on your local browser.
Run the following command in your local terminal after replacing:
<YOUR_SERVER_PORT>
with the PORT allotted to your remote server (For the NodeShift server – you can find it in the deployed GPU details on the dashboard).
<PATH_TO_SSH_KEY>
with the path to the location where your SSH key is stored.
<YOUR_SERVER_IP>
with the IP address of your remote server.
ssh -L 8888:localhost:8888 -p <YOUR_SERVER_PORT> -i <PATH_TO_SSH_KEY> root@<YOUR_SERVER_IP>
Output:
After this copy the URL you received in your remote server:
And paste this on your local browser to access the Jupyter Notebook session.
Step 8: Download and Run the model
a) MedGemma 4B Image-Text-to-Text (Multimodal)
- Open a Python notebook inside Jupyter.
2. Download model checkpoints.
from transformers import pipeline
from PIL import Image
import requests
import torch
pipe = pipeline(
"image-text-to-text",
model="google/medgemma-4b-it",
torch_dtype=torch.bfloat16,
device="cuda",
)
Output:
3. Run the model with your desired prompt and image.
from IPython.display import display, Markdown, Image as IPyImage
# Image attribution: Stillwaterising, CC0, via Wikimedia Commons
image_url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png"
image = Image.open(requests.get(image_url, headers={"User-Agent": "example"}, stream=True).raw)
prompt = "Describe this X-ray"
messages = [
{
"role": "system",
"content": [{"type": "text", "text": "You are an expert radiologist."}]
},
{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{"type": "image", "image": image},
]
}
]
output = pipe(text=messages, max_new_tokens=200)
response = output[0]["generated_text"][-1]["content"]
display(IPyImage(url=image_url))
display(Markdown(f"### Prompt:\n> {prompt}"))
display(Markdown(f"### Radiologist's Description:\n{response}"))
Prompt: “Describe this X-ray”
Here’s the input image:
Output:
b) MedGemma 27B Text-Instruction-Tuned (Text-only)
- Open a new Python notebook inside Jupyter.
2. Download and run the model directly.
Here we use Hugging Face’s chat-style templating (apply_chat_template
) to structure the prompt and run inference directly on the loaded MedGemma model checkpoints.
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "google/medgemma-27b-text-it"
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{
"role": "system",
"content": "You are a helpful medical assistant."
},
{
"role": "user",
"content": "How do you differentiate bacterial from viral pneumonia?"
}
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
input_len = inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**inputs, max_new_tokens=200, do_sample=False)
generation = generation[0][input_len:]
decoded = tokenizer.decode(generation, skip_special_tokens=True)
print(decoded)
Output:
You can increase/decrease max_new_tokens
as desired to change the length of the responses.
Conclusion
In this guide, we walked through everything you need to know to install and run Google’s powerful MedGemma models, both the multimodal 4B and the text-only 27B, on your local/GPU setup. From understanding their architecture to exploring their real-world healthcare applications, it’s clear these models open the door to building innovative AI-driven medical tools. But performance and accessibility matter just as much as capability, especially in the sensitive industries like Healthcare. That’s where NodeShift comes as a helping hand. With seamless GPU access, pre-configured environments, and super fast setup, NodeShift removes the typical infrastructure hurdles, making it effortless for developers and researchers to deploy heavy duty models like MedGemma in production or experimentation environments. If you’re testing on-prem or scaling in the cloud, NodeShift ensures you’re up and running in minutes.