Instructions to use jjsprockel/medgemma27b-luad-qlora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jjsprockel/medgemma27b-luad-qlora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="jjsprockel/medgemma27b-luad-qlora") 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 AutoModel model = AutoModel.from_pretrained("jjsprockel/medgemma27b-luad-qlora", dtype="auto") - PEFT
How to use jjsprockel/medgemma27b-luad-qlora with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use jjsprockel/medgemma27b-luad-qlora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jjsprockel/medgemma27b-luad-qlora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jjsprockel/medgemma27b-luad-qlora", "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/jjsprockel/medgemma27b-luad-qlora
- SGLang
How to use jjsprockel/medgemma27b-luad-qlora 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 "jjsprockel/medgemma27b-luad-qlora" \ --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": "jjsprockel/medgemma27b-luad-qlora", "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 "jjsprockel/medgemma27b-luad-qlora" \ --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": "jjsprockel/medgemma27b-luad-qlora", "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 jjsprockel/medgemma27b-luad-qlora with Docker Model Runner:
docker model run hf.co/jjsprockel/medgemma27b-luad-qlora
medgemma27b-luad-qlora
LoRA adapters (QLoRA, 4-bit) para la identificaci贸n autom谩tica de subtipos de adenocarcinoma de pulm贸n, entrenados sobre el modelo base google/medgemma-27b-it.
馃攷 Descripci贸n
Este repositorio contiene los adapters LoRA obtenidos mediante ajuste fino (QLoRA) con una base de datos de 1194 casos de adenocarcinoma de pulm贸n anotados y distribuidos en los subtipos reconocidos por la Clasificaci贸n de la OMS 2021:contentReference[oaicite:0]{index=0}:
- Lepidic
- Acinar
- Papillary
- Micropapillary
- Solid
- Invasive mucinous
- Colloid
- Fetal
- Enteric
La anotaci贸n y validaci贸n de los casos se realiz贸 siguiendo criterios histol贸gicos y citol贸gicos descritos en la literatura:contentReference[oaicite:1]{index=1}, excluyendo im谩genes con artefactos o sin subtipo identificable.
鈿欙笍 Uso
Ejemplo m铆nimo para cargar los adapters y realizar inferencia:
from transformers import AutoModelForImageTextToText, AutoProcessor, BitsAndBytesConfig
from peft import PeftModel
import torch
from PIL import Image
base_id = "google/medgemma-27b-it"
adapter_id = "jjsprockel/medgemma27b-luad-qlora"
bnb_cfg = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
base = AutoModelForImageTextToText.from_pretrained(
base_id,
quantization_config=bnb_cfg,
device_map={"": "cuda"},
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True
)
model = PeftModel.from_pretrained(base, adapter_id).eval()
processor = AutoProcessor.from_pretrained(base_id)
# Ejemplo de inferencia
img = Image.open("example.png").convert("RGB")
subtypes = ["lepidic","acinar","papillary","micropapillary","solid","invasive mucinous","colloid","fetal","enteric"]
system = "You are an expert pulmonary pathologist. Return ONLY JSON with key 'subtype' strictly from: " + ", ".join(subtypes) + "."
user = "Predict the subtype for this H&E lung adenocarcinoma patch. Only JSON."
messages = [
{"role":"system","content":[{"type":"text","text":system}]},
{"role":"user","content":[{"type":"text","text":user},{"type":"image","image":img}]}
]
templ = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
enc = processor(text=templ, images=img, return_tensors="pt")
inputs = {
"input_ids": enc["input_ids"].to(model.device),
"attention_mask": enc["attention_mask"].to(model.device),
"pixel_values": enc["pixel_values"].to(model.device, dtype=torch.bfloat16),
}
with torch.inference_mode(), torch.amp.autocast("cuda", dtype=torch.bfloat16):
out = model.generate(**inputs, max_new_tokens=32, do_sample=False)[0]
gen = out[inputs["input_ids"].shape[-1]:]
decoded = processor.decode(gen, skip_special_tokens=True)
print(decoded)
## Inference notebook
[馃И Open the inference notebook](https://huggingface.co/jjsprockel/medgemma27b-luad-qlora/resolve/main/notebooks/MedGemma27B_LUAD_inference.ipynb)
This notebook runs MedGemma-27B (base + QLoRA adapters) to classify LUAD subtypes on H&E patches
using the JSON-constrained output described in the paper.