



'''simple docstring'''





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_realm import RealmTokenizer


__a  			=						logging.get_logger(__name__)

__a  			=						{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__a  			=						{
    "vocab_file": {
        "google/realm-cc-news-pretrained-embedder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-encoder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-scorer": (
            "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-openqa": (
            "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/vocab.txt"
        ),
        "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/vocab.txt",
        "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/vocab.txt",
        "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/vocab.txt",
        "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/vocab.txt",
    },
    "tokenizer_file": {
        "google/realm-cc-news-pretrained-embedder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/tokenizer.jsont"
        ),
        "google/realm-cc-news-pretrained-encoder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/tokenizer.json"
        ),
        "google/realm-cc-news-pretrained-scorer": (
            "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/tokenizer.json"
        ),
        "google/realm-cc-news-pretrained-openqa": (
            "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/tokenizer.json"
        ),
        "google/realm-orqa-nq-openqa": (
            "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-nq-reader": (
            "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-wq-openqa": (
            "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-wq-reader": (
            "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/tokenizer.json"
        ),
    },
}

__a  			=						{
    "google/realm-cc-news-pretrained-embedder": 512,
    "google/realm-cc-news-pretrained-encoder": 512,
    "google/realm-cc-news-pretrained-scorer": 512,
    "google/realm-cc-news-pretrained-openqa": 512,
    "google/realm-orqa-nq-openqa": 512,
    "google/realm-orqa-nq-reader": 512,
    "google/realm-orqa-wq-openqa": 512,
    "google/realm-orqa-wq-reader": 512,
}

__a  			=						{
    "google/realm-cc-news-pretrained-embedder": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-encoder": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-scorer": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-openqa": {"do_lower_case": True},
    "google/realm-orqa-nq-openqa": {"do_lower_case": True},
    "google/realm-orqa-nq-reader": {"do_lower_case": True},
    "google/realm-orqa-wq-openqa": {"do_lower_case": True},
    "google/realm-orqa-wq-reader": {"do_lower_case": True},
}







class        UpperCAmelCase_			(			_a      ):
    """simple docstring"""







    lowercase   =						VOCAB_FILES_NAMES
    lowercase   =						PRETRAINED_VOCAB_FILES_MAP
    lowercase   =						PRETRAINED_INIT_CONFIGURATION
    lowercase   =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    lowercase   =						RealmTokenizer




    def __init__(       self   :	Tuple					,	snake_case_   :	str=None					,	snake_case_   :	Any=None					,	snake_case_   :	List[str]=True					,	snake_case_   :	str="[UNK]"					,	snake_case_   :	Dict="[SEP]"					,	snake_case_   :	Tuple="[PAD]"					,	snake_case_   :	Optional[int]="[CLS]"					,	snake_case_   :	List[Any]="[MASK]"					,	snake_case_   :	Dict=True					,	snake_case_   :	List[str]=None					,	**snake_case_   :	Optional[int]					,	):
          super().__init__(
              snake_case_					,	tokenizer_file=snake_case_					,	do_lower_case=snake_case_					,	unk_token=snake_case_					,	sep_token=snake_case_					,	pad_token=snake_case_					,	cls_token=snake_case_					,	mask_token=snake_case_					,	tokenize_chinese_chars=snake_case_					,	strip_accents=snake_case_					,	**snake_case_					,	)

          snake_case__    :       Optional[int]       		= json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
          if (
              normalizer_state.get("""lowercase"""					,	snake_case_		) != do_lower_case
              or normalizer_state.get("""strip_accents"""					,	snake_case_		) != strip_accents
              or normalizer_state.get("""handle_chinese_chars"""					,	snake_case_		) != tokenize_chinese_chars
          ):
                snake_case__    :       Dict       		= getattr(snake_case_					,	normalizer_state.pop("""type"""		)		)
                snake_case__    :       List[Any]       		= do_lower_case
                snake_case__    :       int       		= strip_accents
                snake_case__    :       List[str]       		= tokenize_chinese_chars
                snake_case__    :       Tuple       		= normalizer_class(**snake_case_		)

          snake_case__    :       Optional[Any]       		= do_lower_case




    def lowerCamelCase			(       self   :	int					,	snake_case_   :	Optional[Any]					,	**snake_case_   :	List[str]		):
          snake_case__    :       List[Any]       		= PaddingStrategy.MAX_LENGTH

          snake_case__    :       Tuple       		= text
          snake_case__    :       Any       		= kwargs.pop("""text_pair"""					,	snake_case_		)
          snake_case__    :       int       		= kwargs.pop("""return_tensors"""					,	snake_case_		)

          snake_case__    :       Union[str, Any]       		= {
              """input_ids""": [],
              """attention_mask""": [],
              """token_type_ids""": [],
          }

          for idx, candidate_text in enumerate(snake_case_		):
                if batch_text_pair is not None:
                      snake_case__    :       List[Any]       		= batch_text_pair[idx]
                else:
                      snake_case__    :       Tuple       		= None

                snake_case__    :       Optional[Any]       		= super().__call__(snake_case_					,	snake_case_					,	return_tensors=snake_case_					,	**snake_case_		)

                snake_case__    :       Tuple       		= encoded_candidates.get("""input_ids"""		)
                snake_case__    :       Union[str, Any]       		= encoded_candidates.get("""attention_mask"""		)
                snake_case__    :       List[str]       		= encoded_candidates.get("""token_type_ids"""		)

                if encoded_input_ids is not None:
                      output_data["input_ids"].append(snake_case_		)
                if encoded_attention_mask is not None:
                      output_data["attention_mask"].append(snake_case_		)
                if encoded_token_type_ids is not None:
                      output_data["token_type_ids"].append(snake_case_		)

          snake_case__    :       Dict       		= {key: item for key, item in output_data.items() if len(snake_case_		) != 0}

          return BatchEncoding(snake_case_					,	tensor_type=snake_case_		)




    def lowerCamelCase			(       self   :	Any					,	snake_case_   :	Dict					,	snake_case_   :	Optional[int]=None		):
          snake_case__    :       Tuple       		= [self.cls_token_id] + token_ids_a + [self.sep_token_id]

          if token_ids_a:
                output += token_ids_a + [self.sep_token_id]

          return output




    def lowerCamelCase			(       self   :	int					,	snake_case_   :	List[int]					,	snake_case_   :	Optional[List[int]] = None		):
          snake_case__    :       Tuple       		= [self.sep_token_id]
          snake_case__    :       Dict       		= [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 lowerCamelCase			(       self   :	Dict					,	snake_case_   :	str					,	snake_case_   :	Optional[str] = None		):
          snake_case__    :       int       		= self._tokenizer.model.save(snake_case_					,	name=snake_case_		)
          return tuple(snake_case_		)





'''simple docstring'''





# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import sys

import transformers


__a  			=						"3"

print("Python version:", sys.version)
print("transformers version:", transformers.__version__)

try:
       import torch

       print("Torch version:", torch.__version__)
       print("Cuda available:", torch.cuda.is_available())
       print("Cuda version:", torch.version.cuda)
       print("CuDNN version:", torch.backends.cudnn.version())
       print("Number of GPUs available:", torch.cuda.device_count())
       print("NCCL version:", torch.cuda.nccl.version())
except ImportError:
       print("Torch version:", None)

try:
       import deepspeed

       print("DeepSpeed version:", deepspeed.__version__)
except ImportError:
       print("DeepSpeed version:", None)

try:
       import tensorflow as tf

       print("TensorFlow version:", tf.__version__)
       print("TF GPUs available:", bool(tf.config.list_physical_devices("GPU")))
       print("Number of TF GPUs available:", len(tf.config.list_physical_devices("GPU")))
except ImportError:
       print("TensorFlow version:", None)
