

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


_UpperCamelCase 			=		logging.get_logger(__name__)

_UpperCamelCase 			=		{
    "tanreinama/GPTSAN-2.8B-spout_is_uniform": (
        "https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"
    ),
}







class   __lowercase      (_UpperCAmelCase ):
 _UpperCamelCase			  =  """gptsan-japanese"""
 _UpperCamelCase			  =  [
     """past_key_values""",
 ]
 _UpperCamelCase			  =  {
     """hidden_size""": """d_model""",
     """num_attention_heads""": """num_heads""",
     """num_hidden_layers""": """num_layers""",
 }
 def __init__(							self      ,							A_=3_6000      ,							A_=1280      ,							A_=1024      ,							A_=8192      ,							A_=4096      ,							A_=128      ,							A_=10      ,							A_=0      ,							A_=16      ,							A_=16      ,							A_=128      ,							A_=0.0      ,							A_=1e-5      ,							A_=False      ,							A_=0.0      ,							A_="float32"      ,							A_=False      ,							A_=False      ,							A_=False      ,							A_=0.002      ,							A_=False      ,							A_=True      ,							A_=3_5998      ,							A_=3_5995      ,							A_=3_5999      ,							**A_      ,							)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[Any]					=					vocab_size
       __lowerCAmelCase					:						List[str]					=					max_position_embeddings
       __lowerCAmelCase					:						Any					=					d_model
       __lowerCAmelCase					:						List[Any]					=					d_ff
       __lowerCAmelCase					:						List[str]					=					d_ext
       __lowerCAmelCase					:						Optional[int]					=					d_spout
       __lowerCAmelCase					:						int					=					num_switch_layers
       __lowerCAmelCase					:						str					=					num_ext_layers
       __lowerCAmelCase					:						Optional[Any]					=					num_switch_layers + num_ext_layers
       __lowerCAmelCase					:						Union[str, Any]					=					num_heads
       __lowerCAmelCase					:						List[Any]					=					num_experts
       __lowerCAmelCase					:						int					=					expert_capacity
       __lowerCAmelCase					:						List[Any]					=					dropout_rate
       __lowerCAmelCase					:						Dict					=					layer_norm_epsilon
       __lowerCAmelCase					:						int					=					router_bias
       __lowerCAmelCase					:						str					=					router_jitter_noise
       __lowerCAmelCase					:						Union[str, Any]					=					router_dtype
       __lowerCAmelCase					:						Any					=					router_ignore_padding_tokens
       __lowerCAmelCase					:						Dict					=					output_hidden_states
       __lowerCAmelCase					:						Union[str, Any]					=					output_attentions
       __lowerCAmelCase					:						Union[str, Any]					=					initializer_factor
       __lowerCAmelCase					:						int					=					output_router_logits
       __lowerCAmelCase					:						Optional[int]					=					use_cache

       super().__init__(
           separator_token_id=A_      ,							pad_token_id=A_      ,							eos_token_id=A_      ,							**A_      ,							)





import unicodedata
from dataclasses import dataclass
from typing import Optional, Union

import numpy as np

from transformers.data.data_collator import DataCollatorMixin
from transformers.file_utils import PaddingStrategy
from transformers.tokenization_utils_base import PreTrainedTokenizerBase







def 		_lowercase (     lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__						):
      if isinstance(lowercase__   ,	lowercase__						):
            __lowerCAmelCase					:						Dict					=					np.full((len(lowercase__						), sequence_length, 2)   ,	lowercase__						)
      else:
            __lowerCAmelCase					:						Optional[int]					=					np.full((len(lowercase__						), sequence_length)   ,	lowercase__						)

      for i, tensor in enumerate(lowercase__						):
            if padding_side == "right":
                  if isinstance(lowercase__   ,	lowercase__						):
                        __lowerCAmelCase					:						Union[str, Any]					=					tensor[:sequence_length]
                  else:
                        __lowerCAmelCase					:						int					=					tensor[:sequence_length]
            else:
                  if isinstance(lowercase__   ,	lowercase__						):
                        __lowerCAmelCase					:						Union[str, Any]					=					tensor[:sequence_length]
                  else:
                        __lowerCAmelCase					:						Optional[Any]					=					tensor[:sequence_length]

      return out_tensor.tolist()







def 		_lowercase (     lowercase__						):
      __lowerCAmelCase					:						Union[str, Any]					=					ord(lowercase__						)
      if (cp >= 3_3 and cp <= 4_7) or (cp >= 5_8 and cp <= 6_4) or (cp >= 9_1 and cp <= 9_6) or (cp >= 1_2_3 and cp <= 1_2_6):
            return True
      __lowerCAmelCase					:						int					=					unicodedata.category(lowercase__						)
      if cat.startswith('''P'''						):
            return True
      return False







@dataclass
class   __lowercase      (_UpperCAmelCase ):
 _UpperCamelCase			  =  42
 _UpperCamelCase			  =  True
 _UpperCamelCase			  =  None
 _UpperCamelCase			  =  None
 _UpperCamelCase			  =  -100
 _UpperCamelCase			  =  "pt"
 def 	UpperCamelCase__  (							self      ,							A_					)					->Optional[int]:



       '''simple docstring'''





       import torch

       __lowerCAmelCase					:						List[str]					=					'''label''' if '''label''' in features[0].keys() else '''labels'''
       __lowerCAmelCase					:						Union[str, Any]					=					[feature[label_name] for feature in features] if label_name in features[0].keys() else None
       __lowerCAmelCase					:						List[Any]					=					self.tokenizer.pad(
           A_      ,							padding=self.padding      ,							max_length=self.max_length      ,							pad_to_multiple_of=self.pad_to_multiple_of      ,							return_tensors='''pt''' if labels is None else None      ,							)

       if labels is None:
             return batch

       __lowerCAmelCase					:						Dict					=					torch.tensor(batch['''entity_ids''']					).shape[1]
       __lowerCAmelCase					:						Optional[int]					=					self.tokenizer.padding_side
       if padding_side == "right":
             __lowerCAmelCase					:						Any					=					[
                 list(A_					) + [self.label_pad_token_id] * (sequence_length - len(A_					)) for label in labels
             ]
       else:
             __lowerCAmelCase					:						Optional[int]					=					[
                 [self.label_pad_token_id] * (sequence_length - len(A_					)) + list(A_					) for label in labels
             ]

       __lowerCAmelCase					:						Tuple					=					[feature['''ner_tags'''] for feature in features]
       __lowerCAmelCase					:						List[Any]					=					padding_tensor(A_      ,							-1      ,							A_      ,							A_					)
       __lowerCAmelCase					:						Optional[int]					=					[feature['''original_entity_spans'''] for feature in features]
       __lowerCAmelCase					:						Any					=					padding_tensor(A_      ,							(-1, -1)      ,							A_      ,							A_					)
       __lowerCAmelCase					:						Optional[Any]					=					{k: torch.tensor(A_      ,							dtype=torch.intaa					) for k, v in batch.items()}

       return batch


