Skip to content

Commit fe17871

Browse files
authored
[compile] Parse compile range cache keys as Range during cache loading. (vllm-project#30516)
Signed-off-by: zhxchen17 <zhxchen17@fb.com>
1 parent 783644e commit fe17871

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

vllm/compilation/backends.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,25 @@ def initialize_cache(
141141
# we use ast.literal_eval to parse the data
142142
# because it is a safe way to parse Python literals.
143143
# do not use eval(), it is unsafe.
144-
self.cache = ast.literal_eval(f.read())
144+
cache = ast.literal_eval(f.read())
145+
146+
def check_type(value, ty):
147+
if not isinstance(value, ty):
148+
raise TypeError(f"Expected {ty} but got {type(value)} for {value}")
149+
150+
def parse_key(key: Any) -> tuple[Range, int, str]:
151+
range_tuple, graph_index, compiler_name = key
152+
check_type(graph_index, int)
153+
check_type(compiler_name, str)
154+
if isinstance(range_tuple, tuple):
155+
start, end = range_tuple
156+
check_type(start, int)
157+
check_type(end, int)
158+
range_tuple = Range(start=start, end=end)
159+
check_type(range_tuple, Range)
160+
return range_tuple, graph_index, compiler_name
161+
162+
self.cache = {parse_key(key): value for key, value in cache.items()}
145163

146164
self.compiler.initialize_cache(
147165
cache_dir=cache_dir, disable_cache=disable_cache, prefix=prefix

0 commit comments

Comments
 (0)