22# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
44import ast
5+ import logging
56import dataclasses
67import hashlib
78import json
@@ -535,9 +536,17 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
535536 config_hash = vllm_config .compute_hash ()
536537 compiler_hash = self .compiler_manager .compute_hash (vllm_config )
537538 forward_code_files = list (sorted (self .compilation_config .traced_files ))
539+ class _LazyJoin :
540+ def __init__ (self , seq : list [str ], sep : str = "\n " ):
541+ self .seq = seq
542+ self .sep = sep
543+
544+ def __str__ (self ) -> str :
545+ return self .sep .join (self .seq )
546+
538547 logger .debug (
539548 "Traced files (to be considered for compilation cache):\n %s" ,
540- " \n " . join (forward_code_files ),
549+ _LazyJoin (forward_code_files ),
541550 )
542551 hash_content = []
543552 for filepath in forward_code_files :
@@ -562,7 +571,7 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
562571 # graph.
563572 factors = [env_hash , config_hash , code_hash , compiler_hash ]
564573 # Use SHA-256 for cache key hashing to be consistent across
565- # compute_hash functions. Truncate for a short, stable dir name.
574+ # compute_hash functions. Truncate for a short cache dir name.
566575 hash_key = hashlib .sha256 (str (factors ).encode ()).hexdigest ()[:10 ]
567576 cache_dir = os .path .join (
568577 envs .VLLM_CACHE_ROOT , "torch_compile_cache" , hash_key
@@ -604,27 +613,36 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
604613
605614 # Persist and log only hash-relevant factors together.
606615 try :
607- logger .debug (
608- "Compile env factors (raw):\n %s\n Vllm config hash: %s" ,
609- pprint .pformat (env_factors , width = 120 ),
610- config_hash ,
611- )
612- meta_path = os .path .join (local_cache_dir , "cache_key_factors.json" )
613- with open (meta_path , "w" ) as f :
614- json .dump (
615- {
616- "env" : env_factors , # raw factors used for env_hash
617- "config_hash" : config_hash ,
618- "code_hash" : code_hash ,
619- "compiler_hash" : compiler_hash ,
620- },
621- f ,
622- indent = 2 ,
623- sort_keys = True ,
616+ if logger .isEnabledFor (logging .DEBUG ):
617+ logger .debug (
618+ "Compile env factors (raw):\n %s\n Vllm config hash: %s" ,
619+ pprint .pformat (env_factors , width = 120 ),
620+ config_hash ,
624621 )
622+ meta_path = os .path .join (local_cache_dir , "cache_key_factors.json" )
623+ if not os .path .exists (meta_path ):
624+ with open (meta_path , "w" ) as f :
625+ json .dump (
626+ {
627+ "env" : env_factors , # raw factors used for env_hash
628+ "config_hash" : config_hash ,
629+ "code_hash" : code_hash ,
630+ "compiler_hash" : compiler_hash ,
631+ },
632+ f ,
633+ indent = 2 ,
634+ sort_keys = True ,
635+ )
625636 except Exception :
626637 # Best-effort only; metadata write failures are non-fatal.
627- pass
638+ logger .warning (
639+ (
640+ "Could not write compile cache metadata at %s; continuing without "
641+ "metadata. Compiled cache remains valid; diagnostics may be limited."
642+ ),
643+ local_cache_dir ,
644+ exc_info = True ,
645+ )
628646
629647 # when dynamo calls the backend, it means the bytecode
630648 # transform and analysis are done
@@ -731,4 +749,4 @@ def copy_and_call(*args):
731749 list_args [index ] = static_tensor
732750 return self .split_gm (* list_args )
733751
734- return copy_and_call
752+ return copy_and_call
0 commit comments