22# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
44import ast
5+ import logging
56import dataclasses
67import hashlib
78import json
@@ -531,9 +532,17 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
531532 config_hash = vllm_config .compute_hash ()
532533 compiler_hash = self .compiler_manager .compute_hash (vllm_config )
533534 forward_code_files = list (sorted (self .compilation_config .traced_files ))
535+ class _LazyJoin :
536+ def __init__ (self , seq : list [str ], sep : str = "\n " ):
537+ self .seq = seq
538+ self .sep = sep
539+
540+ def __str__ (self ) -> str :
541+ return self .sep .join (self .seq )
542+
534543 logger .debug (
535544 "Traced files (to be considered for compilation cache):\n %s" ,
536- " \n " . join (forward_code_files ),
545+ _LazyJoin (forward_code_files ),
537546 )
538547 hash_content = []
539548 for filepath in forward_code_files :
@@ -558,7 +567,7 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
558567 # graph.
559568 factors = [env_hash , config_hash , code_hash , compiler_hash ]
560569 # Use SHA-256 for cache key hashing to be consistent across
561- # compute_hash functions. Truncate for a short, stable dir name.
570+ # compute_hash functions. Truncate for a short cache dir name.
562571 hash_key = hashlib .sha256 (str (factors ).encode ()).hexdigest ()[:10 ]
563572 cache_dir = os .path .join (
564573 envs .VLLM_CACHE_ROOT , "torch_compile_cache" , hash_key
@@ -600,27 +609,36 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
600609
601610 # Persist and log only hash-relevant factors together.
602611 try :
603- logger .debug (
604- "Compile env factors (raw):\n %s\n Vllm config hash: %s" ,
605- pprint .pformat (env_factors , width = 120 ),
606- config_hash ,
607- )
608- meta_path = os .path .join (local_cache_dir , "cache_key_factors.json" )
609- with open (meta_path , "w" ) as f :
610- json .dump (
611- {
612- "env" : env_factors , # raw factors used for env_hash
613- "config_hash" : config_hash ,
614- "code_hash" : code_hash ,
615- "compiler_hash" : compiler_hash ,
616- },
617- f ,
618- indent = 2 ,
619- sort_keys = True ,
612+ if logger .isEnabledFor (logging .DEBUG ):
613+ logger .debug (
614+ "Compile env factors (raw):\n %s\n Vllm config hash: %s" ,
615+ pprint .pformat (env_factors , width = 120 ),
616+ config_hash ,
620617 )
618+ meta_path = os .path .join (local_cache_dir , "cache_key_factors.json" )
619+ if not os .path .exists (meta_path ):
620+ with open (meta_path , "w" ) as f :
621+ json .dump (
622+ {
623+ "env" : env_factors , # raw factors used for env_hash
624+ "config_hash" : config_hash ,
625+ "code_hash" : code_hash ,
626+ "compiler_hash" : compiler_hash ,
627+ },
628+ f ,
629+ indent = 2 ,
630+ sort_keys = True ,
631+ )
621632 except Exception :
622633 # Best-effort only; metadata write failures are non-fatal.
623- pass
634+ logger .warning (
635+ (
636+ "Could not write compile cache metadata at %s; continuing without "
637+ "metadata. Compiled cache remains valid; diagnostics may be limited."
638+ ),
639+ local_cache_dir ,
640+ exc_info = True ,
641+ )
624642
625643 # when dynamo calls the backend, it means the bytecode
626644 # transform and analysis are done
@@ -727,4 +745,4 @@ def copy_and_call(*args):
727745 list_args [index ] = static_tensor
728746 return self .split_gm (* list_args )
729747
730- return copy_and_call
748+ return copy_and_call
0 commit comments