Median Total Time
66.53s
Median TTFT
36.01s
Median Prefill TPS
1637.80
Median Gen TPS
14.79
Context Size
262144
Quantization
r64
Engine
vllm
Creation Method
LoRA Finetune
Model Type
Gemma31B
Chat Template
Gemma4
Reasoning
Yes
Vision
Yes
Parameters
31B
Added At
7/25/2026
license: gemma language:
Released by AutoTrust AI Lab Β· Trained by Hai Yu Base model: google/gemma-4-31B-it Β· Method: LoRA (r=16) Β· License: Gemma
A parameter-efficient fine-tune of google/gemma-4-31B-it on agentic coding traces from Fable 5, designed to lift coding and tool-use performance without sacrificing the base model's vision capabilities β a common failure mode of coding fine-tunes.
π€ GGUF variant available: autotrust/gemma4-31B-Fable-5-Distilled-GGUF β F16 + Q8_0 with multimodal projector, runs on llama.cpp / Ollama / LM Studio / Jan.
| Model | HumanEval pass@1 | Ξ vs Base |
|---|---|---|
| gemma4-31B-Fable-5-Distilled (ours) | 92.7% (152/164) | +15.9 pts |
google/gemma-4-31B-it (official) | 76.8% | baseline |
Evaluation: HumanEval (164 Python problems), vLLM 0.22, T=0.1, thinking=off, batch generate. Identical result (92.7%) reproduced via vLLM server API with --reasoning-parser gemma4 at T=0.2.
Why it matters: We achieve this lift with only 0.20% of parameters trainable (61.2M / 31.27B) and without degrading multimodal vision β see Layer-Freezing Strategy below.
Most coding fine-tunes of multimodal models destroy the vision-language fusion learned during base pretraining. We avoid this by applying LoRA adapters only to the upper half of the transformer stack:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layers 30β59 β π’ LoRA-adapted (language head) β β coding & tool-use uplift
β (30 layers) β Q/K/V/O + gate/up/down projections β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Layers 0β29 β π FROZEN (multimodal fusion) β β vision preserved exactly
β (30 layers) β Visual feature processing untouched β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β²
β
Vision encoder (mmproj) β fully frozen
| Layers | State | Role |
|---|---|---|
| 0β29 | π Frozen | Low-level multimodal fusion, visual features |
| 30β59 | π’ LoRA | Higher-level language & generation |
Result: image description quality on held-out samples matches the base model bit-for-bit, while coding pass@1 lifts +15.9 points. Trainable parameters cut nearly in half vs. naive full-layer LoRA (~122M β 61.2M).
LoRA target modules (regex-matched):
language_model.layers.{30..59}.(self_attn|mlp).(q_proj|k_proj|v_proj|o_proj|gate_proj|up_proj|down_proj)
| Property | Value |
|---|---|
| Base Model | google/gemma-4-31B-it |
| Architecture | Gemma4ForConditionalGeneration (text decoder + vision encoder) |
| Parameters | 31.27B (bfloat16) |
| Fine-tuning Method | LoRA |
| LoRA Rank | r=16, Ξ±=32, dropout=0.05 |
| Trainable Parameters | 61.2M (0.20% of total) |
| Sequence Length | 2048 tokens |
| Thinking Mode | Enabled (native Gemma 4 multi-channel format) |
| License | Gemma Terms of Use |
Source: Glint-Research/Fable-5-traces β 23,325 raw interaction records from Fable 5, an agentic coding assistant.
Final training set: 308 conversation pairs after rigorous quality filtering.
Why so few? Quality-first curation. Each retained example is a complete tool-use conversation with verified outputs β full thinking traces, valid tool calls, and successful resolutions. In our ablations, this small high-signal set outperformed larger but noisier datasets (10K+ raw pairs) on both HumanEval and tool-use evaluations. The +15.9 point HumanEval lift is achieved on 308 examples, demonstrating that for post-training of strong base models, example quality dominates example count.
Preprocessing pipeline:
type == "message" records onlyparentId-100, only assistant response contributes to lossEach training example contains:
type: "thinking") β chain-of-thought reasoningtype: "toolCall") β structured invocations with name + argumentstype: "text") β final responseLoss is computed only on assistant response tokens (thinking + tool calls + final text). Prompt tokens (system + user) are labeled -100, so the model is never penalized for failing to predict user input.
input_ids = prompt_ids + completion_ids
labels = [-100] * len(prompt_ids) + completion_ids
| Hyperparameter | Value |
|---|---|
| Optimizer | AdamW (default) |
| Learning Rate | 2e-4 |
| LR Scheduler | Cosine |
| Warmup Steps | 50 |
| Batch Size (per device) | 1 |
| Gradient Accumulation | 16 (effective batch = 16) |
| Precision | bfloat16 |
| Gradient Checkpointing | Enabled |
| Epochs | 1 |
import torch
from transformers import AutoModelForCausalLM, AutoProcessor
model_id = "autotrust/gemma4-31B-Fable-5-Distilled"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
)
messages = [
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "Write a Python function to reverse a linked list."},
]
prompt = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True, enable_thinking=True
)
inputs = processor(text=prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=False))
from PIL import Image
image = Image.open("path/to/image.png").convert("RGB")
messages = [{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": "Describe this image in detail."},
],
}]
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
pip install vllm
vllm serve autotrust/gemma4-31B-Fable-5-Distilled --reasoning-parser gemma4
enable_thinking=True. Responses without thinking may be suboptimal β keep thinking on for production use.Configurations tested:
| Configuration | Pass@1 | Engine | Settings |
|---|---|---|---|
| vLLM offline batch | 92.7% (152/164) | vLLM 0.22 | T=0.1, thinking=off, batch generate |
| vLLM server API | 92.7% (152/164) | vLLM 0.22 | T=0.2, thinking=off, --reasoning-parser gemma4 |
| Google Official (base) | 76.8% | (internal) | T=0.1, thinking=on, base gemma-4-31B-it |
| Type | Count | Detail |
|---|---|---|
| Missing imports | 8 | re (4), math (3), decimal (1), hashlib (1) β model omits stdlib imports |
| Logical errors | 4 | Code compiles but fails test assertions |
The missing-import failures suggest a remediable distillation artifact (Fable 5 traces often elide stdlib imports). A future revision will rebalance the dataset to retain explicit imports.
openai/openai_humaneval (164 problems)python ... ."python\n{prompt}\n"prompt + body + test + check(entry_point) harness, 5s timeoutOn vLLM, enable_thinking=True with --reasoning-parser gemma4 produces verbose thinking traces that can exceed the token budget, resulting in finish_reason=length and empty content. Google AI Studio API handles this correctly by separating thinking from the final answer. Benchmarks above use enable_thinking=False for reliable extraction. For interactive use, keep thinking on with a higher max_tokens budget (we recommend β₯ 1024).
@misc{autotrust2026gemma4fable5,
title = {Gemma-4-31B-Fable-5-Distilled: Layer-Frozen LoRA Distillation
Preserving Multimodal Vision},
author = {{AutoTrust AI Lab} and Yu, Cloud},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/autotrust/gemma4-31B-Fable-5-Distilled}},
note = {Contact: cloud.yu@autotrust.ai}
}
AutoTrust AI Lab builds open foundation models and agentic systems for scientific research and coding. Our flagship products are PaperGuru AI (agentic academic research) and the upcoming ScienceGuru.
We welcome community feedback, benchmarks, and quantization contributions β open an issue in the Community tab.