This is a fine-tuned version of google/gemma-4-E2B-it-assistant, the speculative-decoding (MTP) drafter that ships with Gemma 4 E2B. Use it as the assistant model for google/gemma-4-E2B-it.
What it does: it makes Gemma 4 E2B generate Turkish medical text about 1.7x faster than plain decoding. With the original drafter the speedup was about 1.2x. Other domains do not get worse.
What it does not do: it does not change what the model says. In speculative decoding the target model checks every drafted token, so the output is the same as running gemma-4-E2B-it alone. This is a speed add-on and not a medical model. The target model was not modified.
Speedup is measured with HF generate, greedy decoding, batch size 1, 128 new tokens, on an A100-80GB with bf16. It is compared with the same target without an assistant. τ is the number of tokens accepted per target forward pass. Brackets show 95% bootstrap confidence intervals over prompts.
| Test set (prompts) | Original drafter, K=4 | This drafter, K=4 | Original, K=2 | This drafter, K=2 |
|---|---|---|---|---|
| Turkish medical, fully held-out (20) | 1.15x (τ 1.73) | 1.66x [1.58, 1.76] (τ 2.54) | 1.24x | 1.64x |
| Turkish medical (48) | 1.17x (τ 1.78) | 1.73x [1.68, 1.79] (τ 2.65) | 1.26x | 1.66x |
| Turkish general (32) | 1.24x | 1.44x | 1.31x | 1.47x |
| English medical (24) | 1.46x | 1.65x | 1.46x | 1.58x |
| English general (24) | 1.49x | 1.48x | 1.48x | 1.49x |
K is the number of draft tokens per step. K=4 is recommended.
Teacher-forced acceptance on held-out responses: τ̂ at K=4, averaged over 3 seeds. The seed-to-seed std is about 0.001.
| Test set | Original | This drafter | Difference [95% CI] |
|---|---|---|---|
| Turkish medical, held-out set | 1.905 | 2.544 | +0.64 [+0.54, +0.74] |
| Turkish general, held-out set | 2.049 | 2.243 | +0.20 [+0.16, +0.22] |
| English medical, held-out set | 2.199 | 2.344 | +0.15 [+0.10, +0.20] |
| English general, held-out set | 2.423 | 2.424 | +0.00 [−0.02, +0.02] |
Lossless check: on 16 Turkish medical prompts at K=2 and K=4 in fp32 with TF32 off, the output with this drafter is identical token by token to the output without it in 100% of cases. In bf16 a fraction of outputs diverge after a few dozen tokens. That divergence happens at exactly the same rate and positions with the original drafter, so it is bf16 numerical noise and not caused by the drafter.
The Gemma 4 drafter does not score the full 262k vocabulary. An ordered embedding head first picks the top 32 of 2,048 token clusters, then scores only the tokens in those clusters, which is about 1.6% of the vocabulary. If the target's next token is outside the selected clusters, the drafter cannot predict it.
On Turkish, the correct token was inside the selected clusters only 83% of the time, compared with 92–94% on English. Fine-tuning the cluster selector together with the drafter raises this to 96% for Turkish medical text. That one change gives most of the gain:
| Variant (3 seeds each) | Turkish medical held-out τ̂ (K=4) | Cluster recall |
|---|---|---|
| Original | 1.905 | 82.9% |
| Fine-tune drafter body, KL to target | 2.232 | 85.3% |
| + train cluster selector | 2.470 | 95.5% |
| + train lm_head (this model) | 2.544 | 95.4% |
gemma-4-E2B-it itself (self-distillation, at most 512 tokens), so the drafter learns the target's own distribution.kayrab/patient-doctor-qa-tr-* datasets. Only the questions were used, with PII-like strings removed; the original doctor answers were not used.import torch
from transformers import AutoProcessor, AutoModelForCausalLM
target_id, drafter_id = "google/gemma-4-E2B-it", "senpaicq/gemma-4-E2B-it-assistant-tr-medical"
processor = AutoProcessor.from_pretrained(target_id)
target = AutoModelForCausalLM.from_pretrained(target_id, dtype=torch.bfloat16, device_map="auto")
assistant = AutoModelForCausalLM.from_pretrained(drafter_id, dtype=torch.bfloat16, device_map="auto")
assistant.generation_config.num_assistant_tokens = 4
assistant.generation_config.num_assistant_tokens_schedule = "constant"
messages = [{"role": "user", "content": [{"type": "text", "text": "Tip 2 diyabet hastaları sabah kahvaltısında nelere dikkat etmeli?"}]}]
inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True,
return_dict=True, return_tensors="pt").to(target.device)
out = target.generate(**inputs, assistant_model=assistant, max_new_tokens=512, do_sample=False)
print(processor.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Tested with transformers==5.21.1.
transformers. Serving engines such as vLLM and SGLang have different overheads, so wall-clock gains there will differ. τ (acceptance length) transfers better than wall-clock speedup.model.safetensors, config.json, generation_config.json: the drafter. It is a drop-in replacement for google/gemma-4-E2B-it-assistant.train_cfg.json: the training configuration.eval_results.json: all evaluation numbers, including per-arm, per-seed and paired-bootstrap results.notebooks/: data generation, training/ablation and robustness notebooks, with outputs stripped.The training data is not released because it contains real patient questions.