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)
| 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(): |
nothing calls this directly
no test coverage detected