| 196 | |
| 197 | |
| 198 | class FrozenCLIPT5Encoder(AbstractEncoder): |
| 199 | def __init__(self, clip_version="openai/clip-vit-large-patch14", t5_version="google/t5-v1_1-xl", device="cuda", |
| 200 | clip_max_length=77, t5_max_length=77): |
| 201 | super().__init__() |
| 202 | self.clip_encoder = FrozenCLIPEmbedder(clip_version, device, max_length=clip_max_length) |
| 203 | self.t5_encoder = FrozenT5Embedder(t5_version, device, max_length=t5_max_length) |
| 204 | print(f"{self.clip_encoder.__class__.__name__} has {count_params(self.clip_encoder)*1.e-6:.2f} M parameters, " |
| 205 | f"{self.t5_encoder.__class__.__name__} comes with {count_params(self.t5_encoder)*1.e-6:.2f} M params.") |
| 206 | |
| 207 | def encode(self, text): |
| 208 | return self(text) |
| 209 | |
| 210 | def forward(self, text): |
| 211 | clip_z = self.clip_encoder.encode(text) |
| 212 | t5_z = self.t5_encoder.encode(text) |
| 213 | return [clip_z, t5_z] |
| 214 | |
| 215 |
nothing calls this directly
no outgoing calls
no test coverage detected