MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / ZoeScheduler

Class ZoeScheduler

trainer/scheduler.py:10–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class ZoeScheduler:
11
12 def get_snr(self, timesteps):
13 alphas_cumprod = self.alphas_cumprod[timesteps]
14 sigma_power = 1 - alphas_cumprod
15 return alphas_cumprod / sigma_power
16
17 def get_min_snr_weight(self, timesteps, gamma: float = 5.0):
18 """the original min snr weighting in paper
19 https://arxiv.org/abs/2303.09556."""
20 snr = self.get_snr(timesteps)
21 min_snr_gamma = torch.min(snr, torch.ones_like(snr) * gamma)
22 if self.config.prediction_type == 'epsilon':
23 return min_snr_gamma / (snr + 1e-8)
24 elif self.config.prediction_type == 'sample':
25 return min_snr_gamma
26 elif self.config.prediction_type == 'v_prediction':
27 return min_snr_gamma / (snr + 1)
28
29 def get_min_snr_weight_modified(self,
30 timesteps,
31 gamma: float = 5.0,
32 min_weight: float = 0.01):
33 """modified loss weighting, so that the weighting at zero snr is not
34 zero the original min snr weighting in paper
35 https://arxiv.org/abs/2303.09556."""
36 snr = self.get_snr(timesteps)
37 min_snr_gamma = torch.min(snr, torch.ones_like(snr) * gamma)
38 if self.config.prediction_type == 'epsilon':
39 return torch.max(min_snr_gamma / (snr + 1e-8), min_weight)
40 elif self.config.prediction_type == 'sample':
41 return torch.max(min_snr_gamma, min_weight)
42 elif self.config.prediction_type == 'v_prediction':
43 return torch.max(min_snr_gamma / (snr + 1), min_weight)
44
45 def get_min_snr_weight_cogvideo(self, timesteps):
46 """modified loss weighting, so that the weighting at zero snr is not
47 zero the original min snr weighting in paper
48 https://arxiv.org/abs/2303.09556."""
49 snr = self.get_snr(timesteps)
50 if self.config.prediction_type == 'epsilon':
51 return (snr + 1) / (snr + 1e-8)
52 elif self.config.prediction_type == 'sample':
53 return snr + 1
54 elif self.config.prediction_type == 'v_prediction':
55 return torch.ones_like(snr)
56
57
58class CogVideoXDDIMScheduler(CogVideoXDDIMSchedulerBase, ZoeScheduler):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected