MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / train

Method train

imperative/python/megengine/module/module.py:392–409  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

evalMethod · 0.95
recursive_backup_statsFunction · 0.45
fnMethod · 0.45
train_funcFunction · 0.45
train_funFunction · 0.45
runnerFunction · 0.45
run_frozen_bnFunction · 0.45
train_bnFunction · 0.45
test_frozen_bn_no_affineFunction · 0.45
test_module_apiFunction · 0.45
test_qat_convbn2dFunction · 0.45

Calls 1

applyMethod · 0.95

Tested by 15

train_funcFunction · 0.36
train_funFunction · 0.36
runnerFunction · 0.36
run_frozen_bnFunction · 0.36
train_bnFunction · 0.36
test_frozen_bn_no_affineFunction · 0.36
test_module_apiFunction · 0.36
test_qat_convbn2dFunction · 0.36
test_qat_convFunction · 0.36