Repository navigation
Commit c742ca1
committed
DeepSeek-V4.1: left padding
The compressor pooled consecutive tokens before the attention mask
applied, so left padding shifted the groups and folded pad tokens into
the compressed KV. It now moves the real tokens of each row to the front
before pooling, so the groups are counted from the first real token of a
row. The compressed entries are left-aligned: the cache writes the new
entries of each row at that row's own offset, and keeps the last
`ratio - 1` real tokens of a row for its next group. An entry is rotated
at the position id of its group, and the indexer hides entries by
counting real tokens instead of reading `position_ids`.
`forward` still defaults `position_ids` to an `arange`, like the rest of
the library. The KV are rounded after RoPE, so the model is not
indifferent to a shift of the positions, and a direct call on a padded
batch has to pass the positions that `generate` makes.
The common left padding test is no longer skipped. It hardcoded a
tolerance of 1e-5, so it now takes `atol` and `rtol` like
`test_batching_equivalence` does, and we pass the 1e-2 that our other
comparison tests use. A new test covers padding with a cache, in chunks
and token by token.1 parent 39eb744 commit c742ca1
5 files changed
Lines changed: 347 additions & 149 deletions
File tree
- docs/source/en/model_doc
- src/transformers/models/deepseek_v41
- tests
- generation
- models/deepseek_v41
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
0 commit comments