(self, device="cuda:0", download_root=os.path.expanduser("~/.cache/clip"))
| 80 | |
| 81 | class ConsistencyDecoder: |
| 82 | def __init__(self, device="cuda:0", download_root=os.path.expanduser("~/.cache/clip")): |
| 83 | self.n_distilled_steps = 64 |
| 84 | download_target = _download( |
| 85 | "https://openaipublic.azureedge.net/diff-vae/c9cebd3132dd9c42936d803e33424145a748843c8f716c0814838bdc8a2fe7cb/decoder.pt", |
| 86 | download_root, |
| 87 | ) |
| 88 | self.ckpt = torch.jit.load(download_target).to(device) |
| 89 | self.device = device |
| 90 | sigma_data = 0.5 |
| 91 | betas = betas_for_alpha_bar(1024, lambda t: math.cos((t + 0.008) / 1.008 * math.pi / 2) ** 2).to(device) |
| 92 | alphas = 1.0 - betas |
| 93 | alphas_cumprod = torch.cumprod(alphas, dim=0) |
| 94 | self.sqrt_alphas_cumprod = torch.sqrt(alphas_cumprod) |
| 95 | self.sqrt_one_minus_alphas_cumprod = torch.sqrt(1.0 - alphas_cumprod) |
| 96 | sqrt_recip_alphas_cumprod = torch.sqrt(1.0 / alphas_cumprod) |
| 97 | sigmas = torch.sqrt(1.0 / alphas_cumprod - 1) |
| 98 | self.c_skip = sqrt_recip_alphas_cumprod * sigma_data**2 / (sigmas**2 + sigma_data**2) |
| 99 | self.c_out = sigmas * sigma_data / (sigmas**2 + sigma_data**2) ** 0.5 |
| 100 | self.c_in = sqrt_recip_alphas_cumprod / (sigmas**2 + sigma_data**2) ** 0.5 |
| 101 | |
| 102 | @staticmethod |
| 103 | def round_timesteps(timesteps, total_timesteps, n_distilled_steps, truncate_start=True): |
nothing calls this directly
no test coverage detected