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

Method train

torch/nn/modules/module.py:2375–2395  ·  view source on GitHub ↗

r"""Set the module in training mode. This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`, etc. Args:

(self: T, mode: bool = True)

Source from the content-addressed store, hash-verified

2373 yield from module.named_modules(memo, submodule_prefix, remove_duplicate)
2374
2375 def train(self: T, mode: bool = True) -> T:
2376 r"""Set the module in training mode.
2377
2378 This has any effect only on certain modules. See documentations of
2379 particular modules for details of their behaviors in training/evaluation
2380 mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
2381 etc.
2382
2383 Args:
2384 mode (bool): whether to set training mode (``True``) or evaluation
2385 mode (``False``). Default: ``True``.
2386
2387 Returns:
2388 Module: self
2389 """
2390 if not isinstance(mode, bool):
2391 raise ValueError("training mode is expected to be boolean")
2392 self.training = mode
2393 for module in self.children():
2394 module.train(mode)
2395 return self
2396
2397 def eval(self: T) -> T:
2398 r"""Set the module in evaluation mode.

Callers 14

evalMethod · 0.95
_set_model_to_evalFunction · 0.45
update_bnFunction · 0.45
trainingMethod · 0.45
register_parametrizationFunction · 0.45
trainFunction · 0.45
verifyFunction · 0.45
find_mismatchFunction · 0.45
trainFunction · 0.45
testFunction · 0.45
mainFunction · 0.45

Calls 2

childrenMethod · 0.95
isinstanceFunction · 0.85

Tested by 1

trainFunction · 0.36