'''simple docstring'''

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    lowerCamelCase__  (   __snake_case       ,				__snake_case       ,				__snake_case     ):



   @register_to_config
   def __init__(    self					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__					,      lowerCAmelCase__ = False					,      )				->     Dict:
        """simple docstring"""





        super().__init__()

        _UpperCamelCase  :List[Any]       =nn.Linear(lowerCAmelCase__					,      lowerCAmelCase__					,      bias=lowerCAmelCase__     )

        _UpperCamelCase  :List[str]       =nn.Embedding(lowerCAmelCase__					,      lowerCAmelCase__     )
        _UpperCamelCase  :Any       =False

        _UpperCamelCase  :Optional[Any]       =nn.Dropout(p=lowerCAmelCase__     )

        _UpperCamelCase  :List[str]       =TaConfig(
            d_model=lowerCAmelCase__					,      num_heads=lowerCAmelCase__					,      d_kv=lowerCAmelCase__					,      d_ff=lowerCAmelCase__					,      feed_forward_proj=lowerCAmelCase__					,      dropout_rate=lowerCAmelCase__					,      is_decoder=lowerCAmelCase__					,      is_encoder_decoder=lowerCAmelCase__					,      )
        _UpperCamelCase  :Dict       =nn.ModuleList()
        for lyr_num in range(lowerCAmelCase__     ):
             _UpperCamelCase  :List[str]       =TaBlock(lowerCAmelCase__     )
             self.encoders.append(lowerCAmelCase__     )

        _UpperCamelCase  :str       =TaLayerNorm(lowerCAmelCase__     )
        _UpperCamelCase  :List[str]       =nn.Dropout(p=lowerCAmelCase__     )




   def  _UpperCamelCase		(    self					,      lowerCAmelCase__					,      lowerCAmelCase__     )				->     Any:
        """simple docstring"""





        _UpperCamelCase  :str       =self.input_proj(lowerCAmelCase__     )

        # terminal relative positional encodings
        _UpperCamelCase  :List[str]       =encoder_inputs.shape[1]
        _UpperCamelCase  :Union[str, Any]       =torch.arange(lowerCAmelCase__					,      device=encoder_inputs.device     )

        _UpperCamelCase  :Dict       =encoder_inputs_mask.sum(-1     )
        _UpperCamelCase  :Optional[Any]       =torch.roll(input_positions.unsqueeze(0     )					,      tuple(seq_lens.tolist()     )					,      dims=0     )
        x += self.position_encoding(lowerCAmelCase__     )

        _UpperCamelCase  :List[str]       =self.dropout_pre(lowerCAmelCase__     )

        # inverted the attention mask
        _UpperCamelCase  :Dict       =encoder_inputs.size()
        _UpperCamelCase  :Any       =self.get_extended_attention_mask(lowerCAmelCase__					,      lowerCAmelCase__     )

        for lyr in self.encoders:
             _UpperCamelCase  :Union[str, Any]       =lyr(lowerCAmelCase__					,      lowerCAmelCase__     )[0]
        _UpperCamelCase  :str       =self.layer_norm(lowerCAmelCase__     )

        return self.dropout_post(lowerCAmelCase__     ), encoder_inputs_mask






'''simple docstring'''


from __future__ import annotations

from collections.abc import Callable




def       A							(      _UpperCAmelCase   :				Callable[[int | float], int | float]						,_UpperCAmelCase   :				int | float						,_UpperCAmelCase   :				int | float						,_UpperCAmelCase   :				int = 1_0_0						,)  ->				float:


  '''simple docstring'''




  __lowerCAmelCase		:    Dict			     =  x_start
  __lowerCAmelCase		:    Tuple			     =  fnc(_UpperCAmelCase					)
  __lowerCAmelCase		:    Optional[int]			     =  0.0

  for _ in range(_UpperCAmelCase					):
    # Approximates small segments of curve as linear and solve
    # for trapezoidal area
    __lowerCAmelCase		:    Optional[int]			     =  (x_end - x_start) / steps + xa
    __lowerCAmelCase		:    Optional[Any]			     =  fnc(_UpperCAmelCase					)
    area += abs(fxa + fxa					) * (xa - xa) / 2

    # Increment step
    __lowerCAmelCase		:    Optional[Any]			     =  xa
    __lowerCAmelCase		:    List[Any]			     =  fxa
  return area


if __name__ == "__main__":




    def       A							(      _UpperCAmelCase   :				List[Any]					)  ->				List[Any]:


      '''simple docstring'''




      return x**3

    print("f(x) = x^3")
    print("The area between the curve, x = -10, x = 10 and the x axis is:")
    A_				     =							10
    while i <= 10_00_00:
        A_				     =							trapezoidal_area(f, -5, 5, i)
        print(F'''with {i} steps: {area}''')
        i *= 10





