"""Hook to save the compiled bytecode for direct execution."""
ifold_codeisnotself.original_code_object:
ifold_codeisnotself.original_code_object():
return
# code borrowed from https://github.com/thuml/depyf/blob/f4ad79fadee27ea113b4c75202db1eb1a11c0dbc/depyf/explain/enable_debugging.py#L25
frame=sys._getframe()
...
...
@@ -114,7 +179,7 @@ class TorchCompileWrapperWithCustomDispatcher:
ifframe.f_locals["self"]isnotself:
return
self.compiled_codes.append(new_code)
self._compiled_bytecode=new_code
path=self.vllm_config.compile_debug_dump_path()
ifpath:
...
...
@@ -153,16 +218,21 @@ class TorchCompileWrapperWithCustomDispatcher:
raiseRuntimeError(msg)
@contextmanager
defdispatch_to_code(self,index:int):
"""Context manager to dispatch to the compiled code.
def_dispatch_to_compiled_code(self):
# noqa: E501
"""
Context manager to dispatch to internally compiled code for torch<2.8.
Why does this work? Because Dynamo guarantees that the compiled
bytecode has exactly the same arguments, cell variables, and free
variables as the original code. Therefore we can directly switch
the code object in the function and call it.
See https://dev-discuss.pytorch.org/t/what-is-the-relationship-requirement-among-original-bytecode-transformed-bytecode-and-bytecode-returned-by-hooks-in-dynamo/1693/7
See https://dev-discuss.pytorch.org/t/what-is-the-relationship-requirement-among-original-bytecode-transformed-bytecode-and-bytecode-returned-by-hooks-in-dynamo/1693/7 for more details.