




import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import (
    TaBlock,
    TaConfig,
    TaLayerNorm,
)

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class     a  (     _A			,     _A			,     _A    ):

     '''simple docstring'''





     @register_to_config
     def __init__(			self     :    List[str]      ,					__snake_case     :    int      ,					__snake_case     :    int      ,					__snake_case     :    int      ,					__snake_case     :    float      ,					__snake_case     :    int      ,					__snake_case     :    int      ,					__snake_case     :    int      ,					__snake_case     :    int      ,					__snake_case     :    str      ,					__snake_case     :    bool = False      ,					):
         super().__init__()

         UpperCAmelCase_											=  nn.Linear(__snake_case      ,					__snake_case      ,					bias=__snake_case       )

         UpperCAmelCase_											=  nn.Embedding(__snake_case      ,					__snake_case       )
         UpperCAmelCase_											=  False

         UpperCAmelCase_											=  nn.Dropout(p=__snake_case       )

         UpperCAmelCase_											=  TaConfig(
             d_model=__snake_case      ,					num_heads=__snake_case      ,					d_kv=__snake_case      ,					d_ff=__snake_case      ,					feed_forward_proj=__snake_case      ,					dropout_rate=__snake_case      ,					is_decoder=__snake_case      ,					is_encoder_decoder=__snake_case      ,					)
         UpperCAmelCase_											=  nn.ModuleList()
         for lyr_num in range(__snake_case       ):
             UpperCAmelCase_											=  TaBlock(__snake_case       )
             self.encoders.append(__snake_case       )

         UpperCAmelCase_											=  TaLayerNorm(__snake_case       )
         UpperCAmelCase_											=  nn.Dropout(p=__snake_case       )




     def 						lowerCamelCase_     (			self     :    Optional[Any]      ,					__snake_case     :    Union[str, Any]      ,					__snake_case     :    Any       ):
         UpperCAmelCase_											=  self.input_proj(__snake_case       )

         # terminal relative positional encodings
         UpperCAmelCase_											=  encoder_inputs.shape[1]
         UpperCAmelCase_											=  torch.arange(__snake_case      ,					device=encoder_inputs.device       )

         UpperCAmelCase_											=  encoder_inputs_mask.sum(-1       )
         UpperCAmelCase_											=  torch.roll(input_positions.unsqueeze(0       )      ,					tuple(seq_lens.tolist()       )      ,					dims=0       )
         x += self.position_encoding(__snake_case       )

         UpperCAmelCase_											=  self.dropout_pre(__snake_case       )

         # inverted the attention mask
         UpperCAmelCase_											=  encoder_inputs.size()
         UpperCAmelCase_											=  self.get_extended_attention_mask(__snake_case      ,					__snake_case       )

         for lyr in self.encoders:
             UpperCAmelCase_											=  lyr(__snake_case      ,					__snake_case       )[0]
         UpperCAmelCase_											=  self.layer_norm(__snake_case       )

         return self.dropout_post(__snake_case       ), encoder_inputs_mask











import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


_lowerCamelCase    				=		threading.Lock()
_lowerCamelCase    				=		None

_lowerCamelCase    				=		{
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

_lowerCamelCase    				=		logging.WARNING

_lowerCamelCase    				=		True




def       SCREAMING_SNAKE_CASE			( )						->							List[str]:
    UpperCAmelCase_											=  os.getenv('''DIFFUSERS_VERBOSITY''' ,  __UpperCamelCase   )
    if env_level_str:
        if env_level_str in log_levels:
            return log_levels[env_level_str]
        else:
            logging.getLogger().warning(
                f'Unknown option DIFFUSERS_VERBOSITY={env_level_str}, '
                f'has to be one of: { ", ".join(log_levels.keys()   ) }'   )
    return _default_log_level




def       SCREAMING_SNAKE_CASE			( )						->							str:
    return __name__.split('''.'''   )[0]




def       SCREAMING_SNAKE_CASE			( )						->							logging.Logger:
    return logging.getLogger(_get_library_name()   )




def       SCREAMING_SNAKE_CASE			( )						->							None:
    global _default_handler

    with _lock:
        if _default_handler:
            # This library has already configured the library root logger.
            return
        UpperCAmelCase_											=  logging.StreamHandler()  # Set sys.stderr as stream.
        UpperCAmelCase_											=  sys.stderr.flush

        # Apply our default configuration to the library root logger.
        UpperCAmelCase_											=  _get_library_root_logger()
        library_root_logger.addHandler(_default_handler   )
        library_root_logger.setLevel(_get_default_logging_level()   )
        UpperCAmelCase_											=  False




def       SCREAMING_SNAKE_CASE			( )						->							None:
    global _default_handler

    with _lock:
        if not _default_handler:
            return

        UpperCAmelCase_											=  _get_library_root_logger()
        library_root_logger.removeHandler(_default_handler   )
        library_root_logger.setLevel(logging.NOTSET   )
        UpperCAmelCase_											=  None




def       SCREAMING_SNAKE_CASE			( )						->							Dict:
    return log_levels




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		Optional[str] = None   )						->							logging.Logger:

    if name is None:
        UpperCAmelCase_											=  _get_library_name()

    _configure_library_root_logger()
    return logging.getLogger(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							int:
    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		int   )						->							None:
    _configure_library_root_logger()
    _get_library_root_logger().setLevel(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							Optional[Any]:
    return set_verbosity(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							Union[str, Any]:
    return set_verbosity(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							Tuple:
    return set_verbosity(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							int:
    return set_verbosity(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							None:
    _configure_library_root_logger()

    assert _default_handler is not None
    _get_library_root_logger().removeHandler(_default_handler   )




def       SCREAMING_SNAKE_CASE			( )						->							None:
    _configure_library_root_logger()

    assert _default_handler is not None
    _get_library_root_logger().addHandler(_default_handler   )




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		logging.Handler   )						->							None:
    _configure_library_root_logger()

    assert handler is not None
    _get_library_root_logger().addHandler(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		logging.Handler   )						->							None:
    _configure_library_root_logger()

    assert handler is not None and handler not in _get_library_root_logger().handlers
    _get_library_root_logger().removeHandler(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							None:
    _configure_library_root_logger()
    UpperCAmelCase_											=  False




def       SCREAMING_SNAKE_CASE			( )						->							None:
    _configure_library_root_logger()
    UpperCAmelCase_											=  True




def       SCREAMING_SNAKE_CASE			( )						->							None:
    UpperCAmelCase_											=  _get_library_root_logger().handlers

    for handler in handlers:
        UpperCAmelCase_											=  logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''   )
        handler.setFormatter(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( )						->							None:
    UpperCAmelCase_											=  _get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(__UpperCamelCase   )




def       SCREAMING_SNAKE_CASE			( self    :		Tuple ,  *__UpperCamelCase    :		Any ,  **__UpperCamelCase    :		Any   )						->							Union[str, Any]:
    UpperCAmelCase_											=  os.getenv('''DIFFUSERS_NO_ADVISORY_WARNINGS''' ,  __UpperCamelCase   )
    if no_advisory_warnings:
        return
    self.warning(*__UpperCamelCase ,  **__UpperCamelCase   )


_lowerCamelCase    				=		warning_advice



class     a  :

     '''simple docstring'''





     def __init__(			self     :    List[Any]      ,					*__snake_case     :    Tuple      ,					**__snake_case     :    str       ):  # pylint: disable=unused-argument
         UpperCAmelCase_											=  args[0] if args else None
     def __iter__(			self     :    Union[str, Any]       ):
         return iter(self._iterator       )
     def __getattr__(			self     :    Tuple      ,					__snake_case     :    str       ):

         def empty_fn(*__snake_case     :    Optional[int]      ,					**__snake_case     :    int       ):  # pylint: disable=unused-argument
             return

         return empty_fn
     def __enter__(			self     :    Optional[Any]       ):
         return self




     def __exit__(			self     :    Union[str, Any]      ,					__snake_case     :    List[Any]      ,					__snake_case     :    List[str]      ,					__snake_case     :    Dict       ):
         return



class     a  :

     '''simple docstring'''





     def __call__(			self     :    Union[str, Any]      ,					*__snake_case     :    List[str]      ,					**__snake_case     :    Dict       ):
         if _tqdm_active:
             return tqdm_lib.tqdm(*__snake_case      ,					**__snake_case       )
         else:
             return EmptyTqdm(*__snake_case      ,					**__snake_case       )
     def 						lowerCamelCase_     (			self     :    int      ,					*__snake_case     :    Dict      ,					**__snake_case     :    List[str]       ):
         UpperCAmelCase_											=  None
         if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*__snake_case      ,					**__snake_case       )




     def 						lowerCamelCase_     (			self     :    str       ):
         if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()


_lowerCamelCase    				=		_tqdm_cls()




def       SCREAMING_SNAKE_CASE			( )						->							bool:
    global _tqdm_active
    return bool(_tqdm_active   )




def       SCREAMING_SNAKE_CASE			( )						->							List[str]:
    global _tqdm_active
    UpperCAmelCase_											=  True




def       SCREAMING_SNAKE_CASE			( )						->							Optional[int]:
    global _tqdm_active
    UpperCAmelCase_											=  False





