MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / train_mode

Function train_mode

k_diffusion/utils.py:72–80  ·  view source on GitHub ↗

A context manager that places a model into training mode and restores the previous mode on exit.

(model, mode=True)

Source from the content-addressed store, hash-verified

70
71@contextmanager
72def train_mode(model, mode=True):
73 """A context manager that places a model into training mode and restores
74 the previous mode on exit."""
75 modes = [module.training for module in model.modules()]
76 try:
77 yield model.train(mode)
78 finally:
79 for i, module in enumerate(model.modules()):
80 module.training = modes[i]
81
82
83def eval_mode(model):

Callers 1

eval_modeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected