



from __future__ import annotations

from collections.abc import Callable






def A__   (					UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_ = 1_0_0  ,  ):
						_UpperCamelCase :		Tuple			    =       x_start
						_UpperCamelCase :		Optional[int]			    =       fnc(lowerCamelCase_							)
						_UpperCamelCase :		Optional[int]			    =       0.0
						for _ in range(lowerCamelCase_							):
												# Approximates small segments of curve as linear and solve
												# for trapezoidal area
												_UpperCamelCase :		int			    =       (x_end - x_start) / steps + xa
												_UpperCamelCase :		Union[str, Any]			    =       fnc(lowerCamelCase_							)
												area += abs(fxa + fxa							) * (xa - xa) / 2
												# Increment step
												_UpperCamelCase :		Any			    =       xa
												_UpperCamelCase :		str			    =       fxa
						return area


if __name__ == "__main__":






					def A__   (					UpperCAmelCase_							):
											return x**3 + x**2

					print('f(x) = x^3 + x^2')
					print('The area between the curve, x = -5, x = 5 and the x axis is:')
					snake_case_			:     List[str]  	=  10
					while i <= 100000:
										print(F"""with {i} steps: {trapezoidal_area(f, -5, 5, i)}""")
										i *= 10







'''simple docstring'''
from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


snake_case_			:     int  	=  logging.get_logger(__name__)

snake_case_			:     List[str]  	=  {
    'EleutherAI/gpt-j-6B': 'https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}






class 							lowercase__     (							lowercase       ):
	lowercase__      =      """gptj"""
	lowercase__      =      {
	    """max_position_embeddings""": """n_positions""",
	    """hidden_size""": """n_embd""",
	    """num_attention_heads""": """n_head""",
	    """num_hidden_layers""": """n_layer""",
	}





	def __init__(			self :    Any			,lowerCamelCase__ :    Optional[Any]=50400			,lowerCamelCase__ :    Tuple=2048			,lowerCamelCase__ :    Tuple=4096			,lowerCamelCase__ :    int=28			,lowerCamelCase__ :    Optional[Any]=16			,lowerCamelCase__ :    Optional[Any]=64			,lowerCamelCase__ :    List[Any]=None			,lowerCamelCase__ :    List[Any]="gelu_new"			,lowerCamelCase__ :    Optional[Any]=0.0			,lowerCamelCase__ :    List[str]=0.0			,lowerCamelCase__ :    List[Any]=0.0			,lowerCamelCase__ :    Tuple=1E-5			,lowerCamelCase__ :    int=0.0_2			,lowerCamelCase__ :    Any=True			,lowerCamelCase__ :    str=50256			,lowerCamelCase__ :    Any=50256			,lowerCamelCase__ :    Tuple=False			,**lowerCamelCase__ :    Optional[Any]			,):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       vocab_size
							_UpperCamelCase :		Optional[Any]			    =       n_positions
							_UpperCamelCase :		Union[str, Any]			    =       n_embd
							_UpperCamelCase :		Any			    =       n_layer
							_UpperCamelCase :		Optional[int]			    =       n_head
							_UpperCamelCase :		List[str]			    =       n_inner
							_UpperCamelCase :		List[Any]			    =       rotary_dim
							_UpperCamelCase :		int			    =       activation_function
							_UpperCamelCase :		Dict			    =       resid_pdrop
							_UpperCamelCase :		Any			    =       embd_pdrop
							_UpperCamelCase :		Union[str, Any]			    =       attn_pdrop
							_UpperCamelCase :		Union[str, Any]			    =       layer_norm_epsilon
							_UpperCamelCase :		Optional[Any]			    =       initializer_range
							_UpperCamelCase :		str			    =       use_cache

							_UpperCamelCase :		Union[str, Any]			    =       bos_token_id
							_UpperCamelCase :		Any			    =       eos_token_id

							super().__init__(
							    bos_token_id=lowerCamelCase__			,eos_token_id=lowerCamelCase__			,tie_word_embeddings=lowerCamelCase__			,**lowerCamelCase__			)






class 							lowercase__     (							lowercase       ):





	def __init__(			self :    Tuple			,lowerCamelCase__ :    PretrainedConfig			,lowerCamelCase__ :    str = "default"			,lowerCamelCase__ :    List[PatchingSpec] = None			,lowerCamelCase__ :    bool = False			,):







							'''simple docstring'''
							super().__init__(lowerCamelCase__			,task=lowerCamelCase__			,patching_specs=lowerCamelCase__			,use_past=lowerCamelCase__			)
							if not getattr(self._config			,'pad_token_id'			,lowerCamelCase__			):
													# TODO: how to do that better?
													_UpperCamelCase :		int			    =       0





	@property
	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		List[str]			    =       OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}			)
							if self.use_past:
													self.fill_with_past_key_values_(lowerCamelCase__			,direction='inputs'			)
													_UpperCamelCase :		Tuple			    =       {0: 'batch', 1: 'past_sequence + sequence'}
							else:
													_UpperCamelCase :		Any			    =       {0: 'batch', 1: 'sequence'}

							return common_inputs





	@property
	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							return self._config.n_layer





	@property
	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							return self._config.n_head





	def      UpperCamelCase_  (			self :    List[str]			,lowerCamelCase__ :    PreTrainedTokenizer			,lowerCamelCase__ :    int = -1			,lowerCamelCase__ :    int = -1			,lowerCamelCase__ :    bool = False			,lowerCamelCase__ :    Optional[TensorType] = None			,):







							'''simple docstring'''
							_UpperCamelCase :		Union[str, Any]			    =       super(lowerCamelCase__			,self			).generate_dummy_inputs(
							    lowerCamelCase__			,batch_size=lowerCamelCase__			,seq_length=lowerCamelCase__			,is_pair=lowerCamelCase__			,framework=lowerCamelCase__			)

							# We need to order the input in the way they appears in the forward()
							_UpperCamelCase :		Tuple			    =       OrderedDict({'input_ids': common_inputs['input_ids']}			)

							# Need to add the past_keys
							if self.use_past:
													if not is_torch_available():
																			raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'			)
													else:
																			import torch

																			_UpperCamelCase    ,      _UpperCamelCase :		str			    =       common_inputs['input_ids'].shape
																			# Not using the same length for past_key_values
																			_UpperCamelCase :		Optional[int]			    =       seqlen + 2
																			_UpperCamelCase :		List[Any]			    =       (
																			    batch,
																			    self.num_attention_heads,
																			    past_key_values_length,
																			    self._config.hidden_size // self.num_attention_heads,
																			)
																			_UpperCamelCase :		Optional[Any]			    =       [
																			    (torch.zeros(lowerCamelCase__			), torch.zeros(lowerCamelCase__			)) for _ in range(self.num_layers			)
																			]

							_UpperCamelCase :		Union[str, Any]			    =       common_inputs['attention_mask']
							if self.use_past:
													_UpperCamelCase :		Any			    =       ordered_inputs['attention_mask'].dtype
													_UpperCamelCase :		List[str]			    =       torch.cat(
													    [ordered_inputs['attention_mask'], torch.ones(lowerCamelCase__			,lowerCamelCase__			,dtype=lowerCamelCase__			)]			,dim=1			)

							return ordered_inputs





	@property
	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							return 13


