vllm.v1.worker.gpu.spec_decode.gemma4.speculator ¶
Gemma4 MTP (Multi-Token Prediction) speculator for speculative decoding.
The Gemma4 assistant model runs all decoder layers per draft step (producing one token), and all its attention layers share KV cache with the target model via cross-model KV sharing.
Classes:
Gemma4Speculator ¶
Bases: AutoRegressiveSpeculator
Source code in vllm/v1/worker/gpu/spec_decode/gemma4/speculator.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
_create_draft_vllm_config() ¶
Preserve the target's forced TRITON_ATTN backend for draft layers.
Gemma4 forces TRITON_ATTN due to heterogeneous head dimensions (head_dim=256 sliding, global_head_dim=512 full). The base class resets attention_config.backend to None for draft models, causing sliding layers to fall back to FLASH_ATTN which cannot handle KV-shared cache. Override to carry the target's backend through.
Source code in vllm/v1/worker/gpu/spec_decode/gemma4/speculator.py
_setup_gemma4_kv_sharing(model, target_attn_layer_names) ¶
Wire draft layers to share KV and KV scales with the target model.
Each draft decoder layer is mapped to the last non-KV-shared target layer of the same attention type (sliding or full).
Source code in vllm/v1/worker/gpu/spec_decode/gemma4/speculator.py
_copy_target_kv_scales(attn, target_attn) ¶
Copy target KV scales while preserving their tensor representation.
Default attention scales are scalar buffers, while some quantization methods replace them with length-one or per-head parameters. Re-register cloned buffers on the draft layer so the shared KV cache is interpreted with the target's values and shapes without aliasing target parameters.