





'''simple docstring'''






import json
import os
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


A_		:  Optional[Any]		 =						logging.get_logger(__name__)

A_		:  str		 =						{"vocab_file": "vocab.json"}

A_		:  List[str]		 =						{
    "vocab_file": {
        "mgp-str": "https://huggingface.co/alibaba-damo/mgp-str-base/blob/main/vocab.json",
    }
}

A_		:  Any		 =						{"mgp-str": 27}
class 					__snake_case  (					__SCREAMING_SNAKE_CASE							):






   '''simple docstring'''





   lowerCamelCase__    							=      VOCAB_FILES_NAMES
   lowerCamelCase__    							=      PRETRAINED_VOCAB_FILES_MAP
   lowerCamelCase__    							=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES

   def __init__(							self	,		__SCREAMING_SNAKE_CASE	,		__SCREAMING_SNAKE_CASE="[GO]"	,		__SCREAMING_SNAKE_CASE="[GO]"	,		__SCREAMING_SNAKE_CASE="[s]"	,		__SCREAMING_SNAKE_CASE="[GO]"	,		**__SCREAMING_SNAKE_CASE       ):
    super().__init__(
        unk_token=__SCREAMING_SNAKE_CASE	,		bos_token=__SCREAMING_SNAKE_CASE	,		eos_token=__SCREAMING_SNAKE_CASE	,		pad_token=__SCREAMING_SNAKE_CASE	,		**__SCREAMING_SNAKE_CASE	,		)

    with open(__SCREAMING_SNAKE_CASE	,		encoding="""utf-8"""       ) as vocab_handle:
     snake_case__     :					List[Any]    =  json.load(__SCREAMING_SNAKE_CASE       )
    snake_case__     :					int    =  {v: k for k, v in self.vocab.items()}

   @property
   def 		__UpperCamelCase						(							self       ):
    return len(self.vocab       )

   def 		__UpperCamelCase						(							self       ):
    return dict(self.vocab	,		**self.added_tokens_encoder       )

   def 		__UpperCamelCase						(							self	,		__SCREAMING_SNAKE_CASE       ):
    snake_case__     :					Tuple    =  []
    for s in text:
     char_tokens.extend(__SCREAMING_SNAKE_CASE       )
    return char_tokens

   def 		__UpperCamelCase						(							self	,		__SCREAMING_SNAKE_CASE       ):
    return self.vocab.get(__SCREAMING_SNAKE_CASE	,		self.vocab.get(self.unk_token       )       )

   def 		__UpperCamelCase						(							self	,		__SCREAMING_SNAKE_CASE       ):
    return self.decoder.get(__SCREAMING_SNAKE_CASE       )


   def 		__UpperCamelCase						(							self	,		__SCREAMING_SNAKE_CASE	,		__SCREAMING_SNAKE_CASE = None       ):
    if not os.path.isdir(__SCREAMING_SNAKE_CASE       ):
     logger.error("""Vocabulary path ({}) should be a directory""".format(__SCREAMING_SNAKE_CASE       )       )
     return
    snake_case__     :					int    =  os.path.join(
        __SCREAMING_SNAKE_CASE	,		(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]       )

    with open(__SCREAMING_SNAKE_CASE	,		"""w"""	,		encoding="""utf-8"""       ) as f:
     f.write(json.dumps(self.vocab	,		indent=2	,		sort_keys=__SCREAMING_SNAKE_CASE	,		ensure_ascii=__SCREAMING_SNAKE_CASE       ) + """\n"""       )

    return (vocab_file,)





"""simple docstring"""



import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class  snake_case__      (       unittest.TestCase       ):


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
            "unet/diffusion_pytorch_model.bin",
            # Removed: 'unet/diffusion_pytorch_model.safetensors',
        ]
        self.assertFalse(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            # Removed: 'text_encoder/model.safetensors',
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertFalse(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        # pass variant but use the non-variant filenames
        __a       =    [
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
            "unet/diffusion_pytorch_model.fp16.bin",
            # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
        ]
        __a       =    "fp16"
        self.assertFalse(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        # pass variant but use the non-variant filenames
        __a       =    [
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)






 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            # 'text_encoder/model.fp16.safetensors',
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertFalse(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)
