
# Copyright 2023 The HuggingFace 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 typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_A						      =				{
    "configuration_efficientnet": [
        "EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "EfficientNetConfig",
        "EfficientNetOnnxConfig",
    ]
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _A						      =				["EfficientNetImageProcessor"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _A						      =				[
     "EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST",
     "EfficientNetForImageClassification",
     "EfficientNetModel",
     "EfficientNetPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_efficientnet import (
     EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP,
     EfficientNetConfig,
     EfficientNetOnnxConfig,
 )

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .image_processing_efficientnet import EfficientNetImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_efficientnet import (
      EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST,
      EfficientNetForImageClassification,
      EfficientNetModel,
      EfficientNetPreTrainedModel,
  )

else:
 import sys

 _A						      =				_LazyModule(__name__, globals()["__file__"], _import_structure)



import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin







@require_jieba
class   lowerCamelCase	(						A_							,				unittest.TestCase						):
     UpperCAmelCase__       :							Any     =	CpmAntTokenizer
     UpperCAmelCase__       :							Optional[Any]     =	False





     def 	UpperCAmelCase(self   :					Optional[Any]     )		->		Dict:
         super().setUp()

         snake_case				  =      [
             "<d>",
             "</d>",
             "<s>",
             "</s>",
             "</_>",
             "<unk>",
             "<pad>",
             "</n>",
             "我",
             "是",
             "C",
             "P",
             "M",
             "A",
             "n",
             "t",
         ]
         snake_case				  =      os.path.join(self.tmpdirname       ,					VOCAB_FILES_NAMES["vocab_file"]     )
         with open(self.vocab_file       ,					"w"       ,					encoding="utf-8"     ) as vocab_writer:
             vocab_writer.write("".join([x + "\n" for x in vocab_tokens]     )     )





     @tooslow
     def 	UpperCAmelCase(self   :					Optional[Any]     )		->		Optional[int]:
         snake_case				  =      CpmAntTokenizer.from_pretrained("openbmb/cpm-ant-10b"     )
         snake_case				  =      "今天天气真好！"
         snake_case				  =      ["今天", "天气", "真", "好", "！"]
         snake_case				  =      tokenizer.tokenize(_A     )
         self.assertListEqual(_A       ,					_A     )
         snake_case				  =      "今天天气真好！"
         snake_case				  =      [tokenizer.bos_token] + tokens

         snake_case				  =      [6, 9_8_0_2, 1_4_9_6_2, 2_0_8_2, 8_3_1, 2_4_4]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_A     )       ,					_A     )

         snake_case				  =      tokenizer.decode(_A     )
         self.assertEqual(_A       ,					_A     )

