Repository navigation
Commit ba3eede
committed
fix(training): sanitize masked sentinel and non-finite inputs in the DSpark loss
Padded teacher-forcing layouts fill unsupervised positions with sentinel target
ids (-1 / -100) and non-finite logits. A sentinel id indexes out of bounds in the
gather, and zero-weighting a non-finite row does not save the step: 0 * NaN is
NaN in the forward, and the backward of a non-finite row poisons the gradient
regardless of its weight.
Replace the inputs at unsupervised positions instead of masking the outputs.
torch.where on draft_logits selects exact zeros into those slots in the backward
rather than multiplying by zero, so no NaN reaches draft_logits.grad; target_ids
are filled with a valid row; the reduced L1 and the confidence logits are
scrubbed for non-finite teacher rows without copying the full-vocab teacher.
Keying off the combined supervision mask means dropped anchors get the same
protection as eval-masked positions. A poisoned batch now produces bit-identical
losses, metrics, and gradients to the equivalent clean one, which the tests
assert term by term.
Note in the head's docstring that the embedding lookup stays strict: it is the
producer's job to replace sentinels, and clamping there would silently train on
row 0 rather than fail.
Signed-off-by: khazic <khazzz1c@gmail.com>1 parent f7fd089 commit ba3eede
3 files changed
Lines changed: 75 additions & 7 deletions
File tree
- src/megatron/bridge/training/post_training/dspark
- tests/unit_tests/training/post_training
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| |||
272 | 274 | | |
273 | 275 | | |
274 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
275 | 287 | | |
276 | 288 | | |
277 | | - | |
| 289 | + | |
278 | 290 | | |
279 | 291 | | |
280 | 292 | | |
281 | 293 | | |
282 | 294 | | |
283 | 295 | | |
284 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
285 | 301 | | |
286 | 302 | | |
287 | 303 | | |
288 | 304 | | |
289 | 305 | | |
| 306 | + | |
290 | 307 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 308 | + | |
295 | 309 | | |
296 | 310 | | |
297 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 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 | + | |
| 290 | + | |
245 | 291 | | |
246 | 292 | | |
247 | 293 | | |
| |||
0 commit comments