MCPcopy Index your code
hub / github.com/hpcaitech/ColossalAI / bind

Method bind

colossalai/fx/graph_module.py:37–55  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 6

recompileMethod · 0.95
_get_free_portMethod · 0.45
get_free_portFunction · 0.45
get_free_portFunction · 0.45
appFunction · 0.45
free_portFunction · 0.45

Calls 1

copyMethod · 0.45

Tested by

no test coverage detected