MCPcopy Create free account
hub / github.com/SooLab/CGFormer / add_memory_hooks

Method add_memory_hooks

bert/modeling_utils.py:111–118  ·  view source on GitHub ↗

Add a memory hook before and after each sub-module forward pass to record increase in memory consumption. Increase in memory consumption is stored in a `mem_rss_diff` attribute for each module and can be reset to zero with `model.reset_memory_hooks_state()`

(self)

Source from the content-addressed store, hash-verified

109 return None
110
111 def add_memory_hooks(self):
112 """ Add a memory hook before and after each sub-module forward pass to record increase in memory consumption.
113 Increase in memory consumption is stored in a `mem_rss_diff` attribute for each module and can be reset to zero with `model.reset_memory_hooks_state()`
114 """
115 for module in self.modules():
116 module.register_forward_pre_hook(self._hook_rss_memory_pre_forward)
117 module.register_forward_hook(self._hook_rss_memory_post_forward)
118 self.reset_memory_hooks_state()
119
120 def reset_memory_hooks_state(self):
121 for module in self.modules():

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected