Instructions to use netdur/gemma-3-4b-radiology with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use netdur/gemma-3-4b-radiology with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="netdur/gemma-3-4b-radiology") 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("netdur/gemma-3-4b-radiology") model = AutoModelForMultimodalLM.from_pretrained("netdur/gemma-3-4b-radiology") 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]:])) - llama-cpp-python
How to use netdur/gemma-3-4b-radiology with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="netdur/gemma-3-4b-radiology", filename="mmproj.gguf", )
llm.create_chat_completion( 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" } } ] } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use netdur/gemma-3-4b-radiology with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf netdur/gemma-3-4b-radiology:Q4_K_M # Run inference directly in the terminal: llama cli -hf netdur/gemma-3-4b-radiology:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf netdur/gemma-3-4b-radiology:Q4_K_M # Run inference directly in the terminal: llama cli -hf netdur/gemma-3-4b-radiology:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf netdur/gemma-3-4b-radiology:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf netdur/gemma-3-4b-radiology:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf netdur/gemma-3-4b-radiology:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf netdur/gemma-3-4b-radiology:Q4_K_M
Use Docker
docker model run hf.co/netdur/gemma-3-4b-radiology:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use netdur/gemma-3-4b-radiology with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "netdur/gemma-3-4b-radiology" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "netdur/gemma-3-4b-radiology", "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/netdur/gemma-3-4b-radiology:Q4_K_M
- SGLang
How to use netdur/gemma-3-4b-radiology 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 "netdur/gemma-3-4b-radiology" \ --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": "netdur/gemma-3-4b-radiology", "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 "netdur/gemma-3-4b-radiology" \ --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": "netdur/gemma-3-4b-radiology", "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" } } ] } ] }' - Ollama
How to use netdur/gemma-3-4b-radiology with Ollama:
ollama run hf.co/netdur/gemma-3-4b-radiology:Q4_K_M
- Unsloth Studio
How to use netdur/gemma-3-4b-radiology with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for netdur/gemma-3-4b-radiology to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for netdur/gemma-3-4b-radiology to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for netdur/gemma-3-4b-radiology to start chatting
- Atomic Chat new
- Docker Model Runner
How to use netdur/gemma-3-4b-radiology with Docker Model Runner:
docker model run hf.co/netdur/gemma-3-4b-radiology:Q4_K_M
- Lemonade
How to use netdur/gemma-3-4b-radiology with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull netdur/gemma-3-4b-radiology:Q4_K_M
Run and chat with the model
lemonade run user.gemma-3-4b-radiology-Q4_K_M
List all available models
lemonade list
Uploaded finetuned model
This repository contains a Gemma 3 4B model fine-tuned to generate radiology reports from ultrasound images. It was trained using the Unsloth library and is provided here in GGUF format for use with llama.cpp.
This model card demonstrates a complete, end-to-end example of running inference using llama.cpp and the llama_cpp_dart package.
- Base Model: unsloth/gemma-3-4b-it-unsloth-bnb-4bit
- Fine-tuning Data: unsloth/Radiology_mini
Example Usage
This example uses the llama_cpp_dart package to run the model on a macOS machine with Metal GPU acceleration.
1. Input Image
The following ultrasound image (radiology.png) was used as input.
2. Dart Inference Code
The model was called using the code below. Note the use of ChatFormat.gemma, which correctly applies the <bos><start_of_turn>user... template required by the model.
import 'dart:io';
import 'package:llama_cpp_dart/llama_cpp_dart.dart';
Future<void> main() async {
Llama.libraryPath = "bin/MAC_ARM64/libmtmd.dylib";
final modelParams = ModelParams()..nGpuLayers = -1;
final contextParams = ContextParams()
..nPredict = 512
..nCtx = 8192
..nBatch = 8192;
final samplerParams = SamplerParams()
..temp = 0.0
..topK = 64
..topP = 0.95
..penaltyRepeat = 1.1
..addStopSequence("<end_of_turn>");
final llama = Llama(
"./model-radiology-Q4_K_M.gguf",
modelParams,
contextParams,
samplerParams,
false,
"./mmproj-radiology.gguf");
final image =
LlamaImage.fromFile(File("./radiology.png"));
final chat = ChatHistory();
chat.addMessage(role: Role.user, content: """<image>
You are an expert radiographer. Describe accurately what you see in this image.""");
// Use the correct chat format that matches the fine-tuning process
final prompt =
chat.exportFormat(ChatFormat.gemma, leaveLastAssistantOpen: true);
print("==== PROMPT SENT TO MODEL ====");
print(prompt);
print("==============================");
final sw = Stopwatch()..start();
try {
final stream = llama.generateWithMeda(prompt, inputs: [image]);
await for (final token in stream) {
stdout.write(token);
}
await stdout.flush();
stdout.writeln();
} on LlamaException catch (e) {
stderr.writeln("An error occurred: $e");
} finally {
sw.stop();
stdout.writeln('⏱️ Inference time: ${sw.elapsed}');
llama.dispose();
}
}
Outputs
- Image Type: Transvaginal ultrasound
- Date: 10-05-2012
- Measurement: 40mm
- Findings:
- A large, heterogeneous, cystic mass is seen in the right adnexa.
- The mass appears to be connected to the ovary.
- The mass is 40mm in diameter.
- The right ovary is 62.7 mm in diameter.
- The left ovary is 125/255 mm in diameter.
- The uterus is 3D5-8EK.
- The uterine body is 11:36:15.
- The uterine tube is 0.2.
- Downloads last month
- 41
Model tree for netdur/gemma-3-4b-radiology
Base model
google/gemma-3-4b-pt