Instructions to use google/gemma-3-27b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-3-27b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/gemma-3-27b-it") 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 AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("google/gemma-3-27b-it") model = AutoModelForImageTextToText.from_pretrained("google/gemma-3-27b-it") 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?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use google/gemma-3-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-3-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-3-27b-it", "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/google/gemma-3-27b-it
- SGLang
How to use google/gemma-3-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-3-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-3-27b-it", "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 "google/gemma-3-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-3-27b-it", "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 google/gemma-3-27b-it with Docker Model Runner:
docker model run hf.co/google/gemma-3-27b-it
Keeps repeating itself.
Q4K_M. Simple role-play. LM Studio. RTX3090.
Every 4th line or so is basically a repeat of what it said in the previous response.
I thought at first it was because the context too long, when asking it to proof read a novel. But even a simple role-play, less than 10% of context used, with context set at 32K, it's repeating itself again.
When it works it's great, but at the same time it's totally trash and useless. Someone said there are known issues with the 3090? I have no idea how that would work? They also said there's an update, but from the looks of this it's not updated?
Hi @rdtfddgrffdgfdghfghdfujgdhgsf,
Even when only a small portion of the context window is used, this repetition issue still shows up and it’s not just limited to the RTX 3090. With different hardware setups have reported similar problems.
Could you please try to tweak the Sampling Settings:
- Higher temperature values help make the responses less predictable and reduce repetition.
- Adding a penalty (like 1.1) discourages the model from saying the same thing over and over.
- Adjusting Top-k / Top-p can also help bring in more variety and control the randomness in the output.
Finally, make sure running the latest version of LM Studio because new releases can solve this type of issues. For more information, could you please refer to this reference.
Thank you.
I meet the same issue when trying to use gemma-3-27b to fine tune long texts. If the input text is longer than 3000 token, which is just half of typical length of a single novel unit in CJK, model will repeat if self after correct generate first 2500 token.
I tried to adjust temperature and penalty. Although the adjustment stopped the repetition, the quality dropped dramatically.
This make the model nearly unusable when handling CJK text work.
In my testing, I found it is resolved in latest image:
inferenceservice:
predictor:
containers:
- name: kserve-container
imageURL: vllm/vllm-openai:v0.10.0
args:
- --model=google/gemma-3-27b-it
- --tokenizer=google/gemma-3-27b-it
- --tensor-parallel-size=8
- "--gpu-memory-utilization=0.9"
- "--max-model-len=8192"
- "--trust-remote-code"
- "--enforce-eager"
In my testing, I found it is resolved in latest image:
inferenceservice: predictor: containers: - name: kserve-container imageURL: vllm/vllm-openai:v0.10.0 args: - --model=google/gemma-3-27b-it - --tokenizer=google/gemma-3-27b-it - --tensor-parallel-size=8 - "--gpu-memory-utilization=0.9" - "--max-model-len=8192" - "--trust-remote-code" - "--enforce-eager"
Hi @johnzhengaz , what service did you use to run this container? Thank you for your help.