"""simple docstring"""




from abc import ABC, abstractmethod
from typing import List, Optional
class 			UpperCamelCase__(	UpperCamelCase_       ):





						def __init__(				self   )    -> List[str]:
													self.test()





						def  snake_case__		(				self   )    -> Tuple:
													A__		   =							0
													A__		   =							False
													while not completed:
																				if counter == 1:
																											self.reset()
																				A__		   =							self.advance()
																				if not self.does_advance(lowercase_   ):
																											raise Exception(
																											    'Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.'   )

																				A__		   =							self.update(lowercase_   )
																				counter += 1

																				if counter > 1_00_00:
																											raise Exception('update() does not fulfill the constraint.'   )

													if self.remaining() != 0:
																				raise Exception('Custom Constraint is not defined correctly.'   )





						@abstractmethod
						def  snake_case__		(				self   )    -> List[str]:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )





						@abstractmethod
						def  snake_case__		(				self						,__UpperCAmelCase   )    -> int:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )





						@abstractmethod
						def  snake_case__		(				self						,__UpperCAmelCase   )    -> str:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )





						@abstractmethod
						def  snake_case__		(				self   )    -> Union[str, Any]:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )





						@abstractmethod
						def  snake_case__		(				self   )    -> int:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )





						@abstractmethod
						def  snake_case__		(				self						,__UpperCAmelCase=False   )    -> Union[str, Any]:
													raise NotImplementedError(
													    f'''{self.__class__} is an abstract class. Only classes inheriting this class can be called.'''   )






