Skip to content

Write the aligned token ids to the text config - #7315

Merged
albertvillanova merged 2 commits into
mainfrom
align-token-ids-on-text-config
Sep 23, 2026
Merged

albertvillanova merged 2 commits into
mainfrom
align-token-ids-on-text-config

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

This PR writes the aligned special token ids to the text config instead of the top-level config.

Part of #7093. For a composite model the id the trainer wrote was not the one Trainer reads, so align_special_tokens realigned it at train time and logged it; writing through get_text_config() leaves nothing to realign.

Motivation

The trainers set the tokenizer's pad and eos ids on the model configs before training, so that the alignment Trainer performs at train time finds nothing to change. huggingface/transformers#48847 moved that alignment to read and write model.config.get_text_config(), because a composite model keeps its special token ids on the text sub-config and the top-level config does not forward attribute lookups.

Our writes still land on the top-level config, so for a composite model they are no longer what gets compared, and the realignment message comes back. Measured on tiny-Qwen2_5_VLForConditionalGeneration against transformers main:

TRL writes to model.config                       -> Updated tokens: {'pad_token_id': 151643}
TRL writes to model.config.get_text_config()     -> no message

Solution

Write to model.config.get_text_config() at each site that mirrors a token id for that purpose. get_text_config() returns self for a non-composite config, so this is a no-op for text models and needs no version guard: the method predates our transformers>=4.56.2 floor.

The generation config is untouched, since it is not composite.

Changes

  • Write the mirrored pad token id to the text config in the SFT, DPO, KTO, GRPO, RLOO, Distillation and Reward trainers
  • Write the mirrored eos token id to the text config in the SFT and Reward trainers

CC: @qgallouedec and @lewtun for visibility.


Note

Low Risk
Mechanical API alignment with Transformers token sync; behavior is unchanged for non-composite models and fixes VLM/composite misalignment rather than altering training logic.

Overview
Mirrors tokenizer pad and eos token IDs onto model.config.get_text_config() instead of the top-level model.config everywhere TRL sets them at trainer init (and in clone_chat_template for eos).

This matches Hugging Face Transformers’ token alignment after transformers#48847: composite / VLM configs keep special token IDs on the text sub-config, so writing only to the root config no longer satisfies what Trainer compares and VLMs could log spurious “Updated tokens” realignment. generation_config is unchanged; get_text_config() is a no-op for plain causal LMs (returns self).

Touches core trainers (SFT, DPO, KTO, GRPO, RLOO, Distillation, Reward) and experimental trainers (async distillation/GRPO, CPO, online DPO, SDPO, SDFT, SSD, TPO, IW-OPD).

Reviewed by Cursor Bugbot for commit 29c44c3. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@albertvillanova

Copy link
Copy Markdown
Member Author

CI error with minimum versions is unrelated; see:

@albertvillanova
albertvillanova force-pushed the align-token-ids-on-text-config branch from 0507bef to c3c2597 Compare September 22, 2026 04:50
@albertvillanova
albertvillanova force-pushed the align-token-ids-on-text-config branch from c3c2597 to 29c44c3 Compare September 23, 2026 06:25
@albertvillanova
albertvillanova removed this pull request from stack #7317 September 23, 2026 06:33
@albertvillanova
albertvillanova added this pull request to stack #7349 September 23, 2026 06:34
@albertvillanova

Copy link
Copy Markdown
Member Author

Merging this PR as analog to the already approved and merged #7318.

@albertvillanova
albertvillanova merged commit 3656aae into main Sep 23, 2026
11 checks passed
@albertvillanova
albertvillanova deleted the align-token-ids-on-text-config branch September 23, 2026 09:11
@albertvillanova albertvillanova added the 🐛 bug Something isn't working label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant