From ed404d9ae99cd6615e21e36c805e722a838c096b Mon Sep 17 00:00:00 2001 From: youkaichao Date: Tue, 21 Jan 2025 16:20:28 +0800 Subject: [PATCH] fix no cache dir case Signed-off-by: youkaichao --- vllm/compilation/wrapper.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/vllm/compilation/wrapper.py b/vllm/compilation/wrapper.py index a3ab167353912..dc1464a144130 100644 --- a/vllm/compilation/wrapper.py +++ b/vllm/compilation/wrapper.py @@ -86,22 +86,24 @@ def bytecode_hook(self, old_code: CodeType, new_code: CodeType): self.compiled_codes.append(new_code) local_cache_dir = self.vllm_config.compilation_config.local_cache_dir - decompiled_file = os.path.join(local_cache_dir, "transformed_code.py") - if not os.path.exists(decompiled_file): - try: - # usually the decompilation will succeed for most models, as - # we guarantee a full-graph compilation in Dynamo. - # but there's no 100% guarantee, since decompliation is not a - # reversible process. - import depyf - src = depyf.decompile(new_code) - with open(decompiled_file, "w") as f: - f.write(src) - - logger.info("Dynamo transformed code saved to %s", - decompiled_file) - except Exception: - pass + if isinstance(local_cache_dir, str): + decompiled_file = os.path.join(local_cache_dir, + "transformed_code.py") + if not os.path.exists(decompiled_file): + try: + # usually the decompilation will succeed for most models, + # as we guarantee a full-graph compilation in Dynamo. + # but there's no 100% guarantee, since decompliation is + # not a reversible process. + import depyf + src = depyf.decompile(new_code) + with open(decompiled_file, "w") as f: + f.write(src) + + logger.info("Dynamo transformed code saved to %s", + decompiled_file) + except Exception: + pass if self.vllm_config.compilation_config.use_cudagraph and \ "update" in new_code.co_names: