Commit 8f8c66d
committed
[Core] Add a random suffix to frontend-provided request IDs
Since vllm-project#9550 and vllm-project#10968 we support client's supplying a custom
request ID. The motivation for this is that it can be very helpful
when you need to correlate vLLM logs with logs of a related service.
Since the request ID is used ubiquitously across vLLM as a unique
key, it obviously is problematic if we ever have multiple in-flight
requests using the same client-provided request ID.
We saw this happening recently when `vllm serve bench` started
including a request ID and the request IDs from multiple concurrent
instances caused collisions. See vllm-project#27723
We try to guard against request ID collisions currently in the
frontend in OutputProcessor:
```
def add_request(...):
if request_id in self.request_states:
raise ValueError(f"Request id {request_id} already running.")
```
however, this is not always effective:
1) We can have abort race conditions where a request is no longer
tracked by the frontend, but still not completed in the engine.
See vllm-project#15326 for an attempt to fix this.
2) We can have async scheduling race conditions where a request
ID is removed from the output processor and being scheduled
while the older request with that ID is still being completed
by the model runner. See vllm-project#29355
3) With P/D, a request will continue to be tracked by the prefill
engine long after the prefill request has been completed in
the frontend, while we wait for the decode side to fetch the
KV blocks. See vllm-project#20139
Let's instead ensure we use a unique request ID internally, even
when a client provides a custom request ID. We can do this simply
by appending a short random suffix to any request ID provided
by the frontend.
A full 32 character random UUID would be overkill as a suffix,
so how many random characters would be sufficient? 8 characters
gives us 32 bits of entropy, or 16^8 possible prefixes.
Using the collision probability approximation from
https://preshing.com/20110504/hash-collision-probabilities:
N = 16^8 and k is the number of generated suffixes, then the
probability of collision is (k^2)/(2N), so If a client somehow
caused vLLM to hold 10k requests that reuse the same client-provided
ID, then there would be a 1.16% chance of collision:
```
>>> (k**2)/(2*N)
0.011641532182693481
```
That seems (super good enough)[https://hownot2.com/products/hownot2-super-good-enough-t-shirt].
The key changes to support this are:
1. `InputProcessor.process_inputs()` - we add some randomness to the
request ID just before creating an `EngineCoreRequest`, and store both
the random "internal" request ID (as `request_id`) and the supplied
"external" request ID (as `external_req_id`) in the
`EngineCoreRequest`.
2. `RequestState.make_request_output()` - we ensure that
`RequestOutput.request_id` continues to be the external request ID
(for backwards compat) and add `internal_request_id`.
3. `OutputProcessor.abort_requests()` - we make `OutputProcessor`
track a mapping from external request ID to internal request IDs, so
`abort_requests()` can abort based on either ID.
4. `AsyncLLM` - we use `RequestOutputCollector` to track the internal
request ID, so we can use the internal ID to abort an in-progress
request. We also add an `internal` boolean flag to `abort()` so API
users can abort based on either ID.
5. `ParentRequest` - in the case of parallel sampling, we need to
track both the internal and external ID for the later creation of
`RequestOutput` aggregating the child outputs.
We need to ensure we track the external->internal request ID
mapping because abort() will be supplied an external request ID.
In the case where an external request ID maps to multiple running
requests, we assume the caller requires all of those requests
to be aborted. The caller can use EngineCoreRequest.request_id
as the request ID if they want to be more specific.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>1 parent 92c35ab commit 8f8c66d
File tree
23 files changed
+317
-159
lines changed- tests
- detokenizer
- entrypoints/openai
- tokenizers_
- v1
- engine
- kv_connector/unit
- vllm
- entrypoints
- openai
- v1/engine
23 files changed
+317
-159
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
394 | 396 | | |
395 | 397 | | |
396 | 398 | | |
| |||
662 | 664 | | |
663 | 665 | | |
664 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
665 | 670 | | |
| 671 | + | |
666 | 672 | | |
667 | 673 | | |
668 | 674 | | |
| |||
689 | 695 | | |
690 | 696 | | |
691 | 697 | | |
692 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
693 | 701 | | |
694 | 702 | | |
695 | 703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
551 | | - | |
| 551 | + | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | | - | |
| 51 | + | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | | - | |
| 55 | + | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments