Skip to content

Commit 7f58fb9

Browse files
authored
Add assertion for no objects while hashing hf_config (#16930)
Signed-off-by: rzou <zou3519@gmail.com>
1 parent 30bc3e0 commit 7f58fb9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

vllm/config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import hashlib
77
import inspect
88
import json
9+
import re
910
import sys
1011
import textwrap
1112
import warnings
@@ -328,6 +329,8 @@ def compute_hash(self) -> str:
328329
factors.append(self.rope_theta)
329330
# hf_config can control how the model looks!
330331
factors.append(self.hf_config.to_json_string())
332+
str_factors = str(factors)
333+
assert_hashable(str_factors)
331334
return hashlib.sha256(str(factors).encode()).hexdigest()
332335

333336
def __init__(
@@ -4031,3 +4034,30 @@ def get_current_vllm_config() -> VllmConfig:
40314034
from vllm.config import VllmConfig
40324035
return VllmConfig()
40334036
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}")

0 commit comments

Comments
 (0)