-
Notifications
You must be signed in to change notification settings - Fork 417
Fix interception proxy capturing 0 token ids on current vLLM #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+65
−15
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """The interception proxy must capture per-token ids from a vLLM logprobs response. | ||
|
|
||
| vLLM with ``--return-tokens-as-token-ids`` encodes the id in the ``token`` field as | ||
| ``"token_id:<int>"`` (no separate ``token_id`` key), which the capture must parse so | ||
| GRPO trains on real token ids.""" | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| # Make ``envs/`` importable when running from the repository root. | ||
| _REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) | ||
| if _REPO_ROOT not in sys.path: | ||
| sys.path.insert(0, _REPO_ROOT) | ||
| _ENVS_DIR = os.path.join(_REPO_ROOT, "envs") | ||
| if _ENVS_DIR not in sys.path: | ||
| sys.path.insert(0, _ENVS_DIR) | ||
|
|
||
| from opencode_env.sandbox.interception import _build_turn_record | ||
|
|
||
|
|
||
| def _response(content): | ||
| return {"choices": [{"finish_reason": "stop", "logprobs": {"content": content}}]} | ||
|
|
||
|
|
||
| def test_captures_ids_from_vllm_token_id_prefix(): | ||
| # vLLM --return-tokens-as-token-ids: id lives in the ``token`` field as "token_id:N". | ||
| content = [ | ||
| {"token": "token_id:15339", "logprob": -0.1}, | ||
| {"token": "token_id:1917", "logprob": -0.2}, | ||
| ] | ||
| rec = _build_turn_record( | ||
| turn_idx=0, request_body={}, response_json=_response(content), latency_s=0.0 | ||
| ) | ||
| assert rec.completion_token_ids == [15339, 1917] | ||
| assert rec.per_token_logps == [-0.1, -0.2] | ||
|
|
||
|
|
||
| def test_plain_openai_has_logprobs_but_no_ids(): | ||
| # A plain OpenAI response (no ids) still yields logprobs, just no token ids. | ||
| content = [{"token": "hi", "logprob": -0.3}] | ||
| rec = _build_turn_record( | ||
| turn_idx=0, request_body={}, response_json=_response(content), latency_s=0.0 | ||
| ) | ||
| assert rec.completion_token_ids == [] | ||
| assert rec.per_token_logps == [-0.3] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy token_id key support dropped
Medium Severity
_build_turn_recordonly parses ids from atokenvalue with thetoken_id:prefix and no longer reads a separatetoken_idfield. Builds that still emit that key end up with emptycompletion_token_ids, which breaks GRPO training on those traces. The PR claims both formats are supported, but the legacy path and its test are missing.Additional Locations (1)
tests/envs/test_interception_capture.py#L30-L51Reviewed by Cursor Bugbot for commit d6227f3. Configure here.