MCPcopy
hub / github.com/Stability-AI/generative-models / ema_scope

Method ema_scope

sgm/models/diffusion.py:177–189  ·  view source on GitHub ↗
(self, context=None)

Source from the content-addressed store, hash-verified

175
176 @contextmanager
177 def ema_scope(self, context=None):
178 if self.use_ema:
179 self.model_ema.store(self.model.parameters())
180 self.model_ema.copy_to(self.model)
181 if context is not None:
182 print(f"{context}: Switched to EMA weights")
183 try:
184 yield None
185 finally:
186 if self.use_ema:
187 self.model_ema.restore(self.model.parameters())
188 if context is not None:
189 print(f"{context}: Restored training weights")
190
191 def instantiate_optimizer_from_config(self, params, lr, cfg):
192 return get_obj_from_str(cfg["target"])(

Callers 5

log_imagesMethod · 0.95
do_sampleFunction · 0.45
do_img2imgFunction · 0.45
do_sampleFunction · 0.45
do_img2imgFunction · 0.45

Calls 3

storeMethod · 0.80
copy_toMethod · 0.80
restoreMethod · 0.80

Tested by

no test coverage detected