examples/research_projects/vqgan-clip/VQGAN_CLIP.py/VQGAN_CLIP/_optimize_CLIP
class VQGAN_CLIP:    def _optimize_CLIP(self, original_img, pos_prompts, neg_prompts):
        vector = torch.randn_like(self.latent, requires_grad=True, device=self.device)
        optim = torch.optim.Adam([vector], lr=self.lr)

        for i in range(self.iterations):
            optim.zero_grad()
            transformed_img = self._add_vector(vector)
            processed_img = loop_post_process(transformed_img)
            clip_loss = self._get_CLIP_loss(pos_prompts, neg_prompts, processed_img)
            print("CLIP loss", clip_loss)
            if self.log:
                wandb.log({"CLIP Loss": clip_loss})
            clip_loss.backward(retain_graph=True)
            optim.step()
            if self.return_val == "image":
                yield custom_to_pil(transformed_img[0])
            else:
                yield vector