Spaces:
Running on Zero
Running on Zero
multimodalart HF Staff
MiniMax-H3 ref2va, the denoising half of the split deployment
9e3b8ca verified Download diffusers/pipelines/kandinsky/text_encoder.py from dagloop5/TestingRef2va: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/dagloop5/TestingRef2va/resolve/85b133dc3d05102b1bc2c04626c2cc8432c8564a/diffusers/pipelines/kandinsky/text_encoder.py
- Command line
-
hf download hf://spaces/dagloop5/TestingRef2va@85b133dc3d05102b1bc2c04626c2cc8432c8564a/diffusers/pipelines/kandinsky/text_encoder.py
-
curl -L -o text_encoder.py https://huggingface.co/spaces/dagloop5/TestingRef2va/resolve/85b133dc3d05102b1bc2c04626c2cc8432c8564a/diffusers/pipelines/kandinsky/text_encoder.py
1.09 kB
| import torch | |
| from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel | |
| class MCLIPConfig(XLMRobertaConfig): | |
| model_type = "M-CLIP" | |
| def __init__(self, transformerDimSize=1024, imageDimSize=768, **kwargs): | |
| self.transformerDimensions = transformerDimSize | |
| self.numDims = imageDimSize | |
| super().__init__(**kwargs) | |
| class MultilingualCLIP(PreTrainedModel): | |
| config_class = MCLIPConfig | |
| def __init__(self, config, *args, **kwargs): | |
| super().__init__(config, *args, **kwargs) | |
| self.transformer = XLMRobertaModel(config) | |
| self.LinearTransformation = torch.nn.Linear( | |
| in_features=config.transformerDimensions, out_features=config.numDims | |
| ) | |
| if hasattr(self, "post_init"): | |
| self.post_init() | |
| def forward(self, input_ids, attention_mask): | |
| embs = self.transformer(input_ids=input_ids, attention_mask=attention_mask)[0] | |
| embs2 = (embs * attention_mask.unsqueeze(2)).sum(dim=1) / attention_mask.sum(dim=1)[:, None] | |
| return self.LinearTransformation(embs2), embs | |