




'''simple docstring'''





from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

UpperCamelCase_						:      int       =						TypeVar('''T''')
UpperCamelCase_						:      Dict       =						TypeVar('''U''')

class        _a    (						Generic[T, U]							):






     def __init__(			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )							->      Dict:
          _snake_case							=				key
          _snake_case							=				val
          _snake_case							=				None
          _snake_case							=				None






     def __repr__(			self   )							->      str:
          return (
              f"""Node: key: {self.key}, val: {self.val}, """
              f"""has next: {bool(self.next   )}, has prev: {bool(self.prev   )}"""
          )







class        _a    (						Generic[T, U]							):






     def __init__(			self   )							->      None:
          _snake_case							=				DoubleLinkedListNode(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
          _snake_case							=				DoubleLinkedListNode(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
          _snake_case							, _snake_case							=				self.rear, self.head






     def __repr__(			self   )							->      str:
          _snake_case							=				["DoubleLinkedList"]
          _snake_case							=				self.head
          while node.next is not None:
               rep.append(str(_SCREAMING_SNAKE_CASE   )   )
               _snake_case							=				node.next
          rep.append(str(self.rear   )   )
          return ",\n    ".join(_SCREAMING_SNAKE_CASE   )






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE   )							->      None:
          _snake_case							=				self.rear.prev

          # All nodes other than self.head are guaranteed to have non-None previous
          assert previous is not None

          _snake_case							=				node
          _snake_case							=				previous
          _snake_case							=				node
          _snake_case							=				self.rear






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE   )							->      DoubleLinkedListNode[T, U] | None:

          if node.prev is None or node.next is None:
               return None

          _snake_case							=				node.next
          _snake_case							=				node.prev
          _snake_case							=				None
          _snake_case							=				None
          return node







class        _a    (						Generic[T, U]							):
     SCREAMING_SNAKE_CASE_							:   dict[Callable[[T], U], LRUCache[T, U]]       =						{}






     def __init__(			self ,_SCREAMING_SNAKE_CASE   )							->      str:
          _snake_case							=				DoubleLinkedList()
          _snake_case							=				capacity
          _snake_case							=				0
          _snake_case							=				0
          _snake_case							=				0
          _snake_case							=				{}






     def __repr__(			self   )							->      str:
          return (
              f"""CacheInfo(hits={self.hits}, misses={self.miss}, """
              f"""capacity={self.capacity}, current size={self.num_keys})"""
          )






     def __contains__(			self ,_SCREAMING_SNAKE_CASE   )							->      bool:
          return key in self.cache






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE   )							->      U | None:
          # Note: pythonic interface would throw KeyError rather than return None

          if key in self.cache:
               self.hits += 1
               _snake_case							=				self.cache[key]
               _snake_case							=				self.list.remove(self.cache[key]   )
               assert node == value_node

               # node is guaranteed not None because it is in self.cache
               assert node is not None
               self.list.add(_SCREAMING_SNAKE_CASE   )
               return node.val
          self.miss += 1
          return None






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )							->      None:

          if key not in self.cache:
               if self.num_keys >= self.capacity:
                    # delete first node (oldest) when over capacity
                    _snake_case							=				self.list.head.next

                    # guaranteed to have a non-None first node when num_keys > 0
                    # explain to type checker via assertions
                    assert first_node is not None
                    assert first_node.key is not None
                    assert (
                        self.list.remove(_SCREAMING_SNAKE_CASE   ) is not None
                    )  # node guaranteed to be in list assert node.key is not None

                    del self.cache[first_node.key]
                    self.num_keys -= 1
               _snake_case							=				DoubleLinkedListNode(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )
               self.list.add(self.cache[key]   )
               self.num_keys += 1

          else:
               # bump node to the end of the list, update value
               _snake_case							=				self.list.remove(self.cache[key]   )
               assert node is not None  # node guaranteed to be in list
               _snake_case							=				value
               self.list.add(_SCREAMING_SNAKE_CASE   )






     @classmethod
     def     _lowercase     (			cls ,_SCREAMING_SNAKE_CASE = 128   )							->      Callable[[Callable[[T], U]], Callable[..., U]]:

          def cache_decorator_inner(_SCREAMING_SNAKE_CASE   ) -> Callable[..., U]:
               def cache_decorator_wrapper(*_SCREAMING_SNAKE_CASE   ) -> U:
                    if func not in cls.decorator_function_to_instance_map:
                         _snake_case							=				LRUCache(_SCREAMING_SNAKE_CASE   )

                    _snake_case							=				cls.decorator_function_to_instance_map[func].get(args[0]   )
                    if result is None:
                         _snake_case							=				func(*_SCREAMING_SNAKE_CASE   )
                         cls.decorator_function_to_instance_map[func].put(args[0] ,_SCREAMING_SNAKE_CASE   )
                    return result

               def cache_info() -> LRUCache[T, U]:
                    return cls.decorator_function_to_instance_map[func]

               setattr(_SCREAMING_SNAKE_CASE ,"cache_info" ,_SCREAMING_SNAKE_CASE   )  # noqa: B010

               return cache_decorator_wrapper

          return cache_decorator_inner


