






"""simple docstring"""



import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
 from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor




class 			lowerCAmelCase__			:
   def __init__(		self      :	List[str]							,			snake_case__      :	Optional[int]							,			snake_case__      :	int=1_3							,			snake_case__      :	Tuple=3_2							,			snake_case__      :	Any=3							,			snake_case__      :	int=4							,			snake_case__      :	List[Any]=[1_0, 2_0, 3_0, 4_0]							,			snake_case__      :	Optional[int]=[2, 2, 3, 2]							,			snake_case__      :	Tuple=True							,			snake_case__      :	int=True							,			snake_case__      :	List[str]=3_7							,			snake_case__      :	List[Any]="gelu"							,			snake_case__      :	Tuple=1_0							,			snake_case__      :	List[str]=0.02							,			snake_case__      :	Dict=["stage2", "stage3", "stage4"]							,			snake_case__      :	str=[2, 3, 4]							,			snake_case__      :	Dict=None							,			):


        '''simple docstring'''
        UpperCAmelCase__						:    int							=							parent
        UpperCAmelCase__						:    Any							=							batch_size
        UpperCAmelCase__						:    Optional[int]							=							image_size
        UpperCAmelCase__						:    Optional[int]							=							num_channels
        UpperCAmelCase__						:    List[Any]							=							num_stages
        UpperCAmelCase__						:    Optional[int]							=							hidden_sizes
        UpperCAmelCase__						:    int							=							depths
        UpperCAmelCase__						:    str							=							is_training
        UpperCAmelCase__						:    Union[str, Any]							=							use_labels
        UpperCAmelCase__						:    Optional[Any]							=							intermediate_size
        UpperCAmelCase__						:    Any							=							hidden_act
        UpperCAmelCase__						:    List[str]							=							num_labels
        UpperCAmelCase__						:    Any							=							initializer_range
        UpperCAmelCase__						:    Tuple							=							out_features
        UpperCAmelCase__						:    Optional[Any]							=							out_indices
        UpperCAmelCase__						:    Union[str, Any]							=							scope
   def       __a							(		self      :	int							):


        '''simple docstring'''
        UpperCAmelCase__						:    str							=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

        UpperCAmelCase__						:    str							=							None
        if self.use_labels:
             UpperCAmelCase__						:    List[Any]							=							ids_tensor([self.batch_size]							,			self.num_labels							)

        UpperCAmelCase__						:    Tuple							=							self.get_config()

        return config, pixel_values, labels
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        return ConvNextVaConfig(
            num_channels=self.num_channels							,			hidden_sizes=self.hidden_sizes							,			depths=self.depths							,			num_stages=self.num_stages							,			hidden_act=self.hidden_act							,			is_decoder=snake_case__							,			initializer_range=self.initializer_range							,			out_features=self.out_features							,			out_indices=self.out_indices							,			num_labels=self.num_labels							,			)
   def       __a							(		self      :	int							,			snake_case__      :	Union[str, Any]							,			snake_case__      :	str							,			snake_case__      :	Optional[int]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							ConvNextVaModel(config=snake_case__							)
        model.to(snake_case__							)
        model.eval()
        UpperCAmelCase__						:    int							=							model(snake_case__							)
        # expected last hidden states: B, C, H // 32, W // 32
        self.parent.assertEqual(
            result.last_hidden_state.shape							,			(self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)							,			)
   def       __a							(		self      :	Dict							,			snake_case__      :	List[str]							,			snake_case__      :	List[str]							,			snake_case__      :	int							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[Any]							=							ConvNextVaForImageClassification(snake_case__							)
        model.to(snake_case__							)
        model.eval()
        UpperCAmelCase__						:    Dict							=							model(snake_case__							,			labels=snake_case__							)
        self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_labels)							)
   def       __a							(		self      :	Union[str, Any]							,			snake_case__      :	Tuple							,			snake_case__      :	str							,			snake_case__      :	List[Any]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							ConvNextVaBackbone(config=snake_case__							)
        model.to(snake_case__							)
        model.eval()
        UpperCAmelCase__						:    Optional[Any]							=							model(snake_case__							)

        # verify hidden states
        self.parent.assertEqual(len(result.feature_maps							)							,			len(config.out_features							)							)
        self.parent.assertListEqual(list(result.feature_maps[0].shape							)							,			[self.batch_size, self.hidden_sizes[1], 4, 4]							)

        # verify channels
        self.parent.assertEqual(len(model.channels							)							,			len(config.out_features							)							)
        self.parent.assertListEqual(model.channels							,			config.hidden_sizes[1:]							)

        # verify backbone works with out_features=None
        UpperCAmelCase__						:    List[Any]							=							None
        UpperCAmelCase__						:    List[Any]							=							ConvNextVaBackbone(config=snake_case__							)
        model.to(snake_case__							)
        model.eval()
        UpperCAmelCase__						:    Optional[Any]							=							model(snake_case__							)

        # verify feature maps
        self.parent.assertEqual(len(result.feature_maps							)							,			1							)
        self.parent.assertListEqual(list(result.feature_maps[0].shape							)							,			[self.batch_size, self.hidden_sizes[-1], 1, 1]							)

        # verify channels
        self.parent.assertEqual(len(model.channels							)							,			1							)
        self.parent.assertListEqual(model.channels							,			[config.hidden_sizes[-1]]							)
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[str]							=							self.prepare_config_and_inputs()
        UpperCAmelCase__							,				UpperCAmelCase__							,				UpperCAmelCase__						:    Tuple							=							config_and_inputs
        UpperCAmelCase__						:    Optional[int]							=							{"pixel_values": pixel_values}
        return config, inputs_dict




   def       __a							(		self      :	Any							):


        '''simple docstring'''
        UpperCAmelCase__						:    Dict							=							self.prepare_config_and_inputs()
        UpperCAmelCase__							,				UpperCAmelCase__							,				UpperCAmelCase__						:    int							=							config_and_inputs
        UpperCAmelCase__						:    Union[str, Any]							=							{"pixel_values": pixel_values, "labels": labels}
        return config, inputs_dict




@require_torch
class 			lowerCAmelCase__			(    __magic_name__							,						__magic_name__							,						unittest.TestCase   ):
   SCREAMING_SNAKE_CASE_    =(
       (
           ConvNextVaModel,
           ConvNextVaForImageClassification,
           ConvNextVaBackbone,
       )
       if is_torch_available()
       else ()
   )
   SCREAMING_SNAKE_CASE_    =(
       {'''feature-extraction''': ConvNextVaModel, '''image-classification''': ConvNextVaForImageClassification}
       if is_torch_available()
       else {}
   )

   SCREAMING_SNAKE_CASE_    =False
   SCREAMING_SNAKE_CASE_    =False
   SCREAMING_SNAKE_CASE_    =False
   SCREAMING_SNAKE_CASE_    =False
   SCREAMING_SNAKE_CASE_    =False
   def       __a							(		self      :	Tuple							):


        '''simple docstring'''
        UpperCAmelCase__						:    Union[str, Any]							=							ConvNextVaModelTester(self							)
        UpperCAmelCase__						:    List[str]							=							ConfigTester(self							,			config_class=snake_case__							,			has_text_modality=snake_case__							,			hidden_size=3_7							)
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        self.create_and_test_config_common_properties()
        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()
   def       __a							(		self      :	Optional[Any]							):


        '''simple docstring'''
        return
   @unittest.skip(reason="ConvNextV2 does not use inputs_embeds"							)
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        pass
   @unittest.skip(reason="ConvNextV2 does not support input and output embeddings"							)
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        pass
   @unittest.skip(reason="ConvNextV2 does not use feedforward chunking"							)
   def       __a							(		self      :	int							):


        '''simple docstring'''
        pass
   def       __a							(		self      :	Optional[Any]							):


        '''simple docstring'''
        if not self.model_tester.is_training:
             return

        for model_class in self.all_model_classes:
             UpperCAmelCase__							,				UpperCAmelCase__						:    List[Any]							=							self.model_tester.prepare_config_and_inputs_with_labels()
             UpperCAmelCase__						:    Tuple							=							True

             if model_class.__name__ in [
                 *get_values(snake_case__							),
                 *get_values(snake_case__							),
             ]:
                  continue

             UpperCAmelCase__						:    Optional[int]							=							model_class(snake_case__							)
             model.to(snake_case__							)
             model.train()
             UpperCAmelCase__						:    Dict							=							self._prepare_for_class(snake_case__							,			snake_case__							,			return_labels=snake_case__							)
             UpperCAmelCase__						:    Union[str, Any]							=							model(**snake_case__							).loss
             loss.backward()
   def       __a							(		self      :	int							):


        '''simple docstring'''
        if not self.model_tester.is_training:
             return

        for model_class in self.all_model_classes:
             UpperCAmelCase__							,				UpperCAmelCase__						:    Optional[int]							=							self.model_tester.prepare_config_and_inputs_with_labels()
             UpperCAmelCase__						:    List[str]							=							False
             UpperCAmelCase__						:    Any							=							True

             if (
                 model_class.__name__
                 in [*get_values(snake_case__							), *get_values(snake_case__							)]
                 or not model_class.supports_gradient_checkpointing
             ):
                  continue

             UpperCAmelCase__						:    List[Any]							=							model_class(snake_case__							)
             model.to(snake_case__							)
             model.gradient_checkpointing_enable()
             model.train()
             UpperCAmelCase__						:    Optional[Any]							=							self._prepare_for_class(snake_case__							,			snake_case__							,			return_labels=snake_case__							)
             UpperCAmelCase__						:    Tuple							=							model(**snake_case__							).loss
             loss.backward()
   def       __a							(		self      :	int							):


        '''simple docstring'''
        UpperCAmelCase__							,				UpperCAmelCase__						:    Union[str, Any]							=							self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             UpperCAmelCase__						:    Tuple							=							model_class(snake_case__							)
             UpperCAmelCase__						:    str							=							inspect.signature(model.forward							)
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCAmelCase__						:    int							=							[*signature.parameters.keys()]

             UpperCAmelCase__						:    str							=							["pixel_values"]
             self.assertListEqual(arg_names[:1]							,			snake_case__							)
   def       __a							(		self      :	int							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*snake_case__							)
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        def check_hidden_states_output(snake_case__      :	Tuple							,			snake_case__      :	Any							,			snake_case__      :	Union[str, Any]							):
             UpperCAmelCase__						:    Optional[int]							=							model_class(snake_case__							)
             model.to(snake_case__							)
             model.eval()

             with torch.no_grad():
                  UpperCAmelCase__						:    Union[str, Any]							=							model(**self._prepare_for_class(snake_case__							,			snake_case__							)							)

             UpperCAmelCase__						:    int							=							outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

             UpperCAmelCase__						:    Any							=							self.model_tester.num_stages
             self.assertEqual(len(snake_case__							)							,			expected_num_stages + 1							)

             # ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]							)							,			[self.model_tester.image_size // 4, self.model_tester.image_size // 4]							,			)

        UpperCAmelCase__							,				UpperCAmelCase__						:    List[Any]							=							self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             UpperCAmelCase__						:    Optional[int]							=							True
             check_hidden_states_output(snake_case__							,			snake_case__							,			snake_case__							)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCAmelCase__						:    Dict							=							True

             check_hidden_states_output(snake_case__							,			snake_case__							,			snake_case__							)
   def       __a							(		self      :	Dict							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[str]							=							self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*snake_case__							)




   @slow
   def       __a							(		self      :	Optional[int]							):


        '''simple docstring'''
        for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCAmelCase__						:    Optional[Any]							=							ConvNextVaModel.from_pretrained(snake_case__							)
             self.assertIsNotNone(snake_case__							)




def 	SCREAMING_SNAKE_CASE__       (  )->		Optional[Any]:






     '''simple docstring'''



     UpperCAmelCase__						:    List[Any]							=							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
     return image




@require_torch
@require_vision
class 			lowerCAmelCase__			(    unittest.TestCase   ):
   @cached_property
   def       __a							(		self      :	Union[str, Any]							):


        '''simple docstring'''
        return AutoImageProcessor.from_pretrained("facebook/convnextv2-tiny-1k-224"							) if is_vision_available() else None




   @slow
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        UpperCAmelCase__						:    List[Any]							=							ConvNextVaForImageClassification.from_pretrained("facebook/convnextv2-tiny-1k-224"							).to(snake_case__							)

        UpperCAmelCase__						:    Tuple							=							self.default_image_processor
        UpperCAmelCase__						:    Any							=							prepare_img()
        UpperCAmelCase__						:    List[Any]							=							preprocessor(images=snake_case__							,			return_tensors="pt"							).to(snake_case__							)

        # forward pass
        with torch.no_grad():
             UpperCAmelCase__						:    Union[str, Any]							=							model(**snake_case__							)

        # verify the logits
        UpperCAmelCase__						:    Optional[int]							=							torch.Size((1, 1_0_0_0)							)
        self.assertEqual(outputs.logits.shape							,			snake_case__							)

        UpperCAmelCase__						:    List[str]							=							torch.tensor([0.9996, 0.1966, -0.4386]							).to(snake_case__							)
        self.assertTrue(torch.allclose(outputs.logits[0, :3]							,			snake_case__							,			atol=1e-4							)							)










"""simple docstring"""



import json
from typing import Dict, List, Optional, Tuple, Union

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding, EncodedInput
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_led import LEDTokenizer


_lowerCAmelCase	:	str				=      logging.get_logger(__name__)


_lowerCAmelCase	:	int				=      {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

_lowerCAmelCase	:	List[Any]				=      {
    """vocab_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """allenai/led-base-16384""": """https://huggingface.co/allenai/led-base-16384/resolve/main/tokenizer.json""",
    },
}

_lowerCAmelCase	:	List[str]				=      {
    """allenai/led-base-16384""": 16_384,
}




class 			lowerCAmelCase__			(    __magic_name__   ):
   SCREAMING_SNAKE_CASE_    =VOCAB_FILES_NAMES
   SCREAMING_SNAKE_CASE_    =PRETRAINED_VOCAB_FILES_MAP
   SCREAMING_SNAKE_CASE_    =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   SCREAMING_SNAKE_CASE_    =LEDTokenizer
   SCREAMING_SNAKE_CASE_    =['''input_ids''', '''attention_mask''']
   def __init__(		self      :	Optional[Any]							,			snake_case__      :	str=None							,			snake_case__      :	List[Any]=None							,			snake_case__      :	Dict=None							,			snake_case__      :	List[str]="replace"							,			snake_case__      :	Optional[int]="<s>"							,			snake_case__      :	List[str]="</s>"							,			snake_case__      :	Union[str, Any]="</s>"							,			snake_case__      :	Dict="<s>"							,			snake_case__      :	Tuple="<unk>"							,			snake_case__      :	Any="<pad>"							,			snake_case__      :	Dict="<mask>"							,			snake_case__      :	int=False							,			snake_case__      :	Optional[int]=True							,			**snake_case__      :	List[Any]							,			):


        '''simple docstring'''
        super().__init__(
            snake_case__							,			snake_case__							,			tokenizer_file=snake_case__							,			errors=snake_case__							,			bos_token=snake_case__							,			eos_token=snake_case__							,			sep_token=snake_case__							,			cls_token=snake_case__							,			unk_token=snake_case__							,			pad_token=snake_case__							,			mask_token=snake_case__							,			add_prefix_space=snake_case__							,			trim_offsets=snake_case__							,			**snake_case__							,			)

        UpperCAmelCase__						:    str							=							json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()							)
        if pre_tok_state.get("add_prefix_space"							,			snake_case__							) != add_prefix_space:
             UpperCAmelCase__						:    Dict							=							getattr(snake_case__							,			pre_tok_state.pop("type"							)							)
             UpperCAmelCase__						:    str							=							add_prefix_space
             UpperCAmelCase__						:    Any							=							pre_tok_class(**snake_case__							)

        UpperCAmelCase__						:    Dict							=							add_prefix_space

        # the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
        UpperCAmelCase__						:    List[str]							=							"post_processor"
        UpperCAmelCase__						:    List[Any]							=							getattr(self.backend_tokenizer							,			snake_case__							,			snake_case__							)
        if tokenizer_component_instance:
             UpperCAmelCase__						:    int							=							json.loads(tokenizer_component_instance.__getstate__()							)

             # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
             if "sep" in state:
                  UpperCAmelCase__						:    Optional[Any]							=							tuple(state["sep"]							)
             if "cls" in state:
                  UpperCAmelCase__						:    Any							=							tuple(state["cls"]							)

             UpperCAmelCase__						:    Any							=							False

             if state.get("add_prefix_space"							,			snake_case__							) != add_prefix_space:
                  UpperCAmelCase__						:    Union[str, Any]							=							add_prefix_space
                  UpperCAmelCase__						:    List[Any]							=							True

             if state.get("trim_offsets"							,			snake_case__							) != trim_offsets:
                  UpperCAmelCase__						:    Optional[int]							=							trim_offsets
                  UpperCAmelCase__						:    List[Any]							=							True

             if changes_to_apply:
                  UpperCAmelCase__						:    List[str]							=							getattr(snake_case__							,			state.pop("type"							)							)
                  UpperCAmelCase__						:    Optional[int]							=							component_class(**snake_case__							)
                  setattr(self.backend_tokenizer							,			snake_case__							,			snake_case__							)
   @property
   # Copied from transformers.models.bart.tokenization_bart_fast.BartTokenizerFast.mask_token with BART->LED
   def       __a							(		self      :	Any							):


        '''simple docstring'''
        if self._mask_token is None:
             if self.verbose:
                  logger.error("Using mask_token, but it is not set yet."							)
             return None
        return str(self._mask_token							)
   @mask_token.setter
   def       __a							(		self      :	Any							,			snake_case__      :	Dict							):


        '''simple docstring'''
        UpperCAmelCase__						:    str							=							AddedToken(snake_case__							,			lstrip=snake_case__							,			rstrip=snake_case__							) if isinstance(snake_case__							,			snake_case__							) else value
        UpperCAmelCase__						:    Dict							=							value
   def       __a							(		self      :	str							,			*snake_case__      :	Any							,			**snake_case__      :	Optional[int]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Any							=							kwargs.get("is_split_into_words"							,			snake_case__							)

        if is_split_into_words and not self.add_prefix_space:
             raise ValueError(
                 f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                 "to use it with pretokenized inputs."							)

        return super()._batch_encode_plus(*snake_case__							,			**snake_case__							)
   def       __a							(		self      :	List[str]							,			*snake_case__      :	Union[str, Any]							,			**snake_case__      :	List[Any]							):


        '''simple docstring'''
        UpperCAmelCase__						:    Optional[Any]							=							kwargs.get("is_split_into_words"							,			snake_case__							)

        if is_split_into_words and not self.add_prefix_space:
             raise ValueError(
                 f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                 "to use it with pretokenized inputs."							)

        return super()._encode_plus(*snake_case__							,			**snake_case__							)
   def       __a							(		self      :	Tuple							,			snake_case__      :	str							,			snake_case__      :	Optional[str] = None							):


        '''simple docstring'''
        UpperCAmelCase__						:    Union[str, Any]							=							self._tokenizer.model.save(snake_case__							,			name=snake_case__							)
        return tuple(snake_case__							)
   def       __a							(		self      :	str							,			snake_case__      :	List[Any]							,			snake_case__      :	str=None							):


        '''simple docstring'''
        UpperCAmelCase__						:    Optional[Any]							=							[self.bos_token_id] + token_ids_a + [self.eos_token_id]
        if token_ids_a is None:
             return output

        return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]
   def       __a							(		self      :	str							,			snake_case__      :	List[int]							,			snake_case__      :	Optional[List[int]] = None							):


        '''simple docstring'''
        UpperCAmelCase__						:    Optional[int]							=							[self.sep_token_id]
        UpperCAmelCase__						:    Optional[Any]							=							[self.cls_token_id]

        if token_ids_a is None:
             return len(cls + token_ids_a + sep							) * [0]
        return len(cls + token_ids_a + sep + sep + token_ids_a + sep							) * [0]




   def       __a							(		self      :	Any							,			snake_case__      :	Union[Dict[str, EncodedInput], BatchEncoding]							,			snake_case__      :	Optional[int] = None							,			snake_case__      :	PaddingStrategy = PaddingStrategy.DO_NOT_PAD							,			snake_case__      :	Optional[int] = None							,			snake_case__      :	Optional[bool] = None							,			):


        '''simple docstring'''
        UpperCAmelCase__						:    str							=							super()._pad(
            encoded_inputs=snake_case__							,			max_length=snake_case__							,			padding_strategy=snake_case__							,			pad_to_multiple_of=snake_case__							,			return_attention_mask=snake_case__							,			)

        # Load from model defaults
        if return_attention_mask is None:
             UpperCAmelCase__						:    Optional[int]							=							"attention_mask" in self.model_input_names

        if return_attention_mask and "global_attention_mask" in encoded_inputs:
             UpperCAmelCase__						:    List[Any]							=							encoded_inputs[self.model_input_names[0]]
             # `global_attention_mask` need to have the same length as other (sequential) inputs.
             UpperCAmelCase__						:    Any							=							len(encoded_inputs["global_attention_mask"]							) != len(snake_case__							)

             if needs_to_be_padded:
                  UpperCAmelCase__						:    List[str]							=							len(snake_case__							) - len(encoded_inputs["global_attention_mask"]							)

                  if self.padding_side == "right":
                       # Use `-1` since `0` in `global_attention_mask` means `local attention` instead of `not to attend`
                       UpperCAmelCase__						:    Dict							=							(
                           encoded_inputs["global_attention_mask"] + [-1] * difference
                       )
                  elif self.padding_side == "left":
                       UpperCAmelCase__						:    Dict							=							[-1] * difference + encoded_inputs[
                           "global_attention_mask"
                       ]
                  else:
                       raise ValueError("Invalid padding strategy:" + str(self.padding_side							)							)

        return encoded_inputs


