






'''simple docstring'''
from abc import ABC, abstractmethod
from typing import List, Optional






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):




 def __init__( self		:							Optional[int] )		->  Optional[int]:
       # test for the above condition
       self.test()




 def        __magic_name__		( self		:							Optional[Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			List[str]													=0
       SCREAMING_SNAKE_CASE__       :			Any													=False
       while not completed:
             if counter == 1:
                   self.reset()
             SCREAMING_SNAKE_CASE__       :			Dict													=self.advance()
             if not self.does_advance(__lowercase ):
                   raise Exception(
                       '''Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true.''' )

             SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Optional[Any]													=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        __magic_name__		( self		:							List[str] )		->  int:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )




 @abstractmethod
 def        __magic_name__		( self		:							List[str]   , __lowercase		:							int )		->  Tuple:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )




 @abstractmethod
 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							int )		->  Union[str, Any]:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )




 @abstractmethod
 def        __magic_name__		( self		:							Dict )		->  Tuple:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )




 @abstractmethod
 def        __magic_name__		( self		:							Any )		->  Optional[Any]:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )




 @abstractmethod
 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							List[str]=False )		->  int:
       raise NotImplementedError(
           F"{self.__class__} is an abstract class. Only classes inheriting this class can be called." )






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):




 def __init__( self		:							Union[str, Any]   , __lowercase		:							List[int] )		->  int:
       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}." )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=token_ids

       SCREAMING_SNAKE_CASE__       :			Dict													=len(self.token_ids )
       SCREAMING_SNAKE_CASE__       :			Tuple													=-1  # the index of the currently fulfilled step
       SCREAMING_SNAKE_CASE__       :			List[Any]													=False




 def        __magic_name__		( self		:							List[str] )		->  List[Any]:
       if self.completed:
             return None
       return self.token_ids[self.fulfilled_idx + 1]




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							int )		->  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        __magic_name__		( self		:							Tuple   , __lowercase		:							int )		->  str:
       if not isinstance(__lowercase   , __lowercase ):
             raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(__lowercase )}" )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=False
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=False
       SCREAMING_SNAKE_CASE__       :			str													=False

       if self.does_advance(__lowercase ):
             self.fulfilled_idx += 1
             SCREAMING_SNAKE_CASE__       :			List[Any]													=True
             if self.fulfilled_idx == (self.seqlen - 1):
                   SCREAMING_SNAKE_CASE__       :			int													=True
             SCREAMING_SNAKE_CASE__       :			Any													=completed
       else:
             # failed to make progress.
             SCREAMING_SNAKE_CASE__       :			int													=True
             self.reset()
       return stepped, completed, reset




 def        __magic_name__		( self		:							Optional[int] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			int													=False
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=0




 def        __magic_name__		( self		:							Optional[int] )		->  List[Any]:
       return self.seqlen - (self.fulfilled_idx + 1)




 def        __magic_name__		( self		:							int   , __lowercase		:							int=False )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=PhrasalConstraint(self.token_ids )

       if stateful:
             SCREAMING_SNAKE_CASE__       :			Dict													=self.seqlen
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.fulfilled_idx
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.completed

       return new_constraint






class        __SCREAMING_SNAKE_CASE :




 def __init__( self		:							Optional[Any]   , __lowercase		:							List[List[int]]   , __lowercase		:							Optional[Any]=True )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=max([len(__lowercase ) for one in nested_token_ids] )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													={}
       for token_ids in nested_token_ids:
             SCREAMING_SNAKE_CASE__       :			str													=root
             for tidx, token_id in enumerate(__lowercase ):
                   if token_id not in level:
                         SCREAMING_SNAKE_CASE__       :			str													={}

                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=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}." )

       SCREAMING_SNAKE_CASE__       :			str													=root




 def        __magic_name__		( self		:							List[str]   , __lowercase		:							int )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=self.trie

       for current_token in current_seq:
             SCREAMING_SNAKE_CASE__       :			str													=start[current_token]

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=list(start.keys() )

       return next_tokens




 def        __magic_name__		( self		:							Dict   , __lowercase		:							Union[str, Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=self.next_tokens(__lowercase )

       return len(__lowercase ) == 0




 def        __magic_name__		( self		:							str   , __lowercase		:							Dict )		->  int:
       SCREAMING_SNAKE_CASE__       :			Tuple													=list(root.values() )
       if len(__lowercase ) == 0:
             return 1
       else:
             return sum([self.count_leaves(__lowercase ) for nn in next_nodes] )




 def        __magic_name__		( self		:							Union[str, Any]   , __lowercase		:							List[str]   , __lowercase		:							Optional[Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.count_leaves(__lowercase )
       return len(__lowercase ) != leaf_count






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):




 def __init__( self		:							Any   , __lowercase		:							List[List[int]] )		->  Tuple:
       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}." )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=DisjunctiveTrie(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Dict													=nested_token_ids

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.trie.max_height
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=[]
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=False




 def        __magic_name__		( self		:							Union[str, Any] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Dict													=self.trie.next_tokens(self.current_seq )

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




 def        __magic_name__		( self		:							int   , __lowercase		:							int )		->  List[str]:
       if not isinstance(__lowercase   , __lowercase ):
             raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(__lowercase )}" )

       SCREAMING_SNAKE_CASE__       :			Tuple													=self.trie.next_tokens(self.current_seq )

       return token_id in next_tokens




 def        __magic_name__		( self		:							Dict   , __lowercase		:							int )		->  Optional[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 )}" )

       SCREAMING_SNAKE_CASE__       :			Tuple													=False
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=False
       SCREAMING_SNAKE_CASE__       :			Any													=False

       if self.does_advance(__lowercase ):
             self.current_seq.append(__lowercase )
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=True
       else:
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=True
             self.reset()

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.trie.reached_leaf(self.current_seq )
       SCREAMING_SNAKE_CASE__       :			Any													=completed

       return stepped, completed, reset




 def        __magic_name__		( self		:							Any )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Dict													=False
       SCREAMING_SNAKE_CASE__       :			Tuple													=[]




 def        __magic_name__		( self		:							List[str] )		->  Union[str, Any]:
       if self.completed:
             # since this can be completed without reaching max height
             return 0
       else:
             return self.seqlen - len(self.current_seq )




 def        __magic_name__		( self		:							List[str]   , __lowercase		:							Optional[int]=False )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			Any													=DisjunctiveConstraint(self.token_ids )

       if stateful:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.seqlen
             SCREAMING_SNAKE_CASE__       :			str													=self.current_seq
             SCREAMING_SNAKE_CASE__       :			Tuple													=self.completed

       return new_constraint






class        __SCREAMING_SNAKE_CASE :




 def __init__( self		:							List[Any]   , __lowercase		:							List[Constraint] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			Dict													=constraints

       # max # of steps required to fulfill a given constraint
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=max([c.seqlen for c in constraints] )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=len(__lowercase )
       SCREAMING_SNAKE_CASE__       :			int													=False

       self.init_state()




 def        __magic_name__		( self		:							Optional[Any] )		->  str:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=[]
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=None
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=[constraint.copy(stateful=__lowercase ) for constraint in self.constraints]




 def        __magic_name__		( self		:							List[str] )		->  str:
       SCREAMING_SNAKE_CASE__       :			Any													=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        __magic_name__		( self		:							Union[str, Any] )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=[]
       if self.inprogress_constraint is None:
             for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=constraint.advance()
                   if isinstance(__lowercase   , __lowercase ):
                         token_list.append(__lowercase )
                   elif isinstance(__lowercase   , __lowercase ):
                         token_list.extend(__lowercase )
       else:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=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        __magic_name__		( self		:							Tuple   , __lowercase		:							Optional[List[int]] )		->  Union[str, Any]:
       self.init_state()

       if token_ids is not None:
             for token in token_ids:
                   # completes or steps **one** constraint
                   SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.add(__lowercase )

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




 def        __magic_name__		( self		:							Union[str, Any]   , __lowercase		:							int )		->  Optional[int]:
       if not isinstance(__lowercase   , __lowercase ):
             raise ValueError(F"`token_id` should be an `int`, but is `{token_id}`." )

       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			str													=False, False

       if self.completed:
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=True
             SCREAMING_SNAKE_CASE__       :			int													=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

             SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=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 ) )
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=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 )
                   SCREAMING_SNAKE_CASE__       :			str													=None

                   if len(self.pending_constraints ) == 0:
                         # we're done!
                         SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=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 ):
                         SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Optional[Any]													=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 )
                               SCREAMING_SNAKE_CASE__       :			Dict													=None

                         if not complete and stepped:
                               SCREAMING_SNAKE_CASE__       :			List[str]													=pending_constraint

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

                               SCREAMING_SNAKE_CASE__       :			List[str]													=(
                                   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.

                                     SCREAMING_SNAKE_CASE__       :			str													=True

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

       return complete, stepped




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							Dict=True )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			List[str]													=ConstraintListState(self.constraints )  # we actually never though self.constraints objects
       # throughout this process. So it's at initialization state.

       if stateful:
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=[
                 constraint.copy(stateful=__lowercase ) for constraint in self.complete_constraints
             ]
             if self.inprogress_constraint is not None:
                   SCREAMING_SNAKE_CASE__       :			List[str]													=self.inprogress_constraint.copy(stateful=__lowercase )
             SCREAMING_SNAKE_CASE__       :			Dict													=[constraint.copy() for constraint in self.pending_constraints]

       return new_state







