Skip to content

Commit db29061

Browse files
authored
[Misc] Streamline unique id generation (vllm-project#29375)
Signed-off-by: Nick Hill <nhill@redhat.com>
1 parent 67fc16c commit db29061

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

vllm/entrypoints/openai/protocol.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class ChatCompletionRequest(OpenAIBaseModel):
661661
),
662662
)
663663
request_id: str = Field(
664-
default_factory=lambda: f"{random_uuid()}",
664+
default_factory=random_uuid,
665665
description=(
666666
"The request_id related to this request. If the caller does "
667667
"not set it, a random_uuid will be generated. This id is used "
@@ -1078,7 +1078,7 @@ class CompletionRequest(OpenAIBaseModel):
10781078
),
10791079
)
10801080
request_id: str = Field(
1081-
default_factory=lambda: f"{random_uuid()}",
1081+
default_factory=random_uuid,
10821082
description=(
10831083
"The request_id related to this request. If the caller does "
10841084
"not set it, a random_uuid will be generated. This id is used "
@@ -1375,7 +1375,7 @@ class EmbeddingCompletionRequest(OpenAIBaseModel):
13751375
),
13761376
)
13771377
request_id: str = Field(
1378-
default_factory=lambda: f"{random_uuid()}",
1378+
default_factory=random_uuid,
13791379
description=(
13801380
"The request_id related to this request. If the caller does "
13811381
"not set it, a random_uuid will be generated. This id is used "
@@ -1470,7 +1470,7 @@ class EmbeddingChatRequest(OpenAIBaseModel):
14701470
),
14711471
)
14721472
request_id: str = Field(
1473-
default_factory=lambda: f"{random_uuid()}",
1473+
default_factory=random_uuid,
14741474
description=(
14751475
"The request_id related to this request. If the caller does "
14761476
"not set it, a random_uuid will be generated. This id is used "
@@ -1892,7 +1892,7 @@ class ClassificationCompletionRequest(OpenAIBaseModel):
18921892
),
18931893
)
18941894
request_id: str = Field(
1895-
default_factory=lambda: f"{random_uuid()}",
1895+
default_factory=random_uuid,
18961896
description=(
18971897
"The request_id related to this request. If the caller does "
18981898
"not set it, a random_uuid will be generated. This id is used "
@@ -1983,7 +1983,7 @@ class ClassificationChatRequest(OpenAIBaseModel):
19831983
)
19841984

19851985
request_id: str = Field(
1986-
default_factory=lambda: f"{random_uuid()}",
1986+
default_factory=random_uuid,
19871987
description=(
19881988
"The request_id related to this request. If the caller does "
19891989
"not set it, a random_uuid will be generated. This id is used "
@@ -3094,7 +3094,7 @@ class TranslationResponseVerbose(OpenAIBaseModel):
30943094
####### Tokens IN <> Tokens OUT #######
30953095
class GenerateRequest(BaseModel):
30963096
request_id: str = Field(
3097-
default_factory=lambda: f"{random_uuid()}",
3097+
default_factory=random_uuid,
30983098
description=(
30993099
"The request_id related to this request. If the caller does "
31003100
"not set it, a random_uuid will be generated. This id is used "
@@ -3151,7 +3151,7 @@ class GenerateResponseChoice(BaseModel):
31513151

31523152
class GenerateResponse(BaseModel):
31533153
request_id: str = Field(
3154-
default_factory=lambda: f"{random_uuid()}",
3154+
default_factory=random_uuid,
31553155
description=(
31563156
"The request_id related to this request. If the caller does "
31573157
"not set it, a random_uuid will be generated. This id is used "

vllm/entrypoints/openai/serving_engine.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,12 @@ def _base_request_id(
13491349
raw_request: Request | None, default: str | None = None
13501350
) -> str | None:
13511351
"""Pulls the request id to use from a header, if provided"""
1352-
default = default or random_uuid()
1353-
if raw_request is None:
1354-
return default
1352+
if raw_request is not None and (
1353+
(req_id := raw_request.headers.get("X-Request-Id")) is not None
1354+
):
1355+
return req_id
13551356

1356-
return raw_request.headers.get("X-Request-Id", default)
1357+
return random_uuid() if default is None else default
13571358

13581359
@staticmethod
13591360
def _get_data_parallel_rank(raw_request: Request | None) -> int | None:

vllm/utils/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ def __dir__() -> list[str]:
5252
STR_FLASH_ATTN_VAL: str = "FLASH_ATTN"
5353
STR_INVALID_VAL: str = "INVALID"
5454

55+
MASK_64_BITS = (1 << 64) - 1
56+
5557

5658
def random_uuid() -> str:
57-
return str(uuid.uuid4().hex)
59+
return f"{uuid.uuid4().int & MASK_64_BITS:016x}" # 16 hex chars
5860

5961

6062
def length_from_prompt_token_ids_or_embeds(

0 commit comments

Comments
 (0)