
# Copyright 2022 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.

import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available



def 						lowercase_      (       A__ :    Tuple=None		)							->							Optional[int]:
    """simple docstring"""

    if subparsers is not None:
        snake_case								= subparsers.add_parser("env"		)
    else:
        snake_case								= argparse.ArgumentParser("Accelerate env command"		)

    parser.add_argument(
        "--config_file"			,		default=A__			,		help="The config file to use for the default values in the launching script."		)

    if subparsers is not None:
        parser.set_defaults(func=A__		)
    return parser



def 						lowercase_      (       A__ :    Any		)							->							Union[str, Any]:
    """simple docstring"""

    snake_case								= torch.__version__
    snake_case								= torch.cuda.is_available()
    snake_case								= is_xpu_available()
    snake_case								= is_npu_available()

    snake_case								= "Not found"
    # Get the default from the config file.
    if args.config_file is not None or os.path.isfile(A__		):
        snake_case								= load_config_from_file(args.config_file		).to_dict()

    snake_case								= {
        "`Accelerate` version": version,
        "Platform": platform.platform(),
        "Python version": platform.python_version(),
        "Numpy version": np.__version__,
        "PyTorch version (GPU?)": F'{pt_version} ({pt_cuda_available})',
        "PyTorch XPU available": str(A__		),
        "PyTorch NPU available": str(A__		),
        "System RAM": F'{psutil.virtual_memory().total / 1024 ** 3:.2f} GB',
    }
    if pt_cuda_available:
        snake_case								= torch.cuda.get_device_name()

    print("\nCopy-and-paste the text below in your GitHub issue\n"		)
    print("\n".join([F'- {prop}: {val}' for prop, val in info.items()]		)		)

    print("- `Accelerate` default config:" if args.config_file is None else "- `Accelerate` config passed:"		)
    snake_case								= (
        "\n".join([F'\t- {prop}: {val}' for prop, val in accelerate_config.items()]		)
        if isinstance(A__			,		A__		)
        else F'\t{accelerate_config}'
    )
    print(A__		)

    snake_case								= accelerate_config

    return info



def 						lowercase_      (       )							->							int:
    """simple docstring"""

    snake_case								= env_command_parser()
    snake_case								= parser.parse_args()
    env_command(A__		)
    return 0


if __name__ == "__main__":
   raise SystemExit(main())



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mobilebert import MobileBertTokenizer


_A   =			logging.get_logger(__name__)

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

_A   =			{
    "vocab_file": {"mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/vocab.txt"},
    "tokenizer_file": {
        "mobilebert-uncased": "https://huggingface.co/google/mobilebert-uncased/resolve/main/tokenizer.json"
    },
}

_A   =			{"mobilebert-uncased": 5_12}


_A   =			{}







class 					lowerCamelCase		(  A_  ):
     UpperCAmelCase__    :							Tuple									=		VOCAB_FILES_NAMES
     UpperCAmelCase__    :							Any									=		PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__    :							Tuple									=		PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__    :							Tuple									=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__    :							Optional[Any]									=		MobileBertTokenizer





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

         snake_case								= json.loads(self.backend_tokenizer.normalizer.__getstate__()       )
         if (
             normalizer_state.get("lowercase"    ,   _A       ) != do_lower_case
             or normalizer_state.get("strip_accents"    ,   _A       ) != strip_accents
             or normalizer_state.get("handle_chinese_chars"    ,   _A       ) != tokenize_chinese_chars
         ):
             snake_case								= getattr(_A    ,   normalizer_state.pop("type"       )       )
             snake_case								= do_lower_case
             snake_case								= strip_accents
             snake_case								= tokenize_chinese_chars
             snake_case								= normalizer_class(**_A       )

         snake_case								= do_lower_case





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

