


"""simple docstring"""






import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import DeformableDetrImageProcessor


class     __lowerCamelCase  (					unittest.TestCase				):

     '''simple docstring'''


     def __init__(      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=7    ,				__UpperCAmelCase=3    ,				__UpperCAmelCase=30    ,				__UpperCAmelCase=400    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=[0.5, 0.5, 0.5]    ,				__UpperCAmelCase=[0.5, 0.5, 0.5]    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=1 / 255    ,				__UpperCAmelCase=True    ,				)       ->							Optional[int]:
          # by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
          _a    	=				size if size is not None else {'''shortest_edge''': 18, '''longest_edge''': 1333}
          _a    	=				parent
          _a    	=				batch_size
          _a    	=				num_channels
          _a    	=				min_resolution
          _a    	=				max_resolution
          _a    	=				do_resize
          _a    	=				size
          _a    	=				do_normalize
          _a    	=				image_mean
          _a    	=				image_std
          _a    	=				do_rescale
          _a    	=				rescale_factor
          _a    	=				do_pad


     def 							_UpperCAmelCase      (      self							)       ->							Union[str, Any]:
          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_rescale": self.do_rescale,
              "rescale_factor": self.rescale_factor,
              "do_pad": self.do_pad,
          }





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=False							)       ->							List[str]:
          if not batched:
               _a    	=				image_inputs[0]
               if isinstance(__UpperCAmelCase    ,				Image.Image							):
                    _a	,      _a    	=				image.size
               else:
                    _a	,      _a    	=				image.shape[1], image.shape[2]
               if w < h:
                    _a    	=				int(self.size['''shortest_edge'''] * h / w							)
                    _a    	=				self.size['''shortest_edge''']
               elif w > h:
                    _a    	=				self.size['''shortest_edge''']
                    _a    	=				int(self.size['''shortest_edge'''] * w / h							)
               else:
                    _a    	=				self.size['''shortest_edge''']
                    _a    	=				self.size['''shortest_edge''']

          else:
               _a    	=				[]
               for image in image_inputs:
                    _a	,      _a    	=				self.get_expected_values([image]							)
                    expected_values.append((expected_height, expected_width)							)
               _a    	=				max(__UpperCAmelCase    ,				key=lambda __UpperCAmelCase							: item[0]							)[0]
               _a    	=				max(__UpperCAmelCase    ,				key=lambda __UpperCAmelCase							: item[1]							)[1]

          return expected_height, expected_width