class 			UpperCamelCase__(	UpperCamelCase_       ):





						def __init__(				self						,__UpperCAmelCase   )    -> Any:
													super(lowercase_						,self   ).__init__()

													if not isinstance(lowercase_						,lowercase_   ) or len(lowercase_   ) == 0:
																				raise ValueError(f'''`token_ids` has to be a non-empty list, but is {token_ids}.'''   )
													if any((not isinstance(lowercase_						,lowercase_   ) or token_id < 0) for token_id in token_ids   ):
																				raise ValueError(f'''Each list in `token_ids` has to be a list of positive integers, but is {token_ids}.'''   )

													A__		   =							token_ids

													A__		   =							len(self.token_ids   )
													A__		   =							-1  # the index of the currently fulfilled step
													A__		   =							False





						def  snake_case__		(				self   )    -> Union[str, Any]:




													if self.completed:
																				return None
													return self.token_ids[self.fulfilled_idx + 1]





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> List[str]:




													if not isinstance(lowercase_						,lowercase_   ):
																				raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(lowercase_   )}'''   )

													if self.completed:
																				return False

													return token_id == self.token_ids[self.fulfilled_idx + 1]





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> List[str]:




													if not isinstance(lowercase_						,lowercase_   ):
																				raise ValueError(f'''`token_id` has to be an `int`, but is {token_id} of type {type(lowercase_   )}'''   )

													A__		   =							False
													A__		   =							False
													A__		   =							False

													if self.does_advance(lowercase_   ):
																				self.fulfilled_idx += 1
																				A__		   =							True
																				if self.fulfilled_idx == (self.seqlen - 1):
																											A__		   =							True
																				A__		   =							completed
													else:
																				# failed to make progress.
																				A__		   =							True
																				self.reset()
													return stepped, completed, reset





						def  snake_case__		(				self   )    -> int:
													A__		   =							False
													A__		   =							0





						def  snake_case__		(				self   )    -> Any:
													return self.seqlen - (self.fulfilled_idx + 1)





						def  snake_case__		(				self						,__UpperCAmelCase=False   )    -> Optional[int]:
													A__		   =							PhrasalConstraint(self.token_ids   )

													if stateful:
																				A__		   =							self.seqlen
																				A__		   =							self.fulfilled_idx
																				A__		   =							self.completed

													return new_constraint






class 			UpperCamelCase__:





						def __init__(				self						,__UpperCAmelCase						,__UpperCAmelCase=True   )    -> Any:
													A__		   =							max([len(lowercase_   ) for one in nested_token_ids]   )

													A__		   =							{}
													for token_ids in nested_token_ids:
																				A__		   =							root
																				for tidx, token_id in enumerate(lowercase_   ):
																											if token_id not in level:
																																		A__		   =							{}

																											A__		   =							level[token_id]

													if no_subsets and self.has_subsets(lowercase_						,lowercase_   ):
																				raise ValueError(
																				    'Each list in `nested_token_ids` can\'t be a complete subset of another list, but is'
																				    f''' {nested_token_ids}.'''   )

													A__		   =							root





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> int:
													A__		   =							self.trie

													for current_token in current_seq:
																				A__		   =							start[current_token]

													A__		   =							list(start.keys()   )

													return next_tokens





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Tuple:
													A__		   =							self.next_tokens(lowercase_   )

													return len(lowercase_   ) == 0





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Dict:
													A__		   =							list(root.values()   )
													if len(lowercase_   ) == 0:
																				return 1
													else:
																				return sum([self.count_leaves(lowercase_   ) for nn in next_nodes]   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase   )    -> Optional[int]:
													A__		   =							self.count_leaves(lowercase_   )
													return len(lowercase_   ) != leaf_count






class 			UpperCamelCase__(	UpperCamelCase_       ):





						def __init__(				self						,__UpperCAmelCase   )    -> str:
													super(lowercase_						,self   ).__init__()

													if not isinstance(lowercase_						,lowercase_   ) or len(lowercase_   ) == 0:
																				raise ValueError(f'''`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}.'''   )
													if any(not isinstance(lowercase_						,lowercase_   ) for token_ids in nested_token_ids   ):
																				raise ValueError(f'''`nested_token_ids` has to be a list of lists, but is {nested_token_ids}.'''   )
													if any(
													    any((not isinstance(lowercase_						,lowercase_   ) or token_id < 0) for token_id in token_ids   )
													    for token_ids in nested_token_ids   ):
																				raise ValueError(
																				    f'''Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}.'''   )

													A__		   =							DisjunctiveTrie(lowercase_   )
													A__		   =							nested_token_ids

													A__		   =							self.trie.max_height
													A__		   =							[]
													A__		   =							False





						def  snake_case__		(				self   )    -> List[Any]:
													A__		   =							self.trie.next_tokens(self.current_seq   )

													if len(lowercase_   ) == 0:
																				return None
													else:
																				return token_list





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Any:




													if not isinstance(lowercase_						,lowercase_   ):
																				raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(lowercase_   )}'''   )

													A__		   =							self.trie.next_tokens(self.current_seq   )

													return token_id in next_tokens





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> int:




													if not isinstance(lowercase_						,lowercase_   ):
																				raise ValueError(f'''`token_id` is supposed to be type `int`, but is {token_id} of type {type(lowercase_   )}'''   )

													A__		   =							False
													A__		   =							False
													A__		   =							False

													if self.does_advance(lowercase_   ):
																				self.current_seq.append(lowercase_   )
																				A__		   =							True
													else:
																				A__		   =							True
																				self.reset()

													A__		   =							self.trie.reached_leaf(self.current_seq   )
													A__		   =							completed

													return stepped, completed, reset





						def  snake_case__		(				self   )    -> List[str]:
													A__		   =							False
													A__		   =							[]





						def  snake_case__		(				self   )    -> List[Any]:




													if self.completed:
																				# since this can be completed without reaching max height
																				return 0
													else:
																				return self.seqlen - len(self.current_seq   )





						def  snake_case__		(				self						,__UpperCAmelCase=False   )    -> Dict:
													A__		   =							DisjunctiveConstraint(self.token_ids   )

													if stateful:
																				A__		   =							self.seqlen
																				A__		   =							self.current_seq
																				A__		   =							self.completed

													return new_constraint






class 			UpperCamelCase__:





						def __init__(				self						,__UpperCAmelCase   )    -> Dict:
													A__		   =							constraints

													# max # of steps required to fulfill a given constraint
													A__		   =							max([c.seqlen for c in constraints]   )
													A__		   =							len(lowercase_   )
													A__		   =							False

													self.init_state()





						def  snake_case__		(				self   )    -> int:
													A__		   =							[]
													A__		   =							None
													A__		   =							[constraint.copy(stateful=lowercase_   ) for constraint in self.constraints]





						def  snake_case__		(				self   )    -> str:
													A__		   =							0
													if self.inprogress_constraint:
																				# extra points for having a constraint mid-fulfilled
																				add += self.max_seqlen - self.inprogress_constraint.remaining()

													return (len(self.complete_constraints   ) * self.max_seqlen) + add





						def  snake_case__		(				self   )    -> Optional[Any]:
													A__		   =							[]
													if self.inprogress_constraint is None:
																				for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
																											A__		   =							constraint.advance()
																											if isinstance(lowercase_						,lowercase_   ):
																																		token_list.append(lowercase_   )
																											elif isinstance(lowercase_						,lowercase_   ):
																																		token_list.extend(lowercase_   )
													else:
																				A__		   =							self.inprogress_constraint.advance()
																				if isinstance(lowercase_						,lowercase_   ):
																											token_list.append(lowercase_   )
																				elif isinstance(lowercase_						,lowercase_   ):
																											token_list.extend(lowercase_   )

													if len(lowercase_   ) == 0:
																				return None
													else:
																				return token_list





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> List[str]:
													self.init_state()

													if token_ids is not None:
																				for token in token_ids:
																											# completes or steps **one** constraint
																											A__		   =							self.add(lowercase_   )

																											# the entire list of constraints are fulfilled
																											if self.completed:
																																		break





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Optional[Any]:




													if not isinstance(lowercase_						,lowercase_   ):
																				raise ValueError(f'''`token_id` should be an `int`, but is `{token_id}`.'''   )

													A__		   =							False, False

													if self.completed:
																				A__		   =							True
																				A__		   =							False
																				return complete, stepped

													if self.inprogress_constraint is not None:
																				# In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
																				# job, simply update the state

																				A__		   =							self.inprogress_constraint.update(lowercase_   )
																				if reset:
																											# 1. If the next token breaks the progress, then we must restart.
																											#     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

																											#     But that doesn't mean we self.init_state(), since we only reset the state for this particular
																											#     constraint, not the full list of constraints.

																											self.pending_constraints.append(self.inprogress_constraint.copy(stateful=lowercase_   )   )
																											A__		   =							None

																				if complete:
																											# 2. If the next token completes the constraint, move it to completed list, set
																											#     inprogress to None. If there are no pending constraints either, then this full list of constraints
																											#     is complete.

																											self.complete_constraints.append(self.inprogress_constraint   )
																											A__		   =							None

																											if len(self.pending_constraints   ) == 0:
																																		# we're done!
																																		A__		   =							True

													else:
																				# Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
																				# of constraints?

																				for cidx, pending_constraint in enumerate(self.pending_constraints   ):
																											if pending_constraint.does_advance(lowercase_   ):
																																		A__		   =							pending_constraint.update(lowercase_   )

																																		if not stepped:
																																									raise Exception(
																																									    '`constraint.update(token_id)` is not yielding incremental progress, '
																																									    'even though `constraint.does_advance(token_id)` is true.'   )

																																		if complete:
																																									self.complete_constraints.append(lowercase_   )
																																									A__		   =							None

																																		if not complete and stepped:
																																									A__		   =							pending_constraint

																																		if complete or stepped:
																																									# If we made any progress at all, then it's at least not a "pending constraint".

																																									A__		   =							(
																																									    self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
																																									)

																																									if len(self.pending_constraints   ) == 0 and self.inprogress_constraint is None:
																																																# If there's no longer any pending after this and no inprogress either, then we must be
																																																# complete.

																																																A__		   =							True

																																									break  # prevent accidentally stepping through multiple constraints with just one token.

													return complete, stepped





						def  snake_case__		(				self						,__UpperCAmelCase=True   )    -> Optional[int]:
													A__		   =							ConstraintListState(self.constraints   )  # we actually never though self.constraints objects
													# throughout this process. So it's at initialization state.

													if stateful:
																				A__		   =							[
																				    constraint.copy(stateful=lowercase_   ) for constraint in self.complete_constraints
																				]
																				if self.inprogress_constraint is not None:
																											A__		   =							self.inprogress_constraint.copy(stateful=lowercase_   )
																				A__		   =							[constraint.copy() for constraint in self.pending_constraints]

													return new_state









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


lowerCamelCase											=       logging.get_logger(__name__)

lowerCamelCase											=       {
    'transfo-xl-wt103': 'https://huggingface.co/transfo-xl-wt103/resolve/main/config.json',
}




class A  (   UpperCamelCase_     ):
      UpperCamelCase__							:  Dict      ='transfo-xl'
      UpperCamelCase__							:  int      =['mems']
      UpperCamelCase__							:  List[str]      ={
          'n_token': 'vocab_size',
          'hidden_size': 'd_model',
          'num_attention_heads': 'n_head',
          'num_hidden_layers': 'n_layer',
      }






      def __init__(					self						:     Tuple			,   lowercase_						:     List[Any]=26_7735			,   lowercase_						:     List[Any]=[2_0000, 4_0000, 20_0000]			,   lowercase_						:     Tuple=1024			,   lowercase_						:     Optional[int]=1024			,   lowercase_						:     str=16			,   lowercase_						:     int=64			,   lowercase_						:     Any=4096			,   lowercase_						:     List[Any]=4			,   lowercase_						:     List[Any]=False			,   lowercase_						:     List[str]=18			,   lowercase_						:     Tuple=1600			,   lowercase_						:     List[str]=1000			,   lowercase_						:     Any=True			,   lowercase_						:     str=True			,   lowercase_						:     Optional[int]=0			,   lowercase_						:     List[Any]=-1			,   lowercase_						:     Optional[int]=True			,   lowercase_						:     Any=0.1			,   lowercase_						:     Tuple=0.0			,   lowercase_						:     str=True			,   lowercase_						:     Union[str, Any]="normal"			,   lowercase_						:     Dict=0.01			,   lowercase_						:     Optional[Any]=0.01			,   lowercase_						:     List[Any]=0.02			,   lowercase_						:     List[Any]=1E-5			,   lowercase_						:     Tuple=0			,   **lowercase_						:     Tuple			,   )					->						Dict:
             """simple docstring"""




             _lowerCamelCase       :		Optional[Any]		=vocab_size
             _lowerCamelCase       :		Optional[Any]		=[]
             self.cutoffs.extend(lowercase_ )
             if proj_share_all_but_first:
                    _lowerCamelCase       :		List[str]		=[False] + [True] * len(self.cutoffs )
             else:
                    _lowerCamelCase       :		str		=[False] + [False] * len(self.cutoffs )
             _lowerCamelCase       :		str		=d_model
             _lowerCamelCase       :		str		=d_embed
             _lowerCamelCase       :		str		=d_head
             _lowerCamelCase       :		Dict		=d_inner
             _lowerCamelCase       :		Union[str, Any]		=div_val
             _lowerCamelCase       :		Dict		=pre_lnorm
             _lowerCamelCase       :		Tuple		=n_layer
             _lowerCamelCase       :		Optional[Any]		=n_head
             _lowerCamelCase       :		List[Any]		=mem_len
             _lowerCamelCase       :		List[Any]		=same_length
             _lowerCamelCase       :		Optional[int]		=attn_type
             _lowerCamelCase       :		List[str]		=clamp_len
             _lowerCamelCase       :		int		=sample_softmax
             _lowerCamelCase       :		List[Any]		=adaptive
             _lowerCamelCase       :		List[str]		=dropout
             _lowerCamelCase       :		Any		=dropatt
             _lowerCamelCase       :		Dict		=untie_r
             _lowerCamelCase       :		List[Any]		=init
             _lowerCamelCase       :		List[str]		=init_range
             _lowerCamelCase       :		int		=proj_init_std
             _lowerCamelCase       :		Optional[int]		=init_std
             _lowerCamelCase       :		Tuple		=layer_norm_epsilon
             super().__init__(eos_token_id=lowercase_			,   **lowercase_ )






      @property
      def        lowerCamelCase       (					self						:     List[str] )					->						Dict:
             """simple docstring"""




             logger.info(F'''The model {self.model_type} is one of the few models that has no sequence length limit.''' )
             return -1






      @max_position_embeddings.setter
      def        lowerCamelCase       (					self						:     int			,   lowercase_						:     int )					->						List[str]:
             """simple docstring"""




             raise NotImplementedError(
                 F'''The model {self.model_type} is one of the few models that has no sequence length limit.''' )


