Instructions to use google/gemma-2-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-2-2b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-2-2b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b") model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/gemma-2-2b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-2-2b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-2-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/gemma-2-2b
- SGLang
How to use google/gemma-2-2b 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 "google/gemma-2-2b" \ --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": "google/gemma-2-2b", "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 "google/gemma-2-2b" \ --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": "google/gemma-2-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/gemma-2-2b with Docker Model Runner:
docker model run hf.co/google/gemma-2-2b
Gemma2-2b training uses much more momory!
I have been training gemma2-2b into VLM on 8 80G H800 with max batch size 4 by pytorch FSDP.And I think the batch size is strange because training llama2 into VLM with the same FSDP settings has batch size 32. So I wonder if there are some kernels or computation that are very memory consuming in he code of transformers model gemma2.
I have been training gemma2-2b into VLM
It is very interesting. I wonder how it works.
I think the batch size is strange because training llama2 into VLM with the same FSDP settings has batch size 32.
IIRC, FSDP doesn't support soft capping in Gemma2. You may need to use alternative settings.
Hi @bubbleseller , You are observing that LLaMA-2 can handle a batch size of 32, while Gemma2-2B is constrained to a batch size of 4, even though you are using the same FSDP settings. Could you please use PyTorch's torch.profiler and memory tools to inspect exactly where the memory bottleneck is. I think this will help identify if certain layers or computations are consuming an unusual amount of memory. Kindly try and let me know Thank you.