Instructions to use google/gemma-2-27b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-2-27b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="google/gemma-2-27b-it") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-27b-it") model = AutoModelForCausalLM.from_pretrained("google/gemma-2-27b-it") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/gemma-2-27b-it 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-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "google/gemma-2-27b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/google/gemma-2-27b-it
- SGLang
How to use google/gemma-2-27b-it 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-it" \ --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": "google/gemma-2-27b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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-it" \ --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": "google/gemma-2-27b-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use google/gemma-2-27b-it with Docker Model Runner:
docker model run hf.co/google/gemma-2-27b-it
Unable to reproduce high quality arena-hard-auto results on GCP A100
Hello,
As part of trying this model out, I am reproducing its reported results on arena-hard-auto, in which the 27b IT version reports a 57% win rate.
So, I set up a deployment on GCP according to the recommended k8s yaml, using the docker image:
us-docker.pkg.dev/deeplearning-platform-release/gcr.io/huggingface-text-generation-inference-cu121.2-1.ubuntu2204.py310
I then collected responses for the 500 prompts on arena-hard, and ran the judgement on them. I got the following low quality results:
tgi-google-gemma-2-27b-it | score: 3.8 | 95% CI: (-0.8, 0.7) | average #tokens: 1554
The 3.8% score is so low, that I'm sure that its a problem with the deployment and not that this is the true strength of the model. However, may other people are reporting generation artifacts and overall low quality results, so it seems that there is no cookbook to create a functioning inference server with this model that actually delivers its true capabilities.
Has anyone been able to create a satisfactory inference server running this model?
For me, inferencing with vllm OpenAI compatible API, I added --enforce-eager flag to enable model to enforce eager execution https://github.com/vllm-project/vllm/blob/main/vllm/config.py
docker run command example:
docker run --rm --runtime nvidia --gpus all --env VLLM_ATTENTION_BACKEND=FLASHINFER vllm/vllm-openai:latest --model google/gemma-2-2b-it --tensor-parallel-size 2 --enforce-eager
You can try adding model = Automodel.from_pretrained('google/gemma-2-27b-it', attn_implementation='eager') argument if you use transformer library itself.
I forgot to update this thread, that also worked for me.