A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 13:30 UTC
Add assertion for no objects while hashing hf_config (#16930)
Signed-off-by: rzou <zou3519@gmail.com>
Richard Zou committed
Apr 22, 2025 at 12:32 UTC
7f58fb9718f4d6ed370b0f595d297c8c90fc11fa
1 file changed
+30
vllm/config.py
+30
@@ -6,6 +6,7 @@ import enum
6
import hashlib
7
import inspect
8
import json
9
+import re
10
import sys
11
import textwrap
12
import warnings
@@ -328,6 +329,8 @@ class ModelConfig:
329
factors.append(self.rope_theta)
330
# hf_config can control how the model looks!
331
factors.append(self.hf_config.to_json_string())
332
+ str_factors = str(factors)
333
+ assert_hashable(str_factors)
334
return hashlib.sha256(str(factors).encode()).hexdigest()
335
336
def __init__(
@@ -4031,3 +4034,30 @@ def get_current_vllm_config() -> VllmConfig:
4034
from vllm.config import VllmConfig
4035
return VllmConfig()
4036
return _current_vllm_config
4037
+
4038
+
4039
+def contains_object_print(text):
4040
+ """
4041
+ Check if the text looks like a printed Python object, e.g.
4042
+ contains any substring matching the pattern: "at 0xFFFFFFF>"
4043
+ We match against 0x followed by 2-16 hex chars (there's
4044
+ a max of 16 on a 64 bit system).
4045
+
4046
+ Args:
4047
+ text (str): The text to check
4048
+
4049
+ Returns:
4050
+ bool: True if a match is found, False otherwise
4051
+ """
4052
+ pattern = r'at 0x[a-fA-F0-9]{2,16}>'
4053
+ match = re.search(pattern, text)
4054
+ return match is not None
4055
+
4056
+
4057
+def assert_hashable(text):
4058
+ if not contains_object_print(text):
4059
+ return True
4060
+ raise AssertionError(
4061
+ f"vLLM tried to hash some configs that may have Python objects ids "
4062
+ f"in them. This is a bug, please file an issue. "
4063
+ f"Text being hashed: {text}")