Instructions to use google/gemma-2-27b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-2-27b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-2-27b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-27b") model = AutoModelForCausalLM.from_pretrained("google/gemma-2-27b") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/gemma-2-27b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-2-27b" # 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-27b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/google/gemma-2-27b
- SGLang
How to use google/gemma-2-27b 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-27b" \ --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-27b", "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-27b" \ --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-27b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use google/gemma-2-27b with Docker Model Runner:
docker model run hf.co/google/gemma-2-27b
The base model doesn't generate coherently
I'm having major issues with fine-tuning this model. Is the base model bricked?
Hey @migtissera , could you try with the latest transformers release (v4.42.3) and let us know if it fixes your problem? We have validated the model seems to fine-tune correctly in this version.
We also recommend using attn_implementation='eager' in the configuration to use the eager attention instead of Flash Attention to improve the results.
I've noticed the same issue with transformers 4.44.0. Generating using vLLM 0.5.4 for google/gemma-2-9b is fine, but google/gemma-2-27b generates text similar in quality to openai-community/gpt2-medium.
The vLLM didn't support global attention on odd layers. Although a fix has been implemented in the main branch, it hasn't yet been merged into the v0.5.4 release.
If you're using transformers, you need to set attn_implementation='eager' with the released versions. Otherwise, if you want to use flash_attention_2, you'll need to install the main branch to get the fix.