r"""Sets training mode of all the modules within this module (including itself) to ``mode``. This effectively sets the ``training`` attributes of those modules to ``mode``, but only has effect on certain modules (e.g. :class:`~.BatchNorm2d`, :class:`~.Dropout`, :class:`~.Obse
(self, mode: bool = True, recursive: bool = True)
| 390 | param.grad.reset_zero() |
| 391 | |
| 392 | def train(self, mode: bool = True, recursive: bool = True) -> None: |
| 393 | r"""Sets training mode of all the modules within this module (including itself) to |
| 394 | ``mode``. This effectively sets the ``training`` attributes of those modules |
| 395 | to ``mode``, but only has effect on certain modules (e.g. |
| 396 | :class:`~.BatchNorm2d`, :class:`~.Dropout`, :class:`~.Observer`) |
| 397 | |
| 398 | Args: |
| 399 | mode: the training mode to be set on modules. |
| 400 | recursive: whether to recursively call submodules' ``train()``. |
| 401 | """ |
| 402 | if not recursive: |
| 403 | self.training = mode |
| 404 | return |
| 405 | |
| 406 | def fn(module: Module) -> None: |
| 407 | module.train(mode, recursive=False) |
| 408 | |
| 409 | self.apply(fn) |
| 410 | |
| 411 | def eval(self) -> None: |
| 412 | r"""Sets training mode of all the modules within this module (including itself) to |