Bind function needed for correctly execute gm forward We need to bind checkpoint functions and saved_tensor_hooks functions to gm so that we could correctly execute gm forward Args: ckpt_def (_type_): definition before the forward function
(self, ckpt_def, globals)
| 35 | super().__init__(root, graph, class_name) |
| 36 | |
| 37 | def bind(self, ckpt_def, globals): |
| 38 | """Bind function needed for correctly execute gm forward |
| 39 | |
| 40 | We need to bind checkpoint functions and saved_tensor_hooks functions |
| 41 | to gm so that we could correctly execute gm forward |
| 42 | |
| 43 | Args: |
| 44 | ckpt_def (_type_): definition before the forward function |
| 45 | globals (_type_): global variables |
| 46 | """ |
| 47 | |
| 48 | ckpt_code = "\n".join(ckpt_def) |
| 49 | globals_copy = globals.copy() |
| 50 | _exec_with_source(ckpt_code, globals_copy) |
| 51 | func_list = [func for func in globals_copy.keys() if "checkpoint" in func or "pack" in func] |
| 52 | for func in func_list: |
| 53 | tmp_func = globals_copy[func] |
| 54 | setattr(self, func, tmp_func.__get__(self, self.__class__)) |
| 55 | del globals_copy[func] |
| 56 | |
| 57 | def recompile(self) -> PythonCode: |
| 58 | """ |
no test coverage detected