Commit b4e25ec
committed
Scope prepend_scheme realignment to post-init add_tokens
The `_add_tokens` override flipped a standalone Metaspace("always") to
"first" on every non-special add, including a tokenizer's own added
tokens restored during `from_pretrained`. For a checkpoint that loads
as a standalone Metaspace with non-special added tokens (e.g. kosmos-2,
which restores 1035 of them), this rewrote the saved scheme at load
time and dropped the metaspace prefix after in-text special tokens,
breaking Kosmos2ProcessorTest::test_full_processor.
Gate the flip on a `_prepend_scheme_can_flip` flag set once construction
finishes, so only genuine post-init user `add_tokens` calls realign the
scheme. Add a regression test covering checkpoint restore.1 parent c0cce5b commit b4e25ec
2 files changed
Lines changed: 31 additions & 4 deletions
File tree
- src/transformers
- tests/tokenization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
491 | 495 | | |
492 | 496 | | |
493 | 497 | | |
| |||
727 | 731 | | |
728 | 732 | | |
729 | 733 | | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
734 | 740 | | |
735 | 741 | | |
736 | 742 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
246 | 267 | | |
247 | 268 | | |
248 | 269 | | |
| |||
0 commit comments