

import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      BioGptForCausalLM,
      BioGptForSequenceClassification,
      BioGptForTokenClassification,
      BioGptModel,
      BioGptTokenizer,
  )
  from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST





class 					__lowerCAmelCase	:




  def __init__(							self				,  lowerCAmelCase				,  lowerCAmelCase=13				,  lowerCAmelCase=7				,  lowerCAmelCase=True				,  lowerCAmelCase=True				,  lowerCAmelCase=False				,  lowerCAmelCase=True				,  lowerCAmelCase=99				,  lowerCAmelCase=32				,  lowerCAmelCase=5				,  lowerCAmelCase=4				,  lowerCAmelCase=37				,  lowerCAmelCase="gelu"				,  lowerCAmelCase=0.1				,  lowerCAmelCase=0.1				,  lowerCAmelCase=512				,  lowerCAmelCase=16				,  lowerCAmelCase=2				,  lowerCAmelCase=0.02				,  lowerCAmelCase=3				,  lowerCAmelCase=4				,  lowerCAmelCase=None				,  )    ->					str:
        '''simple docstring'''






        _lowercase      			=parent
        _lowercase      			=batch_size
        _lowercase      			=seq_length
        _lowercase      			=is_training
        _lowercase      			=use_input_mask
        _lowercase      			=use_token_type_ids
        _lowercase      			=use_labels
        _lowercase      			=vocab_size
        _lowercase      			=hidden_size
        _lowercase      			=num_hidden_layers
        _lowercase      			=num_attention_heads
        _lowercase      			=intermediate_size
        _lowercase      			=hidden_act
        _lowercase      			=hidden_dropout_prob
        _lowercase      			=attention_probs_dropout_prob
        _lowercase      			=max_position_embeddings
        _lowercase      			=type_vocab_size
        _lowercase      			=type_sequence_label_size
        _lowercase      			=initializer_range
        _lowercase      			=num_labels
        _lowercase      			=num_choices
        _lowercase      			=scope




  def     A__	(							self   )    ->					List[str]:
        '''simple docstring'''






        _lowercase      			=ids_tensor([self.batch_size, self.seq_length]				,  self.vocab_size   )

        _lowercase      			=None
        if self.use_input_mask:
              _lowercase      			=random_attention_mask([self.batch_size, self.seq_length]   )

        _lowercase      			=None
        if self.use_token_type_ids:
              _lowercase      			=ids_tensor([self.batch_size, self.seq_length]				,  self.type_vocab_size   )

        _lowercase      			=None
        _lowercase      			=None
        _lowercase      			=None
        if self.use_labels:
              _lowercase      			=ids_tensor([self.batch_size]				,  self.type_sequence_label_size   )
              _lowercase      			=ids_tensor([self.batch_size, self.seq_length]				,  self.num_labels   )
              _lowercase      			=ids_tensor([self.batch_size]				,  self.num_choices   )

        _lowercase      			=self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels




  def     A__	(							self   )    ->					Any:
        '''simple docstring'''






        return BioGptConfig(
            vocab_size=self.vocab_size				,  hidden_size=self.hidden_size				,  num_hidden_layers=self.num_hidden_layers				,  num_attention_heads=self.num_attention_heads				,  intermediate_size=self.intermediate_size				,  hidden_act=self.hidden_act				,  hidden_dropout_prob=self.hidden_dropout_prob				,  attention_probs_dropout_prob=self.attention_probs_dropout_prob				,  max_position_embeddings=self.max_position_embeddings				,  type_vocab_size=self.type_vocab_size				,  is_decoder=lowerCAmelCase				,  initializer_range=self.initializer_range				,  )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=BioGptModel(config=lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase   )
        _lowercase      			=model(lowerCAmelCase   )
        self.parent.assertEqual(result.last_hidden_state.shape				,  (self.batch_size, self.seq_length, self.hidden_size)   )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=BioGptForCausalLM(config=lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  token_type_ids=lowerCAmelCase				,  labels=lowerCAmelCase   )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)   )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  *lowerCAmelCase   )    ->					Tuple:
        '''simple docstring'''






        _lowercase      			=BioGptModel(config=lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()

        # create attention mask
        _lowercase      			=torch.ones(input_ids.shape				,  dtype=torch.long				,  device=lowerCAmelCase   )
        _lowercase      			=self.seq_length // 2
        _lowercase      			=0

        # first forward pass
        _lowercase			,			_lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase   ).to_tuple()

        # create hypothetical next token and extent to next_input_ids
        _lowercase      			=ids_tensor((self.batch_size, 1)				,  config.vocab_size   )

        # change a random masked slice from input_ids
        _lowercase      			=ids_tensor((1,)				,  lowerCAmelCase   ).item() + 1
        _lowercase      			=ids_tensor((self.batch_size, 1)				,  config.vocab_size   ).squeeze(-1   )
        _lowercase      			=random_other_next_tokens

        # append to next input_ids and attn_mask
        _lowercase      			=torch.cat([input_ids, next_tokens]				,  dim=-1   )
        _lowercase      			=torch.cat(
            [attn_mask, torch.ones((attn_mask.shape[0], 1)				,  dtype=torch.long				,  device=lowerCAmelCase   )]				,  dim=1				,  )

        # get two different outputs
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase   )['last_hidden_state']
        _lowercase      			=model(lowerCAmelCase				,  past_key_values=lowerCAmelCase				,  attention_mask=lowerCAmelCase   )['last_hidden_state']

        # select random slice
        _lowercase      			=ids_tensor((1,)				,  output_from_past.shape[-1]   ).item()
        _lowercase      			=output_from_no_past[:, -1, random_slice_idx].detach()
        _lowercase      			=output_from_past[:, 0, random_slice_idx].detach()

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(lowerCAmelCase				,  lowerCAmelCase				,  atol=1e-3   )   )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  *lowerCAmelCase   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=BioGptModel(config=lowerCAmelCase   ).to(lowerCAmelCase   ).eval()

        _lowercase      			=torch.ones(input_ids.shape				,  dtype=torch.long				,  device=lowerCAmelCase   )

        # first forward pass
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  use_cache=lowerCAmelCase   )

        _lowercase			,			_lowercase      			=outputs.to_tuple()

        # create hypothetical multiple next token and extent to next_input_ids
        _lowercase      			=ids_tensor((self.batch_size, 3)				,  config.vocab_size   )
        _lowercase      			=ids_tensor((self.batch_size, 3)				,  2   )

        # append to next input_ids and
        _lowercase      			=torch.cat([input_ids, next_tokens]				,  dim=-1   )
        _lowercase      			=torch.cat([attention_mask, next_attn_mask]				,  dim=-1   )

        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase   )['last_hidden_state']
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  past_key_values=lowerCAmelCase   )[
            'last_hidden_state'
        ]

        # select random slice
        _lowercase      			=ids_tensor((1,)				,  output_from_past.shape[-1]   ).item()
        _lowercase      			=output_from_no_past[:, -3:, random_slice_idx].detach()
        _lowercase      			=output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]   )

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(lowerCAmelCase				,  lowerCAmelCase				,  atol=1e-3   )   )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  *lowerCAmelCase				,  lowerCAmelCase=False   )    ->					int:
        '''simple docstring'''






        _lowercase      			=BioGptForCausalLM(lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        if gradient_checkpointing:
              model.gradient_checkpointing_enable()

        _lowercase      			=model(lowerCAmelCase				,  labels=lowerCAmelCase   )
        self.parent.assertEqual(result.loss.shape				,  ()   )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.vocab_size)   )
        result.loss.backward()




  def     A__	(							self				,  lowerCAmelCase				,  *lowerCAmelCase   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=BioGptModel(lowerCAmelCase   )
        _lowercase      			=model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers   )
        for key in model.state_dict().keys():
              if "c_proj" in key and "weight" in key:
                    self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]   ) - model_std   )				,  0.001   )
                    self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]   ) - 0.0   )				,  0.01   )




  def     A__	(							self				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  lowerCAmelCase				,  *lowerCAmelCase   )    ->					int:
        '''simple docstring'''






        _lowercase      			=self.num_labels
        _lowercase      			=BioGptForTokenClassification(lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  token_type_ids=lowerCAmelCase   )
        self.parent.assertEqual(result.logits.shape				,  (self.batch_size, self.seq_length, self.num_labels)   )




  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase      			=self.prepare_config_and_inputs()
        (
            (
            _lowercase
        )			,			(
            _lowercase
        )			,			(
            _lowercase
        )			,			(
            _lowercase
        )			,			(
            _lowercase
        )			,			(
            _lowercase
        )			,			(
            _lowercase
        )			,			
        )      			=config_and_inputs
        _lowercase      			={'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict





@require_torch
class 					__lowerCAmelCase	(   SCREAMING_SNAKE_CASE     ,     SCREAMING_SNAKE_CASE     ,     SCREAMING_SNAKE_CASE     ,     unittest.TestCase				):
  _a		     =    (
      (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
      if is_torch_available()
      else ()
  )
  _a		     =    (BioGptForCausalLM,) if is_torch_available() else ()
  _a		     =    (
      {
          """feature-extraction""": BioGptModel,
          """text-classification""": BioGptForSequenceClassification,
          """text-generation""": BioGptForCausalLM,
          """token-classification""": BioGptForTokenClassification,
          """zero-shot""": BioGptForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  _a		     =    False




  def     A__	(							self   )    ->					str:
        '''simple docstring'''






        _lowercase      			=BioGptModelTester(self   )
        _lowercase      			=ConfigTester(self				,  config_class=lowerCAmelCase				,  hidden_size=37   )




  def     A__	(							self   )    ->					int:
        '''simple docstring'''






        self.config_tester.run_common_tests()




  def     A__	(							self   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase   )




  def     A__	(							self   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
              _lowercase      			=type
              self.model_tester.create_and_check_model(*lowerCAmelCase   )




  def     A__	(							self   )    ->					List[str]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_biogpt_model_attention_mask_past(*lowerCAmelCase   )




  def     A__	(							self   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_forward_and_backwards(*lowerCAmelCase				,  gradient_checkpointing=lowerCAmelCase   )




  def     A__	(							self   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_biogpt_model_past_large_inputs(*lowerCAmelCase   )




  def     A__	(							self   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_biogpt_weight_initialization(*lowerCAmelCase   )




  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase      			=self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_biogpt_for_token_classification(*lowerCAmelCase   )




  @slow
  def     A__	(							self   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=BioGptForCausalLM.from_pretrained('microsoft/biogpt'   )
        model.to(lowerCAmelCase   )
        _lowercase      			=BioGptTokenizer.from_pretrained('microsoft/biogpt'   )

        _lowercase      			='left'

        # Define PAD Token = EOS Token = 50256
        _lowercase      			=tokenizer.eos_token
        _lowercase      			=model.config.eos_token_id

        # use different length sentences to test batching
        _lowercase      			=[
            'Hello, my dog is a little',
            'Today, I',
        ]

        _lowercase      			=tokenizer(lowerCAmelCase				,  return_tensors='pt'				,  padding=lowerCAmelCase   )
        _lowercase      			=inputs['input_ids'].to(lowerCAmelCase   )

        _lowercase      			=model.generate(
            input_ids=lowerCAmelCase				,  attention_mask=inputs['attention_mask'].to(lowerCAmelCase   )				,  )

        _lowercase      			=tokenizer(sentences[0]				,  return_tensors='pt'   ).input_ids.to(lowerCAmelCase   )
        _lowercase      			=model.generate(input_ids=lowerCAmelCase   )

        _lowercase      			=inputs_non_padded.shape[-1] - inputs['attention_mask'][-1].long().sum().cpu().item()
        _lowercase      			=tokenizer(sentences[1]				,  return_tensors='pt'   ).input_ids.to(lowerCAmelCase   )
        _lowercase      			=model.generate(input_ids=lowerCAmelCase				,  max_length=model.config.max_length - num_paddings   )

        _lowercase      			=tokenizer.batch_decode(lowerCAmelCase				,  skip_special_tokens=lowerCAmelCase   )
        _lowercase      			=tokenizer.decode(output_non_padded[0]				,  skip_special_tokens=lowerCAmelCase   )
        _lowercase      			=tokenizer.decode(output_padded[0]				,  skip_special_tokens=lowerCAmelCase   )

        _lowercase      			=[
            'Hello, my dog is a little bit bigger than a little bit.',
            'Today, I have a good idea of how to use the information',
        ]
        self.assertListEqual(lowerCAmelCase				,  lowerCAmelCase   )
        self.assertListEqual(lowerCAmelCase				,  [non_padded_sentence, padded_sentence]   )




  @slow
  def     A__	(							self   )    ->					List[str]:
        '''simple docstring'''






        for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              _lowercase      			=BioGptModel.from_pretrained(lowerCAmelCase   )
              self.assertIsNotNone(lowerCAmelCase   )




  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase			,			_lowercase      			=self.model_tester.prepare_config_and_inputs_for_common()
        _lowercase      			=3
        _lowercase      			=input_dict['input_ids']
        _lowercase      			=input_ids.ne(1   ).to(lowerCAmelCase   )
        _lowercase      			=ids_tensor([self.model_tester.batch_size]				,  self.model_tester.type_sequence_label_size   )
        _lowercase      			=BioGptForSequenceClassification(lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  labels=lowerCAmelCase   )
        self.assertEqual(result.logits.shape				,  (self.model_tester.batch_size, self.model_tester.num_labels)   )




  def     A__	(							self   )    ->					int:
        '''simple docstring'''






        _lowercase			,			_lowercase      			=self.model_tester.prepare_config_and_inputs_for_common()
        _lowercase      			=3
        _lowercase      			='multi_label_classification'
        _lowercase      			=input_dict['input_ids']
        _lowercase      			=input_ids.ne(1   ).to(lowerCAmelCase   )
        _lowercase      			=ids_tensor(
            [self.model_tester.batch_size, config.num_labels]				,  self.model_tester.type_sequence_label_size   ).to(torch.float   )
        _lowercase      			=BioGptForSequenceClassification(lowerCAmelCase   )
        model.to(lowerCAmelCase   )
        model.eval()
        _lowercase      			=model(lowerCAmelCase				,  attention_mask=lowerCAmelCase				,  labels=lowerCAmelCase   )
        self.assertEqual(result.logits.shape				,  (self.model_tester.batch_size, self.model_tester.num_labels)   )





@require_torch
class 					__lowerCAmelCase	(   unittest.TestCase				):




  @slow
  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase      			=BioGptForCausalLM.from_pretrained('microsoft/biogpt'   )
        _lowercase      			=torch.tensor([[2, 4_805, 9, 656, 21]]   )
        _lowercase      			=model(lowerCAmelCase   )[0]

        _lowercase      			=42_384

        _lowercase      			=torch.Size((1, 5, vocab_size)   )
        self.assertEqual(output.shape				,  lowerCAmelCase   )

        _lowercase      			=torch.tensor(
            [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]]   )

        self.assertTrue(torch.allclose(output[:, :3, :3]				,  lowerCAmelCase				,  atol=1e-4   )   )




  @slow
  def     A__	(							self   )    ->					Optional[Any]:
        '''simple docstring'''






        _lowercase      			=BioGptTokenizer.from_pretrained('microsoft/biogpt'   )
        _lowercase      			=BioGptForCausalLM.from_pretrained('microsoft/biogpt'   )
        model.to(lowerCAmelCase   )

        torch.manual_seed(0   )
        _lowercase      			=tokenizer('COVID-19 is'				,  return_tensors='pt'   ).to(lowerCAmelCase   )
        _lowercase      			=model.generate(
            **lowerCAmelCase				,  min_length=100				,  max_length=1_024				,  num_beams=5				,  early_stopping=lowerCAmelCase				,  )
        _lowercase      			=tokenizer.decode(output_ids[0]				,  skip_special_tokens=lowerCAmelCase   )

        _lowercase      			=(
            'COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'
            ' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'
            ' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'
            ' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'
            ' more than 800,000 deaths.'
        )
        self.assertEqual(lowerCAmelCase				,  lowerCAmelCase   )





# Copyright 2021 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from packaging import version

from .. import __version__
from .constants import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, IMAGENET_STANDARD_MEAN, IMAGENET_STANDARD_STD
from .doc import (
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    copy_func,
    replace_return_docstrings,
)
from .generic import (
    ContextManagers,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    TensorType,
    add_model_info_to_auto_map,
    cached_property,
    can_return_loss,
    expand_dims,
    find_labels,
    flatten_dict,
    infer_framework,
    is_jax_tensor,
    is_numpy_array,
    is_tensor,
    is_tf_symbolic_tensor,
    is_tf_tensor,
    is_torch_device,
    is_torch_dtype,
    is_torch_tensor,
    reshape,
    squeeze,
    strtobool,
    tensor_size,
    to_numpy,
    to_py_obj,
    transpose,
    working_or_temp_dir,
)
from .hub import (
    CLOUDFRONT_DISTRIB_PREFIX,
    DISABLE_TELEMETRY,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    EntryNotFoundError,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    cached_file,
    default_cache_path,
    define_sagemaker_information,
    download_url,
    extract_commit_hash,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    has_file,
    http_user_agent,
    is_offline_mode,
    is_remote_url,
    move_cache,
    send_example_telemetry,
    try_to_load_from_cache,
)
from .import_utils import (
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    TORCH_FX_REQUIRED_VERSION,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    DummyObject,
    OptionalDependencyNotAvailable,
    _LazyModule,
    ccl_version,
    direct_transformers_import,
    get_torch_version,
    is_accelerate_available,
    is_apex_available,
    is_bitsandbytes_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_cython_available,
    is_datasets_available,
    is_decord_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_jieba_available,
    is_jumanpp_available,
    is_kenlm_available,
    is_keras_nlp_available,
    is_librosa_available,
    is_natten_available,
    is_ninja_available,
    is_onnx_available,
    is_openai_available,
    is_optimum_available,
    is_pandas_available,
    is_peft_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytest_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sacremoses_available,
    is_safetensors_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_sudachi_available,
    is_tensorflow_probability_available,
    is_tensorflow_text_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_bfaa_cpu_available,
    is_torch_bfaa_gpu_available,
    is_torch_compile_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_neuroncore_available,
    is_torch_tensorrt_fx_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_torchdistx_available,
    is_torchdynamo_available,
    is_torchvision_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    requires_backends,
    torch_only_method,
)


lowercase_   							=  'pytorch_model.bin'
lowercase_   							=  'pytorch_model.bin.index.json'
lowercase_   							=  'adapter_config.json'
lowercase_   							=  'adapter_model.bin'
lowercase_   							=  'adapter_model.safetensors'
lowercase_   							=  'tf_model.h5'
lowercase_   							=  'tf_model.h5.index.json'
lowercase_   							=  'model.ckpt'
lowercase_   							=  'flax_model.msgpack'
lowercase_   							=  'flax_model.msgpack.index.json'
lowercase_   							=  'model.safetensors'
lowercase_   							=  'model.safetensors.index.json'
lowercase_   							=  'config.json'
lowercase_   							=  'preprocessor_config.json'
lowercase_   							=  FEATURE_EXTRACTOR_NAME
lowercase_   							=  'generation_config.json'
lowercase_   							=  'modelcard.json'

lowercase_   							=  '▁'
lowercase_   							=  SENTENCEPIECE_UNDERLINE  # Kept for backward compatibility

lowercase_   							=  [
    [[0, 1, 0, 1], [1, 0, 0, 1]]
] * 2  # Needs to have 0s and 1s only since XLM uses it for langs too.
lowercase_   							=  [[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]]
lowercase_   							=  [[1, 1, 1, 1, 1], [1, 1, 1, 0, 0], [0, 0, 0, 1, 1]]
def 	a (     A__      :  List[str]	)       -> str:





      """simple docstring"""



      if version.parse(A__	) < version.parse(A__	):
            if "dev" in min_version:
                  _lowercase      			=(
                      'This example requires a source install from HuggingFace Transformers (see '
                      '`https://huggingface.co/docs/transformers/installation#install-from-source`),'
                  )
            else:
                  _lowercase      			=F'''This example requires a minimum version of {min_version},'''
            error_message += F''' but the version found is {__version__}.\n'''
            raise ImportError(
                error_message
                + 'Check out https://github.com/huggingface/transformers/tree/main/examples#important-note for the examples corresponding to other '
                'versions of HuggingFace Transformers.'	)


