Gemma 4 12B Quantized
Collection
3 items • Updated
How to use soyrsoyr/gemma-4-12b-it-FP8-Dynamic with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="soyrsoyr/gemma-4-12b-it-FP8-Dynamic")
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("soyrsoyr/gemma-4-12b-it-FP8-Dynamic")
model = AutoModelForMultimodalLM.from_pretrained("soyrsoyr/gemma-4-12b-it-FP8-Dynamic", device_map="auto")
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]:]))How to use soyrsoyr/gemma-4-12b-it-FP8-Dynamic with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "soyrsoyr/gemma-4-12b-it-FP8-Dynamic"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "soyrsoyr/gemma-4-12b-it-FP8-Dynamic",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/soyrsoyr/gemma-4-12b-it-FP8-Dynamic
How to use soyrsoyr/gemma-4-12b-it-FP8-Dynamic with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "soyrsoyr/gemma-4-12b-it-FP8-Dynamic" \
--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": "soyrsoyr/gemma-4-12b-it-FP8-Dynamic",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "soyrsoyr/gemma-4-12b-it-FP8-Dynamic" \
--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": "soyrsoyr/gemma-4-12b-it-FP8-Dynamic",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use soyrsoyr/gemma-4-12b-it-FP8-Dynamic with Docker Model Runner:
docker model run hf.co/soyrsoyr/gemma-4-12b-it-FP8-Dynamic
FP8 Dynamic quantized version of google/gemma-4-12b-it using RTN (round-to-nearest) via llm-compressor.
| Property | Value |
|---|---|
| Base Model | google/gemma-4-12b-it |
| Quantization Method | RTN (round-to-nearest) |
| Format | float-quantized (FP8) |
| Weight Strategy | channel (per-channel) |
| Activation Strategy | token (per-token, dynamic) |
| Weight Bits | 8 (FP8 E4M3) |
| Model Size | ~15 GB |
| Calibration Data | None (data-free) |
Evaluated with lm-evaluation-harness v0.4.12 using vLLM v0.25.1 on 2x NVIDIA H100 80GB.
| Variant | GSM8K (flexible) | GSM8K (strict) |
|---|---|---|
| Baseline (BF16) | 87.57% | 86.58% |
| FP8 Dynamic | 87.95% | 86.96% |
| Delta | +0.38% | +0.38% |
FP8 Dynamic quantization shows no accuracy loss on GSM8K — the delta is within noise (stderr ~0.9%).
Quantized with llm-compressor v0.12.0 on 2x NVIDIA H100 80GB GPUs.
from transformers import AutoModelForImageTextToText, AutoProcessor
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
MODEL_ID = "google/gemma-4-12b-it"
model = AutoModelForImageTextToText.from_pretrained(MODEL_ID, dtype="auto")
recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_DYNAMIC",
ignore=[
"lm_head",
"re:.*embed_vision.*",
"re:.*embed_audio.*",
"re:.*vision_embedder.*",
],
)
oneshot(model=model, recipe=recipe)
model.save_pretrained("gemma-4-12b-it-FP8-Dynamic", save_compressed=True)
pip install vllm
vllm serve soyrsoyr/gemma-4-12b-it-FP8-Dynamic --max-model-len 4096 --tensor-parallel-size 2
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
model="soyrsoyr/gemma-4-12b-it-FP8-Dynamic",
messages=[{"role": "user", "content": "Explain quantization in one sentence."}],
max_tokens=128,
)
print(response.choices[0].message.content)
containers:
- name: vllm
image: vllm/vllm-openai:latest
args:
- --model
- soyrsoyr/gemma-4-12b-it-FP8-Dynamic
- --max-model-len
- "4096"
- --tensor-parallel-size
- "2"
resources:
limits:
nvidia.com/gpu: "2"