if __name__ == "__main__":
   import doctest

   doctest.testmod()








'''simple docstring'''





import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase_						:      str       =						logging.get_logger(__name__)

UpperCamelCase_						:      Optional[Any]       =						{
    '''asapp/sew-tiny-100k''': '''https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json''',
    # See all SEW models at https://huggingface.co/models?filter=sew
}

class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   Dict       =						"""sew"""






     def __init__(			self ,_SCREAMING_SNAKE_CASE=32 ,_SCREAMING_SNAKE_CASE=768 ,_SCREAMING_SNAKE_CASE=12 ,_SCREAMING_SNAKE_CASE=12 ,_SCREAMING_SNAKE_CASE=3_072 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE="gelu" ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.1 ,_SCREAMING_SNAKE_CASE=0.0_2 ,_SCREAMING_SNAKE_CASE=1e-5 ,_SCREAMING_SNAKE_CASE="group" ,_SCREAMING_SNAKE_CASE="gelu" ,_SCREAMING_SNAKE_CASE=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512) ,_SCREAMING_SNAKE_CASE=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1) ,_SCREAMING_SNAKE_CASE=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1) ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=128 ,_SCREAMING_SNAKE_CASE=16 ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=0.0_5 ,_SCREAMING_SNAKE_CASE=10 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=10 ,_SCREAMING_SNAKE_CASE=0 ,_SCREAMING_SNAKE_CASE="mean" ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=256 ,_SCREAMING_SNAKE_CASE=0 ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=2 ,**_SCREAMING_SNAKE_CASE ,)							->      str:
          super().__init__(**_SCREAMING_SNAKE_CASE ,pad_token_id=_SCREAMING_SNAKE_CASE ,bos_token_id=_SCREAMING_SNAKE_CASE ,eos_token_id=_SCREAMING_SNAKE_CASE   )
          _snake_case							=				hidden_size
          _snake_case							=				feat_extract_norm
          _snake_case							=				feat_extract_activation
          _snake_case							=				list(_SCREAMING_SNAKE_CASE   )
          _snake_case							=				list(_SCREAMING_SNAKE_CASE   )
          _snake_case							=				list(_SCREAMING_SNAKE_CASE   )
          _snake_case							=				conv_bias
          _snake_case							=				num_conv_pos_embeddings
          _snake_case							=				num_conv_pos_embedding_groups
          _snake_case							=				len(self.conv_dim   )
          _snake_case							=				num_hidden_layers
          _snake_case							=				intermediate_size
          _snake_case							=				squeeze_factor
          _snake_case							=				hidden_act
          _snake_case							=				num_attention_heads
          _snake_case							=				hidden_dropout
          _snake_case							=				attention_dropout
          _snake_case							=				activation_dropout
          _snake_case							=				feat_proj_dropout
          _snake_case							=				final_dropout
          _snake_case							=				layerdrop
          _snake_case							=				layer_norm_eps
          _snake_case							=				initializer_range
          _snake_case							=				vocab_size

          if (
              (len(self.conv_stride   ) != self.num_feat_extract_layers)
              or (len(self.conv_kernel   ) != self.num_feat_extract_layers)
              or (len(self.conv_dim   ) != self.num_feat_extract_layers)
          ):
               raise ValueError(
                   "Configuration for convolutional layers is incorrect."
                   "It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"
                   f"""but is `len(config.conv_dim) = {len(self.conv_dim   )}`, `len(config.conv_stride)"""
                   f"""= {len(self.conv_stride   )}`, `len(config.conv_kernel) = {len(self.conv_kernel   )}`."""   )

          # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
          _snake_case							=				apply_spec_augment
          _snake_case							=				mask_time_prob
          _snake_case							=				mask_time_length
          _snake_case							=				mask_time_min_masks
          _snake_case							=				mask_feature_prob
          _snake_case							=				mask_feature_length
          _snake_case							=				mask_feature_min_masks

          # ctc loss
          _snake_case							=				ctc_loss_reduction
          _snake_case							=				ctc_zero_infinity

          # sequence classification
          _snake_case							=				use_weighted_layer_sum
          _snake_case							=				classifier_proj_size






     @property
     def     _lowercase     (			self   )							->      Optional[Any]:
          return functools.reduce(operator.mul ,self.conv_stride ,1   )