'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_					=	logging.get_logger(__name__)

a_					=	{
    'microsoft/biogpt': 'https://huggingface.co/microsoft/biogpt/resolve/main/config.json',
    # See all BioGPT models at https://huggingface.co/models?filter=biogpt
}






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):
 snake_case_												=							"""biogpt"""




 def __init__( self		:							str   , __lowercase		:							Union[str, Any]=4_23_84   , __lowercase		:							Union[str, Any]=10_24   , __lowercase		:							Any=24   , __lowercase		:							Any=16   , __lowercase		:							Optional[Any]=40_96   , __lowercase		:							Any="gelu"   , __lowercase		:							Optional[Any]=0.1   , __lowercase		:							List[Any]=0.1   , __lowercase		:							Union[str, Any]=10_24   , __lowercase		:							List[Any]=0.02   , __lowercase		:							Tuple=1e-12   , __lowercase		:							Optional[Any]=True   , __lowercase		:							Optional[Any]=True   , __lowercase		:							Any=0.0   , __lowercase		:							int=0.0   , __lowercase		:							str=1   , __lowercase		:							int=0   , __lowercase		:							Optional[int]=2   , **__lowercase		:							Dict   , )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=vocab_size
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=max_position_embeddings
       SCREAMING_SNAKE_CASE__       :			str													=hidden_size
       SCREAMING_SNAKE_CASE__       :			int													=num_hidden_layers
       SCREAMING_SNAKE_CASE__       :			Tuple													=num_attention_heads
       SCREAMING_SNAKE_CASE__       :			Any													=intermediate_size
       SCREAMING_SNAKE_CASE__       :			int													=hidden_act
       SCREAMING_SNAKE_CASE__       :			List[Any]													=hidden_dropout_prob
       SCREAMING_SNAKE_CASE__       :			Dict													=attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=initializer_range
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=layer_norm_eps
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=scale_embedding
       SCREAMING_SNAKE_CASE__       :			str													=use_cache
       SCREAMING_SNAKE_CASE__       :			str													=layerdrop
       SCREAMING_SNAKE_CASE__       :			Dict													=activation_dropout
       super().__init__(pad_token_id=__lowercase   , bos_token_id=__lowercase   , eos_token_id=__lowercase   , **__lowercase )