Views
No views yet
Gemma4AssistantForCausalLM (Multi-Token Prediction drafter)
google/gemma-4-31B-it.FP8_BLOCK scheme: weights use block-wise scaling over 128×128 blocks, activations are quantized
dynamically per group of 128. The vision-related modules, lm_head, and embed_tokens are left in
their original precision.float8_e4m3fn (the 4 decoder blocks' q_proj, o_proj, gate_proj,
up_proj, down_proj, plus pre_projection and post_projection). Everything else — layer norms,
layer scalars, and the embedding table — stays in BF16.| Upstream (BF16) | This model (FP8-block) | |
|---|---|---|
model.safetensors | 939 MB | 738 MB |
model.embed_tokens.weight (262144 × 1024) is 512 MiB on its own — about 73% of this checkpoint — and it
is excluded from quantization because it is tied to the output head. The quantized linear layers
themselves shrink close to 2×; the embedding table dominates what is left.assistant_model:1from transformers import AutoProcessor, AutoModelForCausalLM
2
3TARGET_MODEL_ID = "google/gemma-4-31B-it"
4ASSISTANT_MODEL_ID = "BarraHome/gemma-4-31B-it-assistant-FP8-block"
5
6processor = AutoProcessor.from_pretrained(TARGET_MODEL_ID)
7target_model = AutoModelForCausalLM.from_pretrained(
8 TARGET_MODEL_ID,
9 dtype="auto",
10 device_map="auto",
11)
12
13# Assistant model (the drafter)
14assistant_model = AutoModelForCausalLM.from_pretrained(
15 ASSISTANT_MODEL_ID,
16 dtype="auto",
17 device_map="auto",
18)
19
20messages = [
21 {"role": "system", "content": "You are a helpful assistant."},
22 {"role": "user", "content": "Write a short joke about saving RAM."},
23]
24
25inputs = processor.apply_chat_template(
26 messages,
27 tokenize=True,
28 return_dict=True,
29 return_tensors="pt",
30 add_generation_prompt=True,
31 enable_thinking=False,
32).to(target_model.device)
33input_len = inputs["input_ids"].shape[-1]
34
35outputs = target_model.generate(
36 **inputs,
37 assistant_model=assistant_model,
38 max_new_tokens=256,
39)
40response = processor.decode(outputs[0][input_len:], skip_special_tokens=False)
41print(processor.parse_response(response))compressed-tensors:pip install -U transformers torch accelerate compressed-tensorsvllm serve google/gemma-4-31B-it \
--speculative-config '{"method": "mtp", "model": "BarraHome/gemma-4-31B-it-assistant-FP8-block", "num_speculative_tokens": 3}'Note: this snippet has not been verified against a running server. MTP drafters attach to the target model's hidden states (backbone_hidden_size: 5376inconfig.json), so it needs a vLLM build that supports thegemma4_assistantarchitecture. Check the vLLM speculative decoding docs for the current syntax and for whether your version handles this architecture.
1from llmcompressor import model_free_ptq
2
3MODEL_ID = "google/gemma-4-31B-it-assistant"
4SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-block"
5
6model_free_ptq(
7 model_stub=MODEL_ID,
8 save_directory=SAVE_DIR,
9 scheme="FP8_BLOCK",
10 ignore=["re:.*vision.*", "lm_head", "re:.*embed_tokens.*"],
11 max_workers=8,
12 device="cuda:0",
13)