(dump_path, unet_checkpoint_path)
| 1180 | |
| 1181 | |
| 1182 | def superres_check_against_original(dump_path, unet_checkpoint_path): |
| 1183 | model_path = dump_path |
| 1184 | model = UNet2DConditionModel.from_pretrained(model_path) |
| 1185 | model.to("cuda") |
| 1186 | orig_path = unet_checkpoint_path |
| 1187 | |
| 1188 | if "-II-" in orig_path: |
| 1189 | from deepfloyd_if.modules import IFStageII |
| 1190 | |
| 1191 | if_II_model = IFStageII(device="cuda", dir_or_name=orig_path, model_kwargs={"precision": "fp32"}).model |
| 1192 | elif "-III-" in orig_path: |
| 1193 | from deepfloyd_if.modules import IFStageIII |
| 1194 | |
| 1195 | if_II_model = IFStageIII(device="cuda", dir_or_name=orig_path, model_kwargs={"precision": "fp32"}).model |
| 1196 | |
| 1197 | batch_size = 1 |
| 1198 | channels = model.config.in_channels // 2 |
| 1199 | height = model.config.sample_size |
| 1200 | width = model.config.sample_size |
| 1201 | height = 1024 |
| 1202 | width = 1024 |
| 1203 | |
| 1204 | torch.manual_seed(0) |
| 1205 | |
| 1206 | latents = torch.randn((batch_size, channels, height, width), device=model.device) |
| 1207 | image_small = torch.randn((batch_size, channels, height // 4, width // 4), device=model.device) |
| 1208 | |
| 1209 | interpolate_antialias = {} |
| 1210 | if "antialias" in inspect.signature(F.interpolate).parameters: |
| 1211 | interpolate_antialias["antialias"] = True |
| 1212 | image_upscaled = F.interpolate( |
| 1213 | image_small, size=[height, width], mode="bicubic", align_corners=False, **interpolate_antialias |
| 1214 | ) |
| 1215 | |
| 1216 | latent_model_input = torch.cat([latents, image_upscaled], dim=1).to(model.dtype) |
| 1217 | t = torch.tensor([5], device=model.device).to(model.dtype) |
| 1218 | |
| 1219 | seq_len = 64 |
| 1220 | encoder_hidden_states = torch.randn((batch_size, seq_len, model.config.encoder_hid_dim), device=model.device).to( |
| 1221 | model.dtype |
| 1222 | ) |
| 1223 | |
| 1224 | fake_class_labels = torch.tensor([t], device=model.device).to(model.dtype) |
| 1225 | |
| 1226 | with torch.no_grad(): |
| 1227 | out = if_II_model(latent_model_input, t, aug_steps=fake_class_labels, text_emb=encoder_hidden_states) |
| 1228 | |
| 1229 | if_II_model.to("cpu") |
| 1230 | del if_II_model |
| 1231 | import gc |
| 1232 | |
| 1233 | torch.cuda.empty_cache() |
| 1234 | gc.collect() |
| 1235 | print(50 * "=") |
| 1236 | |
| 1237 | with torch.no_grad(): |
| 1238 | noise_pred = model( |
| 1239 | sample=latent_model_input, |
nothing calls this directly
no test coverage detected