




import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible





class 			lowerCamelCase_				( unittest.TestCase   ):


 '''simple docstring'''







 def  lowerCAmelCase_    (				self    :						Optional[int]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.bin',
           'safety_checker/model.safetensors',
           'vae/diffusion_pytorch_model.bin',
           'vae/diffusion_pytorch_model.safetensors',
           'text_encoder/pytorch_model.bin',
           'text_encoder/model.safetensors',
           'unet/diffusion_pytorch_model.bin',
           'unet/diffusion_pytorch_model.safetensors',
       ]
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						List[str]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'unet/diffusion_pytorch_model.bin',
           'unet/diffusion_pytorch_model.safetensors',
       ]
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.bin',
           'safety_checker/model.safetensors',
           'vae/diffusion_pytorch_model.bin',
           'vae/diffusion_pytorch_model.safetensors',
           'text_encoder/pytorch_model.bin',
           'text_encoder/model.safetensors',
           'unet/diffusion_pytorch_model.bin',
           # Removed: 'unet/diffusion_pytorch_model.safetensors',
       ]
       self.assertFalse(is_safetensors_compatible(_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Any		):
       SCREAMING_SNAKE_CASE_      		=     [
           'text_encoder/pytorch_model.bin',
           'text_encoder/model.safetensors',
       ]
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						List[str]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.bin',
           'safety_checker/model.safetensors',
           'vae/diffusion_pytorch_model.bin',
           'vae/diffusion_pytorch_model.safetensors',
           'text_encoder/pytorch_model.bin',
           # Removed: 'text_encoder/model.safetensors',
           'unet/diffusion_pytorch_model.bin',
           'unet/diffusion_pytorch_model.safetensors',
       ]
       self.assertFalse(is_safetensors_compatible(_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Optional[Any]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.fp16.bin',
           'safety_checker/model.fp16.safetensors',
           'vae/diffusion_pytorch_model.fp16.bin',
           'vae/diffusion_pytorch_model.fp16.safetensors',
           'text_encoder/pytorch_model.fp16.bin',
           'text_encoder/model.fp16.safetensors',
           'unet/diffusion_pytorch_model.fp16.bin',
           'unet/diffusion_pytorch_model.fp16.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Dict		):
       SCREAMING_SNAKE_CASE_      		=     [
           'unet/diffusion_pytorch_model.fp16.bin',
           'unet/diffusion_pytorch_model.fp16.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Tuple		):
       # pass variant but use the non-variant filenames
       SCREAMING_SNAKE_CASE_      		=     [
           'unet/diffusion_pytorch_model.bin',
           'unet/diffusion_pytorch_model.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						List[str]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.fp16.bin',
           'safety_checker/model.fp16.safetensors',
           'vae/diffusion_pytorch_model.fp16.bin',
           'vae/diffusion_pytorch_model.fp16.safetensors',
           'text_encoder/pytorch_model.fp16.bin',
           'text_encoder/model.fp16.safetensors',
           'unet/diffusion_pytorch_model.fp16.bin',
           # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertFalse(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						Tuple		):
       SCREAMING_SNAKE_CASE_      		=     [
           'text_encoder/pytorch_model.fp16.bin',
           'text_encoder/model.fp16.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)



 def  lowerCAmelCase_    (				self    :						int		):
       # pass variant but use the non-variant filenames
       SCREAMING_SNAKE_CASE_      		=     [
           'text_encoder/pytorch_model.bin',
           'text_encoder/model.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertTrue(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)




 def  lowerCAmelCase_    (				self    :						Optional[int]		):
       SCREAMING_SNAKE_CASE_      		=     [
           'safety_checker/pytorch_model.fp16.bin',
           'safety_checker/model.fp16.safetensors',
           'vae/diffusion_pytorch_model.fp16.bin',
           'vae/diffusion_pytorch_model.fp16.safetensors',
           'text_encoder/pytorch_model.fp16.bin',
           # 'text_encoder/model.fp16.safetensors',
           'unet/diffusion_pytorch_model.fp16.bin',
           'unet/diffusion_pytorch_model.fp16.safetensors',
       ]
       SCREAMING_SNAKE_CASE_      		=     'fp16'
       self.assertFalse(is_safetensors_compatible(_lowerCAmelCase							,							variant=_lowerCAmelCase		)		)





import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       "M-CLIP"



 def __init__(				self    :						Tuple							,							_lowerCAmelCase    :						List[str]=1_024							,							_lowerCAmelCase    :						str=768							,							**_lowerCAmelCase    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     transformerDimSize
       SCREAMING_SNAKE_CASE_      		=     imageDimSize
       super().__init__(**_lowerCAmelCase		)





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       MCLIPConfig



 def __init__(				self    :						Dict							,							_lowerCAmelCase    :						Union[str, Any]							,							*_lowerCAmelCase    :						str							,							**_lowerCAmelCase    :						str		):
       super().__init__(_lowerCAmelCase							,							*_lowerCAmelCase							,							**_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     XLMRobertaModel(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     torch.nn.Linear(
           in_features=config.transformerDimensions							,							out_features=config.numDims		)




 def  lowerCAmelCase_    (				self    :						List[Any]							,							_lowerCAmelCase    :						Any							,							_lowerCAmelCase    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     self.transformer(input_ids=_lowerCAmelCase							,							attention_mask=_lowerCAmelCase		)[0]
       SCREAMING_SNAKE_CASE_      		=     (embs * attention_mask.unsqueeze(2		)).sum(dim=1		) / attention_mask.sum(dim=1		)[:, None]
       return self.LinearTransformation(_lowerCAmelCase		), embs