Register hooks to the trainer. The hooks are executed in the order they are registered. Args: hooks (list[Optional[HookBase]]): list of hooks
(self, hooks)
| 98 | self._hooks = [] |
| 99 | |
| 100 | def register_hooks(self, hooks): |
| 101 | """ |
| 102 | Register hooks to the trainer. The hooks are executed in the order |
| 103 | they are registered. |
| 104 | |
| 105 | Args: |
| 106 | hooks (list[Optional[HookBase]]): list of hooks |
| 107 | """ |
| 108 | hooks = [h for h in hooks if h is not None] |
| 109 | for h in hooks: |
| 110 | assert isinstance(h, HookBase) |
| 111 | # To avoid circular reference, hooks and trainer cannot own each other. |
| 112 | # This normally does not matter, but will cause memory leak if the |
| 113 | # involved objects contain __del__: |
| 114 | # See http://engineering.hearsaysocial.com/2013/06/16/circular-references-in-python/ |
| 115 | h.trainer = weakref.proxy(self) |
| 116 | self._hooks.extend(hooks) |
| 117 | |
| 118 | def train(self, start_iter: int, max_iter: int): |
| 119 | """ |
no outgoing calls
no test coverage detected