Views
No views yet
pip install git+https://github.com/huggingface/transformers@v4.49.0-Gemma-31
2from transformers import AutoProcessor, Gemma3ForConditionalGeneration, BitsAndBytesConfig
3from PIL import Image
4import torch
5
6model_id = "MISHANM/google-gemma-3-12b-it-fp8"
7
8# Load the model with 8-bit quantization
9model = Gemma3ForConditionalGeneration.from_pretrained(
10 model_id, device_map="auto"
11).eval()
12
13processor = AutoProcessor.from_pretrained(model_id)
14
15# Define chat messages for inference
16messages = [
17 {
18 "role": "system",
19 "content": [{"type": "text", "text": "You are a helpful assistant."}]
20 },
21 {
22 "role": "user",
23 "content": [
24 {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
25 {"type": "text", "text": "Describe this image in detail."}
26 ]
27 }
28]
29
30# Prepare inputs for the model
31inputs = processor.apply_chat_template(
32 messages, add_generation_prompt=True, tokenize=True,
33 return_dict=True, return_tensors="pt"
34).to(model.device, dtype=torch.bfloat16)
35
36input_len = inputs["input_ids"].shape[-1]
37
38# Generate model output
39with torch.inference_mode():
40 generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
41 generation = generation[0][input_len:]
42
43# Decode the generated output
44decoded = processor.decode(generation, skip_special_tokens=True)
45print(decoded)
46
47
48@misc{MISHANM/google-gemma-3-12b-it-fp8,
author = {Mishan Maurya},
title = {Introducing fp8 quantized version of google/gemma-3-12b-it},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face repository},
}