


from ..utils import deprecate
from .attention_processor import (  # noqa: F401
    Attention,
    AttentionProcessor,
    AttnAddedKVProcessor,
    AttnProcessor2_0,
    LoRAAttnProcessor,
    LoRALinearLayer,
    LoRAXFormersAttnProcessor,
    SlicedAttnAddedKVProcessor,
    SlicedAttnProcessor,
    XFormersAttnProcessor,
)
from .attention_processor import AttnProcessor as AttnProcessorRename  # noqa: F401


deprecate(
    '''cross_attention''',
    '''0.20.0''',
    '''Importing from cross_attention is deprecated. Please import from diffusers.models.attention_processor instead.''',
    standard_warn=False,
)


__lowerCAmelCase									=				AttentionProcessor





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  List[Any]         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							int:




        '''simple docstring'''
        lowercase__:  Optional[int]         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  int         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Tuple         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							int:




        '''simple docstring'''
        lowercase__:  str         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							Dict:




        '''simple docstring'''
        lowercase__:  Any         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)





class     __a     (       __UpperCamelCase ):
 def __init__(  self							,					*lowerCAmelCase__							,					**lowerCAmelCase__					)   ->							Tuple:




        '''simple docstring'''
        lowercase__:  List[Any]         =  F'{self.__class__.__name__} is deprecated and will be removed in `0.20.0`. Please use `from diffusers.models.attention_processor import {"".join(self.__class__.__name__.split("Cross"					)					)} instead.'
        deprecate('cross_attention'							,					'0.20.0'							,					lowerCAmelCase__							,					standard_warn=lowerCAmelCase__					)
        super().__init__(*lowerCAmelCase__							,					**lowerCAmelCase__					)






import unittest

from cer import CER


__lowerCAmelCase									=				CER()





class     __a     (       unittest.TestCase ):
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ['White House']
        lowercase__:  Optional[int]         =  ['white house']
        # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
        lowercase__:  str         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  ['were wolf']
        lowercase__:  Union[str, Any]         =  ['werewolf']
        # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
        lowercase__:  Tuple         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1					) < 1E-6					)

        lowercase__:  Dict         =  ['werewolf']
        lowercase__:  Optional[Any]         =  ['weae     wolf']
        # S = 1, D = 1, I = 0, N = 8, CER = 0.25
        lowercase__:  Optional[int]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.2_5					) < 1E-6					)

        # consecutive whitespaces case 1
        lowercase__:  Union[str, Any]         =  ['were wolf']
        lowercase__:  int         =  ['were               wolf']
        # S = 0, D = 0, I = 0, N = 9, CER = 0
        lowercase__:  int         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0					) < 1E-6					)

        # consecutive whitespaces case 2
        lowercase__:  List[str]         =  ['were   wolf']
        lowercase__:  Tuple         =  ['were               wolf']
        # S = 0, D = 0, I = 0, N = 9, CER = 0
        lowercase__:  Dict         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Optional[int]         =  ['werewolf']
        lowercase__:  Dict         =  ['weaewolf']
        # S = 1, D = 0, I = 0, N = 8, CER = 0.125
        lowercase__:  int         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  int         =  ['werewolf']
        lowercase__:  Optional[int]         =  ['wereawolf']
        # S = 0, D = 1, I = 0, N = 8, CER = 0.125
        lowercase__:  Dict         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ['werewolf']
        lowercase__:  List[str]         =  ['wereolf']
        # S = 0, D = 0, I = 1, N = 8, CER = 0.125
        lowercase__:  Optional[Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  List[str]         =  ['werewolf']
        lowercase__:  List[Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertEqual(lowerCAmelCase__							,					0.0					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  int         =  ['werewolf', 'I am your father']
        lowercase__:  Union[str, Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertEqual(lowerCAmelCase__							,					0.0					)

        lowercase__:  List[str]         =  ['werewolf', 'I am your father', 'doge']
        lowercase__:  Any         =  ['werxwolf', 'I       am your father', 'doge']
        # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
        lowercase__:  int         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  List[Any]         =  ['My hovercraft', 'is full of eels']
        lowercase__:  Union[str, Any]         =  ['My hovercraft is full', ' of eels']
        # S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
        # whitespace at the front of " of eels" will be strip during preporcessing
        # so need to insert 2 whitespaces
        lowercase__:  Optional[int]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__							,					concatenate_texts=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Dict:




        '''simple docstring'''
        lowercase__:  Dict         =  ['我能吞下玻璃而不伤身体']
        lowercase__:  Tuple         =  [' 能吞虾玻璃而 不霜身体啦']
        # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
        lowercase__:  str         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5					) < 1E-6					)

        lowercase__:  Any         =  ['我能吞下玻璃', '而不伤身体']
        lowercase__:  Union[str, Any]         =  ['我    能 吞 下 玻 璃', '而不伤身体']
        # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
        lowercase__:  Optional[Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5_4_5					) < 1E-6					)

        lowercase__:  int         =  ['我能吞下玻璃而不伤身体']
        lowercase__:  Any         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertFalse(lowerCAmelCase__							,					0.0					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Dict         =  ['']
        lowercase__:  int         =  ['Hypothesis']
        with self.assertRaises(lowerCAmelCase__					):
               cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)


if __name__ == "__main__":
 unittest.main()


