Repository navigation
[rl] Verifiers generation server: faster request path, required sampling params (4/10) - #5454
Conversation
02a2df0 to
1a3ab66
Compare
1a3ab66 to
7378cf6
Compare
| # Text, not one dict per token: 1.4x faster, and no GC pass every ~700 tokens. | ||
| # A finite Python float's repr is valid JSON; vLLM's logprobs are Python floats. | ||
| logprobs_content = ",".join( | ||
| f'{{"token":"token_id:{token_id}","logprob":{logprob!r}}}' | ||
| for token_id, logprob in zip( | ||
| completion.token_ids, completion.token_logprobs | ||
| ) | ||
| ) |
There was a problem hiding this comment.
this is creative. Was this tested for 131k context? does any other library do it? Would we extend that to router replay?
15db4c0 to
b5e3419
Compare
|
reply from claude:
|
b5e3419 to
c4649cf
Compare
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 1m 55s —— View job Approve (please add the missing "Summary (human-written)" section before merging) -- review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging -- the code keeps the same wire format, the speedups are backed by microbenchmarks, and the new required-field check turns a silent fallback to default sampling into a 400.
What this PR does. The Verifiers generation server checks prompt token ids with one C-level set(map(type, ...)) instead of a per-token Python generator, and no longer copies the list. It builds the per-token logprobs.content list as JSON text and splices it into the json.dumps output, so it no longer creates one dict per token. temperature, top_p and max_tokens are now required in sampling_params.
Example.
POST /inference/v1/generate {"token_ids": [10, 11], "sampling_params": {"stop_token_ids": [99], "torchtitan_group_id": 1}}
before: 200, sampled at temperature=0.8, max_tokens=100 (SamplingConfig defaults)
after: 400 "sampling_params must include ['max_tokens', 'temperature', 'top_p']"
Completion(token_ids=[31, 32], token_logprobs=[-0.1, -0.2])
before/after: ..."logprobs": {"content": [{"token": "token_id:31", "logprob": -0.1}, ...]}... (same bytes after parsing; pinned by the exact-payload test)
Must fix
- PR description -- there is no "Summary (human-written)" section from
.github/pull_request_template.md. Please add the 2-5 sentence author summary. The rest of the description matches the code.
Details
- Splice safety.
rpartition(json.dumps(placeholder))only matches the real placeholder. In any other JSON string value,"is escaped as\", so the quoted placeholder can't appear insiderequest_id(which comes from theX-Session-IDheader).finish_reasonis restricted tostop/lengthbefore this point, and the match takes the last occurrence anyway. - Dropping
zip(strict=True)is fine: line 233 already returns 500 when the lengths differ. {logprob!r}. The logprobs reach this code as Python floats:engine.py:500callslist(completion_output.logprobs.logprobs)withflat_logprobs=True.reprof a finite float (-0.1,1e-05,-1.5e+20) is valid JSON. Numpy scalars would print asnp.float64(...)and break the response, but this path never produces them.- No copy in
_validate_token_ids. Both callers pass lists from the freshly parsed request body, which nothing else holds, so aliasing them is safe. - Required sampling fields. The only in-repo client,
rollouter.py:316-319, always sets all three onVerifiersSamplingConfig. - Non-finite logprobs. These now fail in the client's JSON parse instead of its finiteness check. That is still a loud failure, so no extra guard is needed under the "no just-in-case checks" rule.
- Tests.
test_validate_token_idspins theboolrejection across the rewrite (type()vsisinstance). The sampling-config test guards against the silent fallback to defaults coming back. Both are cheap CPU tests.
Not verified: that Verifiers 0.4.0 forwards top_p/max_tokens verbatim (I didn't inspect the package), and the end-to-end GIL saving (the PR says it was estimated, not re-measured). A maintainer still needs to review.
… the trainable one's
…lo1/genserver-no-access-log
…/genserver-request-path
…lo1/genserver-no-access-log
…/genserver-request-path
|
Reply from claude: @claude review again |
|
Claude finished @felipemello1's task in 38s —— View job Approve (one item still open: add the "Summary (human-written)" section to the PR description) -- review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging -- the only code change since the last review is a comment deletion. Both maintainer comments are resolved. The one remaining item is in the PR description.
What changed since the last review. dd6fff4ec deletes the comment above _validate_token_ids. The other three commits (1e310855e, 4d329617c, 982fcf127) merge the base branch and don't touch this PR's hunks. The diff against felipemello1/genserver-no-access-log is otherwise the same code I approved before.
Must fix
- PR description -- still open from the last review: the body has no
## Summary (human-written)section from.github/pull_request_template.md. Please add the 2-5 sentence author summary.
Details
- Maintainer comment,
generation_server.py:267(scale, router replay, score centering, other libraries). The author answered it with a 1k/100k-token CPU microbenchmark. The parsed output is identical, and the speedup is about 1.5x at both sizes. Router replay and score centering don't change this response payload: it carries onlytoken_idsand per-token logprobs. The code agrees. The splice covers onlycompletion.token_idsandcompletion.token_logprobs(lines 268-272), so context length and expert rows never reach it. No maintainer pushed back on the answer. - Maintainer comment, "we can remove this comment" (the
type()vsisinstancenote). Fixed indd6fff4ec.test_validate_token_idskeeps the[1, True]case, so theboolrejection is still pinned. - Minor, not blocking. The comment at line 266 says "1.4x faster". The new benchmark reply measures 1.5x. Either number is fine.
Not verified: the end-to-end GIL saving (the description says it is estimated, not re-measured). A maintainer still needs to review.
TLDR: Token-id validation is 5.7x faster (~390 -> 68 us per 7k-token prompt) and the response build 1.4x faster with no GC passes. Together they were ~42% of the controller thread's GIL-holding samples at 10 nodes, so its GIL-holding time drops by ~25% (estimated from microbenchmarks, not re-measured).
temperature,top_pandmax_tokensare now required (the rollouter always sends them).Stack (10 PRs, merge bottom-up; this PR is in bold)
The four HTTP generation PRs left this stack. They wait on the generator/router design discussion.
Problem
Solution
_validate_token_idschecksset(map(type, token_ids)) <= {int}and returns the list without a copy.temperature,top_pandmax_tokensare now required. A missing one used to sample at the defaults (temperature 0.8, 100 tokens); the rollouter always sends all three.Results
You may ask: why not orjson? It's a new dependency, and the request decode it would also speed up (13.4%) is smaller than either fix here.
NOTE: a non-finite logprob now fails the client's JSON parse instead of its finiteness check; the request fails either way.
Test plan
pytest tests/rl/unit_tests/cpu/test_verifiers.py -k "generation_server or validate_token_ids or sampling_config"test_parse_sampling_config_requires_temperature_top_p_max_tokensfails on main;test_validate_token_idsand the exact-payload assertion pin unchanged behavior.