Commit faf7df4
Add hybrid LK loss (adaptive KL/TV blend) for speculative decoding (vllm-project#673)
## Summary
Adds the hybrid LK loss: an adaptive per-position blend of KL and TV,
L = lambda*KL + (1-lambda)*TV with lambda = exp(-eta * sg[alpha]), alpha
= overlap.
## Motivation
TV optimizes acceptance directly but has a vanishing gradient from a
cold start; KL has a
strong early gradient but optimizes a proxy. The hybrid leans on KL when
overlap is low and
shifts to TV as the draft aligns, making TV's acceptance-optimal target
trainable from
scratch. Source: Samarin et al., arXiv 2602.23881. Paper's best setting:
eta=3.
## Changes
- `lk_hybrid_loss(logits, targets, eta=3.0)` in metrics.py, reusing
`kl_div_loss` and the
TV overlap term; alpha in the blend weight is detached.
- `resolve_loss_fn` gains `lk_loss_eta` (default 3.0), binding eta into
the "lk_hybrid"
entry via functools.partial (single binding point; call sites
unchanged).
- `--lk-loss-eta` CLI flag (mirrors --dflash-decay-gamma), threaded
through each
get_trainer_kwargs into resolve_loss_fn; "lk_hybrid" added to --loss-fn
choices.
- Tests: eta->0 == KL, eta->inf == TV, shape/finiteness, alpha-detach
gradient check,
resolve binds eta.
## Notes
- The adaptive KL/TV blend and the DFlash positional decay are
orthogonal weightings.
- tv/nla are not in the --loss-fn choices list either; happy to add them
here if desired.
- Loss key name "lk_hybrid" open to preference.
Signed-off-by: GIREESH7963 <abburigireesh@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Eros483 <arnabmandal2912@gmail.com>1 parent 5ef8435 commit faf7df4
3 files changed
Lines changed: 107 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
866 | | - | |
867 | | - | |
| 866 | + | |
| 867 | + | |
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
183 | 225 | | |
184 | 226 | | |
185 | 227 | | |
| |||
219 | 261 | | |
220 | 262 | | |
221 | 263 | | |
| 264 | + | |
222 | 265 | | |
223 | 266 | | |
224 | 267 | | |
| |||
229 | 272 | | |
230 | 273 | | |
231 | 274 | | |
232 | | - | |
233 | | - | |
| 275 | + | |
| 276 | + | |
234 | 277 | | |
235 | 278 | | |
236 | 279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
167 | 227 | | |
168 | 228 | | |
169 | 229 | | |
| |||
0 commit comments