Instructions to use google/gemma-4-31B-it-qat-w4a16-ct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/gemma-4-31B-it-qat-w4a16-ct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="google/gemma-4-31B-it-qat-w4a16-ct") 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, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/gemma-4-31B-it-qat-w4a16-ct") model = AutoModelForMultimodalLM.from_pretrained("google/gemma-4-31B-it-qat-w4a16-ct") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use google/gemma-4-31B-it-qat-w4a16-ct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "google/gemma-4-31B-it-qat-w4a16-ct" # 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-4-31B-it-qat-w4a16-ct", "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-4-31B-it-qat-w4a16-ct
- SGLang
How to use google/gemma-4-31B-it-qat-w4a16-ct 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-4-31B-it-qat-w4a16-ct" \ --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-4-31B-it-qat-w4a16-ct", "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-4-31B-it-qat-w4a16-ct" \ --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-4-31B-it-qat-w4a16-ct", "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-4-31B-it-qat-w4a16-ct with Docker Model Runner:
docker model run hf.co/google/gemma-4-31B-it-qat-w4a16-ct
Raise per-image vision soft-token budget from 280 to 1120
Browse filesIncreases the default per-image vision soft-token budget from 280 to 1120 (the maximum supported value) so images are encoded at higher resolution by default. Video budget is unchanged (`video_processor.max_soft_tokens` = 70); no other values are modified.
Exact changes in this repo:
- `config.json`:
- `vision_config.default_output_length`: 280 → 1120
- `vision_soft_tokens_per_image`: 280 → 1120
- `processor_config.json`:
- `image_processor.image_seq_length`: 280 → 1120
- `image_processor.max_soft_tokens`: 280 → 1120
- `image_seq_length`: 280 → 1120
- config.json +2 -2
- processor_config.json +3 -3
|
@@ -369,7 +369,7 @@
|
|
| 369 |
"attention_bias": false,
|
| 370 |
"attention_dropout": 0.0,
|
| 371 |
"chunk_size_feed_forward": 0,
|
| 372 |
-
"default_output_length":
|
| 373 |
"dtype": "bfloat16",
|
| 374 |
"global_head_dim": 72,
|
| 375 |
"head_dim": 72,
|
|
@@ -406,5 +406,5 @@
|
|
| 406 |
"standardize": true,
|
| 407 |
"use_clipped_linears": false
|
| 408 |
},
|
| 409 |
-
"vision_soft_tokens_per_image":
|
| 410 |
}
|
|
|
|
| 369 |
"attention_bias": false,
|
| 370 |
"attention_dropout": 0.0,
|
| 371 |
"chunk_size_feed_forward": 0,
|
| 372 |
+
"default_output_length": 1120,
|
| 373 |
"dtype": "bfloat16",
|
| 374 |
"global_head_dim": 72,
|
| 375 |
"head_dim": 72,
|
|
|
|
| 406 |
"standardize": true,
|
| 407 |
"use_clipped_linears": false
|
| 408 |
},
|
| 409 |
+
"vision_soft_tokens_per_image": 1120
|
| 410 |
}
|
|
@@ -33,19 +33,19 @@
|
|
| 33 |
0.0
|
| 34 |
],
|
| 35 |
"image_processor_type": "Gemma4ImageProcessor",
|
| 36 |
-
"image_seq_length":
|
| 37 |
"image_std": [
|
| 38 |
1.0,
|
| 39 |
1.0,
|
| 40 |
1.0
|
| 41 |
],
|
| 42 |
-
"max_soft_tokens":
|
| 43 |
"patch_size": 16,
|
| 44 |
"pooling_kernel_size": 3,
|
| 45 |
"resample": 3,
|
| 46 |
"rescale_factor": 0.00392156862745098
|
| 47 |
},
|
| 48 |
-
"image_seq_length":
|
| 49 |
"processor_class": "Gemma4Processor",
|
| 50 |
"video_processor": {
|
| 51 |
"do_convert_rgb": true,
|
|
|
|
| 33 |
0.0
|
| 34 |
],
|
| 35 |
"image_processor_type": "Gemma4ImageProcessor",
|
| 36 |
+
"image_seq_length": 1120,
|
| 37 |
"image_std": [
|
| 38 |
1.0,
|
| 39 |
1.0,
|
| 40 |
1.0
|
| 41 |
],
|
| 42 |
+
"max_soft_tokens": 1120,
|
| 43 |
"patch_size": 16,
|
| 44 |
"pooling_kernel_size": 3,
|
| 45 |
"resample": 3,
|
| 46 |
"rescale_factor": 0.00392156862745098
|
| 47 |
},
|
| 48 |
+
"image_seq_length": 1120,
|
| 49 |
"processor_class": "Gemma4Processor",
|
| 50 |
"video_processor": {
|
| 51 |
"do_convert_rgb": true,
|