Text Generation
Transformers
Safetensors
English
medical
anatomy
clinical-reasoning
optimized
8-bit precision
Instructions to use krishna195/medgemma-anatomy-v2.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use krishna195/medgemma-anatomy-v2.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="krishna195/medgemma-anatomy-v2.1")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("krishna195/medgemma-anatomy-v2.1", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use krishna195/medgemma-anatomy-v2.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "krishna195/medgemma-anatomy-v2.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krishna195/medgemma-anatomy-v2.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/krishna195/medgemma-anatomy-v2.1
- SGLang
How to use krishna195/medgemma-anatomy-v2.1 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 "krishna195/medgemma-anatomy-v2.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krishna195/medgemma-anatomy-v2.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "krishna195/medgemma-anatomy-v2.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krishna195/medgemma-anatomy-v2.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use krishna195/medgemma-anatomy-v2.1 with Docker Model Runner:
docker model run hf.co/krishna195/medgemma-anatomy-v2.1
MedGemma-4B Anatomy v2.1 (Optimized)
Improved version with better generalization - fixes overfitting from v2.0.
Key Improvements
- ✅ Reduced epochs: 6 → 3 (prevents overfitting)
- ✅ Early stopping: Stops when validation loss plateaus
- ✅ Stronger regularization: Increased dropout and weight decay
- ✅ Better convergence: Higher learning rate with more warmup
Model Details
- Base Model: google/medgemma-4b-it (4B parameters)
- Training Data: 895 anatomy Q&A pairs
- Method: LoRA (r=32, α=64, dropout=0.1)
- Epochs: 3 (with early stopping)
- Training Time: ~0.2 hours
- Hardware: A100 40GB GPU
- Final Train Loss: 1.3326
- Best Val Loss: 1.2016
Training Configuration
CONFIG = {
'max_seq_length': 1024,
'num_epochs': 3,
'batch_size': 4 (effective 16),
'learning_rate': 0.0001,
'lora_r': 32,
'lora_alpha': 64,
'lora_dropout': 0.1,
'weight_decay': 0.03,
'early_stopping_patience': 5
}
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "krishna195/medgemma-anatomy-v2.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
question = "What is the carpal tunnel?"
prompt = f"<start_of_turn>user\n{question}<end_of_turn>\n<start_of_turn>model\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
License
Apache 2.0
- Downloads last month
- 3