@require_torch
@require_vision
class     __lowerCamelCase  (					a__  ,					unittest.TestCase				):

     '''simple docstring'''
     A_       :	List[str]    =		DeformableDetrImageProcessor if is_vision_available() else None


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				DeformableDetrImageProcessingTester(self							)


     @property
     def 							_UpperCAmelCase      (      self							)       ->							Union[str, Any]:
          return self.image_processor_tester.prepare_image_processor_dict()


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				self.image_processing_class(**self.image_processor_dict							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''image_mean'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''image_std'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''do_normalize'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''do_resize'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''do_rescale'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''do_pad'''							)							)
          self.assertTrue(hasattr(__UpperCAmelCase    ,				'''size'''							)							)


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          _a    	=				self.image_processing_class.from_dict(self.image_processor_dict							)
          self.assertEqual(image_processor.size    ,				{'''shortest_edge''': 18, '''longest_edge''': 1333}							)
          self.assertEqual(image_processor.do_pad    ,				__UpperCAmelCase							)

          _a    	=				self.image_processing_class.from_dict(
              self.image_processor_dict    ,				size=42    ,				max_size=84    ,				pad_and_return_pixel_mask=__UpperCAmelCase							)
          self.assertEqual(image_processor.size    ,				{'''shortest_edge''': 42, '''longest_edge''': 84}							)
          self.assertEqual(image_processor.do_pad    ,				__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self							)       ->							int:
          pass


     def 							_UpperCAmelCase      (      self							)       ->							List[Any]:
          # Initialize image_processing
          _a    	=				self.image_processing_class(**self.image_processor_dict							)
          # create random PIL images
          _a    	=				prepare_image_inputs(self.image_processor_tester    ,				equal_resolution=__UpperCAmelCase							)
          for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase    ,				Image.Image							)

          # Test not batched input
          _a    	=				image_processing(image_inputs[0]    ,				return_tensors='''pt'''							).pixel_values

          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase							)

          self.assertEqual(
              encoded_images.shape    ,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,				)

          # Test batched
          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase    ,				batched=__UpperCAmelCase							)

          _a    	=				image_processing(__UpperCAmelCase    ,				return_tensors='''pt'''							).pixel_values
          self.assertEqual(
              encoded_images.shape    ,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )    ,				)


     def 							_UpperCAmelCase      (      self							)       ->							int:
          # Initialize image_processing
          _a    	=				self.image_processing_class(**self.image_processor_dict							)
          # create random numpy tensors
          _a    	=				prepare_image_inputs(self.image_processor_tester    ,				equal_resolution=__UpperCAmelCase    ,				numpify=__UpperCAmelCase							)
          for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase    ,				np.ndarray							)

          # Test not batched input
          _a    	=				image_processing(image_inputs[0]    ,				return_tensors='''pt'''							).pixel_values

          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase							)

          self.assertEqual(
              encoded_images.shape    ,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,				)

          # Test batched
          _a    	=				image_processing(__UpperCAmelCase    ,				return_tensors='''pt'''							).pixel_values

          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase    ,				batched=__UpperCAmelCase							)

          self.assertEqual(
              encoded_images.shape    ,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )    ,				)


     def 							_UpperCAmelCase      (      self							)       ->							Dict:
          # Initialize image_processing
          _a    	=				self.image_processing_class(**self.image_processor_dict							)
          # create random PyTorch tensors
          _a    	=				prepare_image_inputs(self.image_processor_tester    ,				equal_resolution=__UpperCAmelCase    ,				torchify=__UpperCAmelCase							)
          for image in image_inputs:
               self.assertIsInstance(__UpperCAmelCase    ,				torch.Tensor							)

          # Test not batched input
          _a    	=				image_processing(image_inputs[0]    ,				return_tensors='''pt'''							).pixel_values

          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase							)

          self.assertEqual(
              encoded_images.shape    ,				(1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,				)

          # Test batched
          _a    	=				image_processing(__UpperCAmelCase    ,				return_tensors='''pt'''							).pixel_values

          _a	,      _a    	=				self.image_processor_tester.get_expected_values(__UpperCAmelCase    ,				batched=__UpperCAmelCase							)

          self.assertEqual(
              encoded_images.shape    ,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              )    ,				)


     @slow
     def 							_UpperCAmelCase      (      self							)       ->							Optional[Any]:
          # prepare image and target
          _a    	=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
          with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt'''    ,				'''r'''							) as f:
               _a    	=				json.loads(f.read()							)

          _a    	=				{'''image_id''': 39769, '''annotations''': target}

          # encode them
          _a    	=				DeformableDetrImageProcessor()
          _a    	=				image_processing(images=__UpperCAmelCase    ,				annotations=__UpperCAmelCase    ,				return_tensors='''pt'''							)

          # verify pixel values
          _a    	=				torch.Size([1, 3, 800, 1066]							)
          self.assertEqual(encoding['''pixel_values'''].shape    ,				__UpperCAmelCase							)

          _a    	=				torch.tensor([0.2796, 0.3138, 0.3481]							)
          self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]    ,				__UpperCAmelCase    ,				atol=1e-4							)							)

          # verify area
          _a    	=				torch.tensor([5887.9600, 11250.2061, 489353.8438, 837122.7500, 147967.5156, 165732.3438]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']    ,				__UpperCAmelCase							)							)
          # verify boxes
          _a    	=				torch.Size([6, 4]							)
          self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape    ,				__UpperCAmelCase							)
          _a    	=				torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]    ,				__UpperCAmelCase    ,				atol=1e-3							)							)
          # verify image_id
          _a    	=				torch.tensor([39769]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']    ,				__UpperCAmelCase							)							)
          # verify is_crowd
          _a    	=				torch.tensor([0, 0, 0, 0, 0, 0]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']    ,				__UpperCAmelCase							)							)
          # verify class_labels
          _a    	=				torch.tensor([75, 75, 63, 65, 17, 17]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']    ,				__UpperCAmelCase							)							)
          # verify orig_size
          _a    	=				torch.tensor([480, 640]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']    ,				__UpperCAmelCase							)							)
          # verify size
          _a    	=				torch.tensor([800, 1066]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']    ,				__UpperCAmelCase							)							)





     @slow
     def 							_UpperCAmelCase      (      self							)       ->							str:
          # prepare image, target and masks_path
          _a    	=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
          with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'''    ,				'''r'''							) as f:
               _a    	=				json.loads(f.read()							)

          _a    	=				{'''file_name''': '''000000039769.png''', '''image_id''': 39769, '''segments_info''': target}

          _a    	=				pathlib.Path('''./tests/fixtures/tests_samples/COCO/coco_panoptic'''							)

          # encode them
          _a    	=				DeformableDetrImageProcessor(format='''coco_panoptic'''							)
          _a    	=				image_processing(images=__UpperCAmelCase    ,				annotations=__UpperCAmelCase    ,				masks_path=__UpperCAmelCase    ,				return_tensors='''pt'''							)

          # verify pixel values
          _a    	=				torch.Size([1, 3, 800, 1066]							)
          self.assertEqual(encoding['''pixel_values'''].shape    ,				__UpperCAmelCase							)

          _a    	=				torch.tensor([0.2796, 0.3138, 0.3481]							)
          self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]    ,				__UpperCAmelCase    ,				atol=1e-4							)							)

          # verify area
          _a    	=				torch.tensor([147979.6875, 165527.0469, 484638.5938, 11292.9375, 5879.6562, 7634.1147]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']    ,				__UpperCAmelCase							)							)
          # verify boxes
          _a    	=				torch.Size([6, 4]							)
          self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape    ,				__UpperCAmelCase							)
          _a    	=				torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]    ,				__UpperCAmelCase    ,				atol=1e-3							)							)
          # verify image_id
          _a    	=				torch.tensor([39769]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']    ,				__UpperCAmelCase							)							)
          # verify is_crowd
          _a    	=				torch.tensor([0, 0, 0, 0, 0, 0]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']    ,				__UpperCAmelCase							)							)
          # verify class_labels
          _a    	=				torch.tensor([17, 17, 63, 75, 75, 93]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']    ,				__UpperCAmelCase							)							)
          # verify masks
          _a    	=				822873
          self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item()    ,				__UpperCAmelCase							)
          # verify orig_size
          _a    	=				torch.tensor([480, 640]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']    ,				__UpperCAmelCase							)							)
          # verify size
          _a    	=				torch.tensor([800, 1066]							)
          self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']    ,				__UpperCAmelCase							)							)




"""simple docstring"""






import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__snake_case		=       logging.get_logger(__name__)
__snake_case		=       {'''vocab_file''': '''spiece.model'''}

__snake_case		=       {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    }
}

__snake_case		=       {
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

__snake_case		=       '''▁'''


class     __lowerCamelCase  (					a__				):

     '''simple docstring'''
     A_       :	Optional[int]    =		VOCAB_FILES_NAMES
     A_       :	int    =		PRETRAINED_VOCAB_FILES_MAP
     A_       :	Optional[int]    =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES


     def __init__(      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=True    ,				__UpperCAmelCase=False    ,				__UpperCAmelCase="[CLS]"    ,				__UpperCAmelCase="[SEP]"    ,				__UpperCAmelCase="<unk>"    ,				__UpperCAmelCase="[SEP]"    ,				__UpperCAmelCase="<pad>"    ,				__UpperCAmelCase="[CLS]"    ,				__UpperCAmelCase="[MASK]"    ,				__UpperCAmelCase = None    ,				**__UpperCAmelCase    ,				)       ->							None:
          # Mask token behave like a normal word, i.e. include the space before it and
          # is included in the raw text, there should be a match in a non-normalized sentence.
          _a    	=				(
              AddedToken(__UpperCAmelCase    ,				lstrip=__UpperCAmelCase    ,				rstrip=__UpperCAmelCase    ,				normalized=__UpperCAmelCase							)
              if isinstance(__UpperCAmelCase    ,				__UpperCAmelCase							)
              else mask_token
          )

          _a    	=				{} if sp_model_kwargs is None else sp_model_kwargs

          super().__init__(
              do_lower_case=__UpperCAmelCase    ,				remove_space=__UpperCAmelCase    ,				keep_accents=__UpperCAmelCase    ,				bos_token=__UpperCAmelCase    ,				eos_token=__UpperCAmelCase    ,				unk_token=__UpperCAmelCase    ,				sep_token=__UpperCAmelCase    ,				pad_token=__UpperCAmelCase    ,				cls_token=__UpperCAmelCase    ,				mask_token=__UpperCAmelCase    ,				sp_model_kwargs=self.sp_model_kwargs    ,				**__UpperCAmelCase    ,				)

          _a    	=				do_lower_case
          _a    	=				remove_space
          _a    	=				keep_accents
          _a    	=				vocab_file

          _a    	=				spm.SentencePieceProcessor(**self.sp_model_kwargs							)
          self.sp_model.Load(__UpperCAmelCase							)


     @property
     def 							_UpperCAmelCase      (      self							)       ->							str:
          return len(self.sp_model							)


     def 							_UpperCAmelCase      (      self							)       ->							Optional[Any]:
          _a    	=				{self.convert_ids_to_tokens(__UpperCAmelCase							): i for i in range(self.vocab_size							)}
          vocab.update(self.added_tokens_encoder							)
          return vocab


     def __getstate__(      self							)       ->							int:
          _a    	=				self.__dict__.copy()
          _a    	=				None
          return state


     def __setstate__(      self    ,				__UpperCAmelCase							)       ->							Tuple:
          _a    	=				d

          # for backward compatibility
          if not hasattr(self    ,				'''sp_model_kwargs'''							):
               _a    	=				{}

          _a    	=				spm.SentencePieceProcessor(**self.sp_model_kwargs							)
          self.sp_model.Load(self.vocab_file							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							List[str]:
          if self.remove_space:
               _a    	=				''' '''.join(inputs.strip().split()							)
          else:
               _a    	=				inputs
          _a    	=				outputs.replace('''``'''    ,				'''"'''							).replace('''\'\''''    ,				'''"'''							)

          if not self.keep_accents:
               _a    	=				unicodedata.normalize('''NFKD'''    ,				__UpperCAmelCase							)
               _a    	=				''''''.join([c for c in outputs if not unicodedata.combining(__UpperCAmelCase							)]							)
          if self.do_lower_case:
               _a    	=				outputs.lower()

          return outputs


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							List[str]:
          _a    	=				self.preprocess_text(__UpperCAmelCase							)
          _a    	=				self.sp_model.encode(__UpperCAmelCase    ,				out_type=__UpperCAmelCase							)
          _a    	=				[]
          for piece in pieces:
               if len(__UpperCAmelCase							) > 1 and piece[-1] == str(''','''							) and piece[-2].isdigit():
                    _a    	=				self.sp_model.EncodeAsPieces(piece[:-1].replace(__UpperCAmelCase    ,				''''''							)							)
                    if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                         if len(cur_pieces[0]							) == 1:
                              _a    	=				cur_pieces[1:]
                         else:
                              _a    	=				cur_pieces[0][1:]
                    cur_pieces.append(piece[-1]							)
                    new_pieces.extend(__UpperCAmelCase							)
               else:
                    new_pieces.append(__UpperCAmelCase							)

          return new_pieces


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							str:
          return self.sp_model.PieceToId(__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							int:
          return self.sp_model.IdToPiece(__UpperCAmelCase							)


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase							)       ->							Optional[Any]:
          _a    	=				[]
          _a    	=				''''''
          _a    	=				False
          for token in tokens:
               # make sure that special tokens are not decoded using sentencepiece model
               if token in self.all_special_tokens:
                    if not prev_is_special:
                         out_string += " "
                    out_string += self.sp_model.decode(__UpperCAmelCase							) + token
                    _a    	=				True
                    _a    	=				[]
               else:
                    current_sub_tokens.append(__UpperCAmelCase							)
                    _a    	=				False
          out_string += self.sp_model.decode(__UpperCAmelCase							)
          return out_string.strip()


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None							)       ->							List[int]:
          _a    	=				[self.sep_token_id]
          _a    	=				[self.cls_token_id]
          if token_ids_a is None:
               return cls + token_ids_a + sep
          return cls + token_ids_a + sep + token_ids_a + sep


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None    ,				__UpperCAmelCase = False							)       ->							List[int]:

          if already_has_special_tokens:
               return super().get_special_tokens_mask(
                   token_ids_a=__UpperCAmelCase    ,				token_ids_a=__UpperCAmelCase    ,				already_has_special_tokens=__UpperCAmelCase							)

          if token_ids_a is not None:
               return [1] + ([0] * len(__UpperCAmelCase							)) + [1] + ([0] * len(__UpperCAmelCase							)) + [1]
          return [1] + ([0] * len(__UpperCAmelCase							)) + [1]


     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None							)       ->							List[int]:
          _a    	=				[self.sep_token_id]
          _a    	=				[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							) * [0] + len(token_ids_a + sep							) * [1]





     def 							_UpperCAmelCase      (      self    ,				__UpperCAmelCase    ,				__UpperCAmelCase = None							)       ->							Tuple[str]:
          if not os.path.isdir(__UpperCAmelCase							):
               logger.error(F'Vocabulary path ({save_directory}) should be a directory'							)
               return
          _a    	=				os.path.join(
              __UpperCAmelCase    ,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']							)

          if os.path.abspath(self.vocab_file							) != os.path.abspath(__UpperCAmelCase							) and os.path.isfile(self.vocab_file							):
               copyfile(self.vocab_file    ,				__UpperCAmelCase							)
          elif not os.path.isfile(self.vocab_file							):
               with open(__UpperCAmelCase    ,				'''wb'''							) as fi:
                    _a    	=				self.sp_model.serialized_model_proto()
                    fi.write(__UpperCAmelCase							)

          return (out_vocab_file,)