Commit 2c08671
fix: recover per-token ids and logprobs from content[] to stop RL KLD corruption (#458)
* fix: request exact token ids and fail loud in FireworksV1CompletionsClient
The /v1/completions sampling path corrupted RL training via retokenization
drift. The request never set return_token_ids, so choices[].token_ids came
back empty and the client silently re-encoded decoded text. Retokenization
drops the trailing end-of-turn/EOS token, making completion_ids one shorter
than token_logprobs and misaligning every per-token logprob (inference KLD
spiked to ~60 vs ~0.028 with exact ids).
- Default return_token_ids=True in the request payload (overridable via
request_params).
- Remove the tokenizer.encode() re-encode fallback; raise when exact ids are
absent instead of silently returning corrupted data.
- Assert len(completion_token_ids) == len(completion_logprobs) at the boundary
to catch any residual drift.
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: recover per-token ids and logprobs from content[] logprobs shape
This client always requests boolean logprobs=True, so every response uses the
new content[] logprobs shape. Read the exact per-token ids and logprobs
together from content[] (token_id + sampling_logprob) so they are aligned by
construction.
Bug 1 (alignment / KLD corruption) — the real fix: previously ids were read
only from the top-level choices[].token_ids (populated by return_token_ids,
which this client never requested) and, when absent, silently re-derived via
tokenizer.encode(decode(text)). Retokenization drops the trailing
end-of-turn/EOS token, making completion_ids one shorter than the logprobs and
misaligning every per-token logprob (inference_kld ~60 vs ~0.028). Since
content[] already carries token_id per entry, reading ids there removes the
drift entirely — no return_token_ids, no re-encode fallback.
Bug 2 (precision) — more of a feature: prefer content[].sampling_logprob (the
exact value the sampler drew with) over content[].logprob (rounded).
- Drop legacy token_logprobs / top-level token_ids / raw_output id sources.
- Fail loud when content[] is absent or a content[] entry lacks token_id,
instead of silently returning corrupted data.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: require sampling_logprob per content[] entry, no fallback
Always read the per-token logprob from content[].sampling_logprob (the exact
value the sampler drew with). Fail loud if any content[] entry lacks
sampling_logprob instead of substituting the rounded content[].logprob or 0.0,
so silently degraded logprobs never reach RL training. Removes the now-unused
_extract_entry_logprob helper.
Co-authored-by: Cursor <cursoragent@cursor.com>
* test: use pytest.approx for logprob list comparison
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 08e9b85 commit 2c08671
2 files changed
Lines changed: 200 additions & 22 deletions
File tree
- eval_protocol/integrations
- tests
Lines changed: 37 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | 396 | | |
400 | 397 | | |
401 | 398 | | |
402 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
403 | 437 | | |
404 | 438 | | |
405 | 439 | | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | 440 | | |
426 | 441 | | |
427 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 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 | + | |
| 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 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
127 | 290 | | |
128 | 291 | | |
129 | 292 | | |
| |||
0 commit comments