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
ERROR:Gemma3Config' object has no attribute 'vocab_size'
INFO 03-13 14:12:23 transformers.py:129] Using Transformers backend.
ERROR 03-13 14:12:23 engine.py:400] 'Gemma3Config' object has no attribute 'vocab_size'
ERROR 03-13 14:12:23 engine.py:400] Traceback (most recent call last):
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/multiprocessing/engine.py", line 391, in run_mp_engine
ERROR 03-13 14:12:23 engine.py:400] engine = MQLLMEngine.from_engine_args(engine_args=engine_args,
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/multiprocessing/engine.py", line 124, in from_engine_args
ERROR 03-13 14:12:23 engine.py:400] return cls(ipc_path=ipc_path,
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/multiprocessing/engine.py", line 76, in init
ERROR 03-13 14:12:23 engine.py:400] self.engine = LLMEngine(*args, **kwargs)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/engine/llm_engine.py", line 273, in init
ERROR 03-13 14:12:23 engine.py:400] self.model_executor = executor_class(vllm_config=vllm_config, )
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/executor_base.py", line 52, in init
ERROR 03-13 14:12:23 engine.py:400] self._init_executor()
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 47, in _init_executor
ERROR 03-13 14:12:23 engine.py:400] self.collective_rpc("load_model")
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 56, in collective_rpc
ERROR 03-13 14:12:23 engine.py:400] answer = run_method(self.driver_worker, method, args, kwargs)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/utils.py", line 2196, in run_method
ERROR 03-13 14:12:23 engine.py:400] return func(*args, **kwargs)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/worker/worker.py", line 183, in load_model
ERROR 03-13 14:12:23 engine.py:400] self.model_runner.load_model()
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/worker/model_runner.py", line 1112, in load_model
ERROR 03-13 14:12:23 engine.py:400] self.model = get_model(vllm_config=self.vllm_config)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/init.py", line 14, in get_model
ERROR 03-13 14:12:23 engine.py:400] return loader.load_model(vllm_config=vllm_config)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/loader.py", line 406, in load_model
ERROR 03-13 14:12:23 engine.py:400] model = _initialize_model(vllm_config=vllm_config)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/model_loader/loader.py", line 125, in _initialize_model
ERROR 03-13 14:12:23 engine.py:400] return model_class(vllm_config=vllm_config, prefix=prefix)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/vllm/model_executor/models/transformers.py", line 135, in init
ERROR 03-13 14:12:23 engine.py:400] self.vocab_size = config.vocab_size
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] File "/root/miniconda3/envs/vllm/lib/python3.12/site-packages/transformers/configuration_utils.py", line 214, in getattribute
ERROR 03-13 14:12:23 engine.py:400] return super().getattribute(key)
ERROR 03-13 14:12:23 engine.py:400] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 03-13 14:12:23 engine.py:400] AttributeError: 'Gemma3Config' object has no attribute 'vocab_size'
Seems like you are trying to load this model as AutoModelForCausalLM. Gemma3 is multimodal and its submodule language_model belongs to this class.
same problem here too
Apologies for the delayed response. We can confirm that this issue has been addressed and resolved in Transformers version 4.53.0.
Could you please try again by installing the latest Transformers version using !pip install -U transformers and then load the gemma-3-27b-it model with the following code:
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("google/gemma-3-27b-it")
Please let us know if this resolves the issue or if you continue to experience the same problem. Thank you.