(self, image_input_ids, image_position_ids, text_input_ids, text_position_ids, *, image_attention_mask=None, text_attention_mask=None, **kw_args)
| 118 | self.text_encoder.reinit(mixin_names) |
| 119 | |
| 120 | def forward(self, image_input_ids, image_position_ids, text_input_ids, text_position_ids, *, image_attention_mask=None, text_attention_mask=None, **kw_args): |
| 121 | image_embeds, *image_mems = self.encode_image(image_input_ids, image_position_ids, attention_mask=image_attention_mask, **kw_args) |
| 122 | text_embeds, *text_mems = self.encode_text(text_input_ids, text_position_ids, attention_mask=text_attention_mask, **kw_args) |
| 123 | |
| 124 | # normalized features |
| 125 | image_embeds = image_embeds / image_embeds.norm(dim=-1, keepdim=True) |
| 126 | text_embeds = text_embeds / text_embeds.norm(dim=-1, keepdim=True) |
| 127 | |
| 128 | # cosine similarity as logits |
| 129 | logit_scale = self.logit_scale.exp() |
| 130 | logits_per_text = torch.matmul(text_embeds, image_embeds.t()) * logit_scale |
| 131 | logits_per_image = logits_per_text.T |
| 132 | return image_embeds, text_embeds, logits_per_text, logits_per_image |
| 133 | |
| 134 | @classmethod |
| 135 | def add_model_specific_args(cls, parser): |
nothing calls this directly
no test coverage detected