
'''simple docstring'''






import tempfile
import unittest

import numpy as np

from diffusers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionPipeline,
    PNDMScheduler,
)
from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
 import onnxruntime as ort

class 			UpperCAmelCase__    (							_UpperCamelCase    ,						unittest.TestCase			):
    lowerCAmelCase_					     =		"hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline"



    def 	lowerCamelCase_	(						self   :							str,__A   :							Optional[Any]=0  ):
          _lowerCamelCase					: Union[str, Any]		    = np.random.RandomState(a_  )
          _lowerCamelCase					: List[Any]		    = {
              "prompt": "A painting of a squirrel eating a burger",
              "generator": generator,
              "num_inference_steps": 2,
              "guidance_scale": 7.5,
              "output_type": "numpy",
          }
          return inputs



    def 	lowerCamelCase_	(						self   :							Dict  ):
          _lowerCamelCase					: Tuple		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Optional[int]		    = self.get_dummy_inputs()
          _lowerCamelCase					: Union[str, Any]		    = pipe(**a_  ).images
          _lowerCamelCase					: Tuple		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: List[str]		    = np.array([0.65072, 0.58492, 0.48219, 0.55521, 0.53180, 0.55939, 0.50697, 0.39800, 0.46455]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							Tuple  ):
          _lowerCamelCase					: Dict		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          _lowerCamelCase					: List[str]		    = PNDMScheduler.from_config(pipe.scheduler.config,skip_prk_steps=a_  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Optional[int]		    = self.get_dummy_inputs()
          _lowerCamelCase					: List[Any]		    = pipe(**a_  ).images
          _lowerCamelCase					: Union[str, Any]		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: List[str]		    = np.array([0.65863, 0.59425, 0.49326, 0.56313, 0.53875, 0.56627, 0.51065, 0.39777, 0.46330]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							Tuple  ):
          _lowerCamelCase					: Dict		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          _lowerCamelCase					: Tuple		    = LMSDiscreteScheduler.from_config(pipe.scheduler.config  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: List[Any]		    = self.get_dummy_inputs()
          _lowerCamelCase					: Optional[Any]		    = pipe(**a_  ).images
          _lowerCamelCase					: int		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: Dict		    = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							Optional[Any]  ):
          _lowerCamelCase					: Union[str, Any]		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          _lowerCamelCase					: Dict		    = EulerDiscreteScheduler.from_config(pipe.scheduler.config  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Optional[int]		    = self.get_dummy_inputs()
          _lowerCamelCase					: int		    = pipe(**a_  ).images
          _lowerCamelCase					: Tuple		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: str		    = np.array([0.53755, 0.60786, 0.47402, 0.49488, 0.51869, 0.49819, 0.47985, 0.38957, 0.44279]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							Union[str, Any]  ):
          _lowerCamelCase					: str		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          _lowerCamelCase					: Dict		    = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Any		    = self.get_dummy_inputs()
          _lowerCamelCase					: List[str]		    = pipe(**a_  ).images
          _lowerCamelCase					: Union[str, Any]		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: Any		    = np.array([0.53817, 0.60812, 0.47384, 0.49530, 0.51894, 0.49814, 0.47984, 0.38958, 0.44271]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							Tuple  ):
          _lowerCamelCase					: str		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          _lowerCamelCase					: str		    = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Tuple		    = self.get_dummy_inputs()
          _lowerCamelCase					: List[str]		    = pipe(**a_  ).images
          _lowerCamelCase					: Any		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 1_2_8, 1_2_8, 3)
          _lowerCamelCase					: Any		    = np.array([0.53895, 0.60808, 0.47933, 0.49608, 0.51886, 0.49950, 0.48053, 0.38957, 0.44200]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-2



    def 	lowerCamelCase_	(						self   :							str  ):
          _lowerCamelCase					: Dict		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Any		    = self.get_dummy_inputs()
          _lowerCamelCase					: Any		    = 3 * [inputs["prompt"]]

          # forward
          _lowerCamelCase					: Union[str, Any]		    = pipe(**a_  )
          _lowerCamelCase					: int		    = output.images[0, -3:, -3:, -1]

          _lowerCamelCase					: Union[str, Any]		    = self.get_dummy_inputs()
          _lowerCamelCase					: List[Any]		    = 3 * [inputs.pop("prompt"  )]

          _lowerCamelCase					: Optional[Any]		    = pipe.tokenizer(
              a_,padding="max_length",max_length=pipe.tokenizer.model_max_length,truncation=a_,return_tensors="np",)
          _lowerCamelCase					: List[str]		    = text_inputs["input_ids"]

          _lowerCamelCase					: int		    = pipe.text_encoder(input_ids=text_inputs.astype(np.intaa  )  )[0]

          _lowerCamelCase					: List[Any]		    = prompt_embeds

          # forward
          _lowerCamelCase					: List[Any]		    = pipe(**a_  )
          _lowerCamelCase					: List[str]		    = output.images[0, -3:, -3:, -1]

          assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()  ).max() < 1e-4



    def 	lowerCamelCase_	(						self   :							Dict  ):
          _lowerCamelCase					: Tuple		    = OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint,provider="CPUExecutionProvider"  )
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Tuple		    = self.get_dummy_inputs()
          _lowerCamelCase					: Dict		    = 3 * ["this is a negative prompt"]
          _lowerCamelCase					: Optional[Any]		    = negative_prompt
          _lowerCamelCase					: Any		    = 3 * [inputs["prompt"]]

          # forward
          _lowerCamelCase					: str		    = pipe(**a_  )
          _lowerCamelCase					: List[str]		    = output.images[0, -3:, -3:, -1]

          _lowerCamelCase					: Union[str, Any]		    = self.get_dummy_inputs()
          _lowerCamelCase					: Union[str, Any]		    = 3 * [inputs.pop("prompt"  )]

          _lowerCamelCase					: List[Any]		    = []
          for p in [prompt, negative_prompt]:
                _lowerCamelCase					: int		    = pipe.tokenizer(
                    a_,padding="max_length",max_length=pipe.tokenizer.model_max_length,truncation=a_,return_tensors="np",)
                _lowerCamelCase					: Any		    = text_inputs["input_ids"]

                embeds.append(pipe.text_encoder(input_ids=text_inputs.astype(np.intaa  )  )[0]  )

          _lowerCamelCase					: Union[str, Any]		    = embeds

          # forward
          _lowerCamelCase					: Dict		    = pipe(**a_  )
          _lowerCamelCase					: Any		    = output.images[0, -3:, -3:, -1]

          assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()  ).max() < 1e-4


@nightly
@require_onnxruntime
@require_torch_gpu
class 			UpperCAmelCase__    (							unittest.TestCase			):



    @property
    def 	lowerCamelCase_	(						self   :							Optional[Any]  ):
          return (
              "CUDAExecutionProvider",
              {
                  "gpu_mem_limit": "15000000000",  # 15GB
                  "arena_extend_strategy": "kSameAsRequested",
              },
          )



    @property
    def 	lowerCamelCase_	(						self   :							Optional[int]  ):
          _lowerCamelCase					: List[str]		    = ort.SessionOptions()
          _lowerCamelCase					: List[str]		    = False
          return options



    def 	lowerCamelCase_	(						self   :							Optional[int]  ):
          _lowerCamelCase					: Dict		    = OnnxStableDiffusionPipeline.from_pretrained(
              "CompVis/stable-diffusion-v1-4",revision="onnx",safety_checker=a_,feature_extractor=a_,provider=self.gpu_provider,sess_options=self.gpu_options,)
          sd_pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Optional[int]		    = "A painting of a squirrel eating a burger"
          np.random.seed(0  )
          _lowerCamelCase					: Dict		    = sd_pipe([prompt],guidance_scale=6.0,num_inference_steps=1_0,output_type="np"  )
          _lowerCamelCase					: Any		    = output.images

          _lowerCamelCase					: Optional[int]		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 5_1_2, 5_1_2, 3)
          _lowerCamelCase					: str		    = np.array([0.0452, 0.0390, 0.0087, 0.0350, 0.0617, 0.0364, 0.0544, 0.0523, 0.0720]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-3



    def 	lowerCamelCase_	(						self   :							Union[str, Any]  ):
          _lowerCamelCase					: Any		    = DDIMScheduler.from_pretrained(
              "runwayml/stable-diffusion-v1-5",subfolder="scheduler",revision="onnx"  )
          _lowerCamelCase					: str		    = OnnxStableDiffusionPipeline.from_pretrained(
              "runwayml/stable-diffusion-v1-5",revision="onnx",scheduler=a_,safety_checker=a_,feature_extractor=a_,provider=self.gpu_provider,sess_options=self.gpu_options,)
          sd_pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: str		    = "open neural network exchange"
          _lowerCamelCase					: Tuple		    = np.random.RandomState(0  )
          _lowerCamelCase					: Dict		    = sd_pipe([prompt],guidance_scale=7.5,num_inference_steps=1_0,generator=a_,output_type="np"  )
          _lowerCamelCase					: Dict		    = output.images
          _lowerCamelCase					: Union[str, Any]		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 5_1_2, 5_1_2, 3)
          _lowerCamelCase					: Dict		    = np.array([0.2867, 0.1974, 0.1481, 0.7294, 0.7251, 0.6667, 0.4194, 0.5642, 0.6486]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-3



    def 	lowerCamelCase_	(						self   :							Optional[int]  ):
          _lowerCamelCase					: List[Any]		    = LMSDiscreteScheduler.from_pretrained(
              "runwayml/stable-diffusion-v1-5",subfolder="scheduler",revision="onnx"  )
          _lowerCamelCase					: List[Any]		    = OnnxStableDiffusionPipeline.from_pretrained(
              "runwayml/stable-diffusion-v1-5",revision="onnx",scheduler=a_,safety_checker=a_,feature_extractor=a_,provider=self.gpu_provider,sess_options=self.gpu_options,)
          sd_pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: Any		    = "open neural network exchange"
          _lowerCamelCase					: Optional[Any]		    = np.random.RandomState(0  )
          _lowerCamelCase					: Optional[int]		    = sd_pipe([prompt],guidance_scale=7.5,num_inference_steps=1_0,generator=a_,output_type="np"  )
          _lowerCamelCase					: int		    = output.images
          _lowerCamelCase					: Tuple		    = image[0, -3:, -3:, -1]

          assert image.shape == (1, 5_1_2, 5_1_2, 3)
          _lowerCamelCase					: Dict		    = np.array([0.2306, 0.1959, 0.1593, 0.6549, 0.6394, 0.5408, 0.5065, 0.6010, 0.6161]  )

          assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1e-3



    def 	lowerCamelCase_	(						self   :							int  ):
          _lowerCamelCase					: List[str]		    = 0

          def test_callback_fn(__A   :							int,__A   :							int,__A   :							np.ndarray  ) -> None:
                _lowerCamelCase					: Optional[int]		    = True
                nonlocal number_of_steps
                number_of_steps += 1
                if step == 0:
                      assert latents.shape == (1, 4, 6_4, 6_4)
                      _lowerCamelCase					: Any		    = latents[0, -3:, -3:, -1]
                      _lowerCamelCase					: Union[str, Any]		    = np.array(
                          [-0.6772, -0.3835, -1.2456, 0.1905, -1.0974, 0.6967, -1.9353, 0.0178, 1.0167]  )

                      assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 1e-3
                elif step == 5:
                      assert latents.shape == (1, 4, 6_4, 6_4)
                      _lowerCamelCase					: Union[str, Any]		    = latents[0, -3:, -3:, -1]
                      _lowerCamelCase					: Optional[int]		    = np.array(
                          [-0.3351, 0.2241, -0.1837, -0.2325, -0.6577, 0.3393, -0.0241, 0.5899, 1.3875]  )

                      assert np.abs(latents_slice.flatten() - expected_slice  ).max() < 1e-3

          _lowerCamelCase					: Tuple		    = False

          _lowerCamelCase					: Optional[int]		    = OnnxStableDiffusionPipeline.from_pretrained(
              "runwayml/stable-diffusion-v1-5",revision="onnx",safety_checker=a_,feature_extractor=a_,provider=self.gpu_provider,sess_options=self.gpu_options,)
          pipe.set_progress_bar_config(disable=a_  )

          _lowerCamelCase					: List[Any]		    = "Andromeda galaxy in a bottle"

          _lowerCamelCase					: str		    = np.random.RandomState(0  )
          pipe(
              prompt=a_,num_inference_steps=5,guidance_scale=7.5,generator=a_,callback=a_,callback_steps=1,)
          assert test_callback_fn.has_been_called
          assert number_of_steps == 6



    def 	lowerCamelCase_	(						self   :							Tuple  ):
          _lowerCamelCase					: Optional[Any]		    = OnnxStableDiffusionPipeline.from_pretrained(
              "runwayml/stable-diffusion-v1-5",revision="onnx",safety_checker=a_,feature_extractor=a_,provider=self.gpu_provider,sess_options=self.gpu_options,)
          assert isinstance(a_,a_  )
          assert pipe.safety_checker is None

          _lowerCamelCase					: Tuple		    = pipe("example prompt",num_inference_steps=2  ).images[0]
          assert image is not None

          # check that there's no error when saving a pipeline with one of the models being None
          with tempfile.TemporaryDirectory() as tmpdirname:
                pipe.save_pretrained(a_  )
                _lowerCamelCase					: Optional[int]		    = OnnxStableDiffusionPipeline.from_pretrained(a_  )

          # sanity check that the pipeline still works
          assert pipe.safety_checker is None
          _lowerCamelCase					: Dict		    = pipe("example prompt",num_inference_steps=2  ).images[0]
          assert image is not None






"""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 SPIECE_UNDERLINE, logging


__UpperCAmelCase						=			logging.get_logger(__name__)

__UpperCAmelCase						=			{'''vocab_file''': '''spiece.model'''}

__UpperCAmelCase						=			{
    '''vocab_file''': {
        '''TsinghuaAI/CPM-Generate''': '''https://huggingface.co/TsinghuaAI/CPM-Generate/resolve/main/spiece.model''',
    }
}



class 					__UpperCAmelCase							(						_UpperCamelCase  ):
				def __init__(		self    :			str	, a_    :			Dict	, a_    :			List[str]=False	, a_    :			Any=True	, a_    :			int=False	, a_    :			Union[str, Any]="<s>"	, a_    :			Optional[int]="</s>"	, a_    :			int="<unk>"	, a_    :			List[Any]="<sep>"	, a_    :			Dict="<pad>"	, a_    :			Any="<cls>"	, a_    :			Optional[Any]="<mask>"	, a_    :			int=["<eop>", "<eod>"]	, a_    :			Optional[Dict[str, Any]] = None	, **a_    :			int	, )	->	None:



							'''simple docstring'''



							a__  :	List[str]		 =			AddedToken(a_	, lstrip=a_	, rstrip=a_    ) if isinstance(a_	, a_    ) else mask_token

							a__  :	List[str]		 =			{} if sp_model_kwargs is None else sp_model_kwargs

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

							a__  :	Union[str, Any]		 =			3

							a__  :	Dict		 =			do_lower_case
							a__  :	Union[str, Any]		 =			remove_space
							a__  :	int		 =			keep_accents
							a__  :	str		 =			vocab_file

							a__  :	str		 =			spm.SentencePieceProcessor(**self.sp_model_kwargs    )
							self.sp_model.Load(a_    )

							try:
										import jieba
							except ModuleNotFoundError as error:
										raise error.__class__(
										    "You need to install jieba to use CpmTokenizer or CpmTokenizerFast. "
										    "See https://pypi.org/project/jieba/ for installation."    )
							a__  :	Optional[int]		 =			jieba
							a__  :	Optional[int]		 =			str.maketrans(" \n"	, "\u2582\u2583"    )
				@property
				# Copied from transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.vocab_size
				def       UpperCAmelCase      (		self    :			Union[str, Any]    )	->	str:



							'''simple docstring'''



							return len(self.sp_model    )
				def       UpperCAmelCase      (		self    :			Dict    )	->	Union[str, Any]:



							'''simple docstring'''



							a__  :	Optional[int]		 =			{self.convert_ids_to_tokens(a_    ): i for i in range(self.vocab_size    )}
							vocab.update(self.added_tokens_encoder    )
							return vocab
				def __getstate__(		self    :			Tuple    )	->	List[str]:



							'''simple docstring'''



							a__  :	Tuple		 =			self.__dict__.copy()
							a__  :	Union[str, Any]		 =			None
							return state
				def __setstate__(		self    :			Tuple	, a_    :			int    )	->	List[str]:



							'''simple docstring'''



							a__  :	Any		 =			d

							# for backward compatibility
							if not hasattr(self	, "sp_model_kwargs"    ):
										a__  :	str		 =			{}

							a__  :	List[str]		 =			spm.SentencePieceProcessor(**self.sp_model_kwargs    )
							self.sp_model.Load(self.vocab_file    )
				def       UpperCAmelCase      (		self    :			List[Any]	, a_    :			Optional[Any]    )	->	List[str]:



							'''simple docstring'''



							if self.remove_space:
										a__  :	Union[str, Any]		 =			" ".join(inputs.strip().split()    )
							else:
										a__  :	Optional[Any]		 =			inputs
							a__  :	List[str]		 =			outputs.replace("``"	, "\""    ).replace("''"	, "\""    )

							if not self.keep_accents:
										a__  :	Union[str, Any]		 =			unicodedata.normalize("NFKD"	, a_    )
										a__  :	Union[str, Any]		 =			"".join([c for c in outputs if not unicodedata.combining(a_    )]    )
							if self.do_lower_case:
										a__  :	List[Any]		 =			outputs.lower()

							return outputs
				def       UpperCAmelCase      (		self    :			Any	, a_    :			str    )	->	List[str]:



							'''simple docstring'''



							a__  :	Optional[Any]		 =			self.preprocess_text(a_    )
							a__  :	Dict		 =			self.sp_model.encode(a_	, out_type=a_    )
							a__  :	Optional[Any]		 =			[]
							for piece in pieces:
										if len(a_    ) > 1 and piece[-1] == str(","    ) and piece[-2].isdigit():
													a__  :	Optional[Any]		 =			self.sp_model.EncodeAsPieces(piece[:-1].replace(a_	, ""    )    )
													if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
																if len(cur_pieces[0]    ) == 1:
																			a__  :	List[str]		 =			cur_pieces[1:]
																else:
																			a__  :	List[str]		 =			cur_pieces[0][1:]
													cur_pieces.append(piece[-1]    )
													new_pieces.extend(a_    )
										else:
													new_pieces.append(a_    )

							return new_pieces
				def       UpperCAmelCase      (		self    :			int	, a_    :			Dict    )	->	int:



							'''simple docstring'''



							return self.sp_model.PieceToId(a_    )
				def       UpperCAmelCase      (		self    :			Dict	, a_    :			Tuple    )	->	List[Any]:



							'''simple docstring'''



							return self.sp_model.IdToPiece(a_    )
				def       UpperCAmelCase      (		self    :			Union[str, Any]	, a_    :			List[Any]    )	->	str:



							'''simple docstring'''



							a__  :	Optional[Any]		 =			"".join(a_    ).replace(a_	, " "    ).strip()
							return out_string
				def       UpperCAmelCase      (		self    :			str	, a_    :			List[int]	, a_    :			Optional[List[int]] = None    )	->	List[int]:



							'''simple docstring'''



							a__  :	List[Any]		 =			[self.sep_token_id]
							a__  :	int		 =			[self.cls_token_id]
							if token_ids_a is None:
										return token_ids_a + sep + cls
							return token_ids_a + sep + token_ids_a + sep + cls
				def       UpperCAmelCase      (		self    :			int	, a_    :			List[int]	, a_    :			Optional[List[int]] = None	, a_    :			bool = False    )	->	List[int]:



							'''simple docstring'''



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

							if token_ids_a is not None:
										return ([0] * len(a_    )) + [1] + ([0] * len(a_    )) + [1, 1]
							return ([0] * len(a_    )) + [1, 1]
				def       UpperCAmelCase      (		self    :			List[Any]	, a_    :			List[int]	, a_    :			Optional[List[int]] = None    )	->	List[int]:



							'''simple docstring'''



							a__  :	List[str]		 =			[self.sep_token_id]
							a__  :	Tuple		 =			[2]

							if token_ids_a is None:
										return len(token_ids_a + sep    ) * [0] + cls_segment_id
							return len(token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1] + cls_segment_id
				def       UpperCAmelCase      (		self    :			Dict	, a_    :			str	, a_    :			Optional[str] = None    )	->	Tuple[str]:



							'''simple docstring'''



							if not os.path.isdir(a_    ):
										logger.error(F"Vocabulary path ({save_directory}) should be a directory"    )
										return
							a__  :	Optional[int]		 =			os.path.join(
							    a_	, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]    )

							if os.path.abspath(self.vocab_file    ) != os.path.abspath(a_    ) and os.path.isfile(self.vocab_file    ):
										copyfile(self.vocab_file	, a_    )
							elif not os.path.isfile(self.vocab_file    ):
										with open(a_	, "wb"    ) as fi:
													a__  :	int		 =			self.sp_model.serialized_model_proto()
													fi.write(a_    )

							return (out_vocab_file,)






				def       UpperCAmelCase      (		self    :			str	, *a_    :			Union[str, Any]	, **a_    :			Any    )	->	int:



							'''simple docstring'''



							a__  :	Optional[int]		 =			super()._decode(*a_	, **a_    )
							a__  :	Tuple		 =			text.replace(" "	, ""    ).replace("\u2582"	, " "    ).replace("\u2583"	, "\n"    )
							return text