feat: preserve token IDs on messages#448
Open
Hecate0821 wants to merge 1 commit intomainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds token-native trace support to EP messages without turning EP into an RL framework.
Current Design
eval_protocol.models.Messagenow has optionaltoken_ids: list[int] | None. This lets rollout processors preserve engine token IDs alongside message content and provider logprob metadata.The schema remains backward compatible:
logprobsdictionaries are still accepted unchanged.token_idsand flatlist[float]logprobs are set. In that case, lengths must match.SingleTurnRolloutProcessornow extracts token IDs from serialized provider logprobs when they are available:logprobs.content[].token_idlogprobs.token_ids[]Those IDs are stored on the assistant
Message.token_ids. If the provider does not expose token IDs, the field remains unset.Why
The cookbook async RL path is token-native only. Multi-turn RL cannot safely re-tokenize assistant text after rollout because BPE merges can cross turn boundaries and inference logprobs can become misaligned. EP needs a simple message-level carrier for token IDs so downstream training can consume traces without reconstructing tokens from text.
Tests / Checks
python3.11 -m pytest tests/test_rollout_logprobs.py tests/test_eval_protocol_import.py::TestRewardProtocolFunctionality::test_message_preserves_token_ids tests/test_eval_protocol_import.py::TestRewardProtocolFunctionality::test_message_rejects_misaligned_float_logprobspython3.11 -m ruff check eval_protocol/models.py eval_protocol/pytest/default_single_turn_rollout_process.py tests/test_rollout_logprobs.py tests/test_eval_protocol_import.pygit diff --checkNote: full
tests/test_eval_protocol_import.pycurrently has an unrelated failure inTestRewardProtocolImports.test_star_import_worksbecauseeval_protocol.adaptersdoes not exposeLangfuseAdapter.Related