| 63 | |
| 64 | |
| 65 | class DummyOpenCLIPTextEmbedder(nn.Module): |
| 66 | def __init__( |
| 67 | self, |
| 68 | nulltext_path="nulltext.npy", |
| 69 | ): |
| 70 | super().__init__() |
| 71 | self.arch = "ViT-H-14" |
| 72 | self.version = "laion2b_s32b_b79k" |
| 73 | self.layer = "penultimate" |
| 74 | |
| 75 | # find correct path for nulltext embedding |
| 76 | if isinstance(nulltext_path, list) or isinstance(nulltext_path, ListConfig): |
| 77 | for path in nulltext_path: |
| 78 | if os.path.exists(path): |
| 79 | nulltext_path = path |
| 80 | break |
| 81 | else: |
| 82 | raise FileNotFoundError("Could not find a valid nulltext path.") |
| 83 | |
| 84 | cond = np.load(nulltext_path) |
| 85 | self.uncond = torch.from_numpy(cond).squeeze(0) |
| 86 | |
| 87 | def forward(self, x, *args, **kwargs): |
| 88 | bs = x.shape[0] |
| 89 | device = x.device |
| 90 | if self.uncond.device is not device: |
| 91 | self.uncond = self.uncond.to(device) |
| 92 | |
| 93 | return self.uncond[None, :].repeat(bs, 1, 1) |
| 94 | |
| 95 | |
| 96 | class FrozenOpenCLIPImageEmbedder(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected