|
6 | 6 | import hashlib |
7 | 7 | import inspect |
8 | 8 | import json |
| 9 | +import re |
9 | 10 | import sys |
10 | 11 | import textwrap |
11 | 12 | import warnings |
@@ -328,6 +329,8 @@ def compute_hash(self) -> str: |
328 | 329 | factors.append(self.rope_theta) |
329 | 330 | # hf_config can control how the model looks! |
330 | 331 | factors.append(self.hf_config.to_json_string()) |
| 332 | + str_factors = str(factors) |
| 333 | + assert_hashable(str_factors) |
331 | 334 | return hashlib.sha256(str(factors).encode()).hexdigest() |
332 | 335 |
|
333 | 336 | def __init__( |
@@ -4031,3 +4034,30 @@ def get_current_vllm_config() -> VllmConfig: |
4031 | 4034 | from vllm.config import VllmConfig |
4032 | 4035 | return VllmConfig() |
4033 | 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}") |
0 commit comments