





import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin


class 					__magic_name__  (							lowerCamelCase__							):





     """simple docstring"""



     __UpperCamelCase					    =     '''AutoFeatureExtractor'''
     __UpperCamelCase					    =     '''Speech2Text2Tokenizer'''



     def __init__(							self       :Union[str, Any]			,      snake_case       :Any			,      snake_case       :Optional[int]  ):





        '''simple docstring'''




        super().__init__(snake_case			,      snake_case  )
        A_					:				List[Any]          =			self.feature_extractor
        A_					:				Optional[Any]          =			False



     def __call__(							self       :Union[str, Any]			,      *snake_case       :Union[str, Any]			,      **snake_case       :Optional[Any]  ):





        '''simple docstring'''




        if self._in_target_context_manager:
           return self.current_processor(*snake_case			,      **snake_case  )

        if "raw_speech" in kwargs:
           warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."  )
           A_					:				Optional[int]          =			kwargs.pop("raw_speech"  )
        else:
           A_					:				Tuple          =			kwargs.pop("audio"			,      snake_case  )
        A_					:				List[Any]          =			kwargs.pop("sampling_rate"			,      snake_case  )
        A_					:				str          =			kwargs.pop("text"			,      snake_case  )
        if len(snake_case  ) > 0:
           A_					:				str          =			args[0]
           A_					:				int          =			args[1:]

        if audio is None and text is None:
           raise ValueError("You need to specify either an `audio` or `text` input to process."  )

        if audio is not None:
           A_					:				int          =			self.feature_extractor(snake_case			,      *snake_case			,      sampling_rate=snake_case			,      **snake_case  )
        if text is not None:
           A_					:				Tuple          =			self.tokenizer(snake_case			,      **snake_case  )

        if text is None:
           return inputs
        elif audio is None:
           return encodings
        else:
           A_					:				str          =			encodings["input_ids"]
           return inputs



     def 						SCREAMING_SNAKE_CASE		(							self       :int			,      *snake_case       :Optional[Any]			,      **snake_case       :Tuple  ):





        '''simple docstring'''




        return self.tokenizer.batch_decode(*snake_case			,      **snake_case  )



     def 						SCREAMING_SNAKE_CASE		(							self       :str			,      *snake_case       :int			,      **snake_case       :List[Any]  ):





        '''simple docstring'''




        return self.tokenizer.decode(*snake_case			,      **snake_case  )





     @contextmanager
     def 						SCREAMING_SNAKE_CASE		(							self       :str  ):





        '''simple docstring'''




        warnings.warn(
            "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
            "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
            "your audio inputs, or in a separate call."  )
        A_					:				str          =			True
        A_					:				int          =			self.tokenizer
        yield
        A_					:				Optional[int]          =			self.feature_extractor
        A_					:				Any          =			False







import torch
from torch import autograd


class 					__magic_name__  (							autograd.Function							):





     """simple docstring"""



     @staticmethod
     def 						SCREAMING_SNAKE_CASE		(							snake_case       :Any			,      snake_case       :torch.tensor			,      snake_case       :float			,      snake_case       :bool  ):





        '''simple docstring'''




        A_					:				int          =			inputs.numel()
        A_					:				str          =			int(0.005 * nb_elems  ) + 1
        if sigmoid:
           A_					:				List[Any]          =			(torch.sigmoid(snake_case  ) > threshold).type(inputs.type()  )
        else:
           A_					:				Optional[Any]          =			(inputs > threshold).type(inputs.type()  )
        if mask.sum() < nb_min:
           # We limit the pruning so that at least 0.5% (half a percent) of the weights are remaining
           A_					:				Tuple          =			inputs.flatten().kthvalue(max(nb_elems - nb_min			,      1  )  ).values
           A_					:				Optional[int]          =			(inputs > k_threshold).type(inputs.type()  )
        return mask





     @staticmethod
     def 						SCREAMING_SNAKE_CASE		(							snake_case       :Optional[int]			,      snake_case       :int  ):





        '''simple docstring'''




        return gradOutput, None, None




class 					__magic_name__  (							autograd.Function							):





     """simple docstring"""



     @staticmethod
     def 						SCREAMING_SNAKE_CASE		(							snake_case       :Tuple			,      snake_case       :torch.tensor			,      snake_case       :float  ):





        '''simple docstring'''




        A_					:				Tuple          =			inputs.clone()
        A_      ,						A_					:				Optional[int]          =			inputs.flatten().sort(descending=snake_case  )
        A_					:				Dict          =			int(threshold * inputs.numel()  )

        # flat_out and mask access the same memory.
        A_					:				str          =			mask.flatten()
        A_					:				List[Any]          =			0
        A_					:				List[str]          =			1
        return mask





     @staticmethod
     def 						SCREAMING_SNAKE_CASE		(							snake_case       :List[Any]			,      snake_case       :Optional[Any]  ):





        '''simple docstring'''




        return gradOutput, None




class 					__magic_name__  (							lowerCamelCase__							):





     """simple docstring"""



     @staticmethod
     def 						SCREAMING_SNAKE_CASE		(							snake_case       :torch.tensor			,      snake_case       :float  ):





        '''simple docstring'''




        A_					:				str          =			inputs.clone()
        A_      ,						A_					:				Optional[int]          =			inputs.abs().flatten().sort(descending=snake_case  )
        A_					:				int          =			int(threshold * inputs.numel()  )

        # flat_out and mask access the same memory.
        A_					:				List[str]          =			mask.flatten()
        A_					:				List[str]          =			0
        A_					:				Union[str, Any]          =			1
        return mask
