code: 
  
  
  
  """simple docstring"""
  import importlib
  import importlib.metadata
  import os
  import warnings
  from distutils.util import strtobool
  from functools import lru_cache
  
  import torch
  from packaging import version
  from packaging.version import parse
  
  from .environment import parse_flag_from_env
  from .versions import compare_versions, is_torch_version
  
  
  try:
    import torch_xla.core.xla_model as xm  # noqa: F401
  
    _lowerCAmelCase					:Tuple  =      True
  except ImportError:
    _lowerCAmelCase					:int  =      False
  
  
  # Cache this result has it's a C FFI call which can be pretty time-consuming
  _lowerCAmelCase					:int  =      torch.distributed.is_available()
  
  
  
  
  
  def 				lowerCamelCase_		(UpperCamelCase__	:	str							):
      # Check we're not importing a "pkg_name" directory somewhere but the actual library by trying to grab the version
      _UpperCAmelCase							:						Any       							=					importlib.util.find_spec(UpperCamelCase__							) is not None
      if package_exists:
          try:
              _UpperCAmelCase							:						List[Any]       							=					importlib.metadata.metadata(UpperCamelCase__							)
              return True
          except importlib.metadata.PackageNotFoundError:
              return False
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _torch_distributed_available
  
  
  
  
  
  def 				lowerCamelCase_		():
      try:
          pass
      except ImportError:
          print(
              '''Intel(R) oneCCL Bindings for PyTorch* is required to run DDP on Intel(R) GPUs, but it is not'''
              ''' detected. If you see \"ValueError: Invalid backend: \'ccl\'\" error, please install Intel(R) oneCCL'''
              ''' Bindings for PyTorch*.'''							)
      return (
          importlib.util.find_spec('''torch_ccl'''							) is not None
          or importlib.util.find_spec('''oneccl_bindings_for_pytorch'''							) is not None
      )
  
  
  
  
  
  def 				lowerCamelCase_		():
      return importlib.metadata.version('''oneccl_bind_pt'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''transformer_engine'''							)
  
  
  
  
  
  @lru_cache
  def 				lowerCamelCase_		(UpperCamelCase__	:	Optional[int]=True							):
      # Due to bugs on the amp series GPUs, we disable torch-xla on them
      if torch.cuda.is_available():
          return False
      if _tpu_available and check_device:
          try:
              # Will raise a RuntimeError if no XLA configuration is found
              _UpperCAmelCase							:						Union[str, Any]       							=					xm.xla_device()
              return True
          except RuntimeError:
              return False
      return _tpu_available
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''deepspeed'''							)
  
  
  
  
  
  def 				lowerCamelCase_		(UpperCamelCase__	:	int=False							):
      if is_tpu_available():
          return not ignore_tpu
      if torch.cuda.is_available():
          return torch.cuda.is_bfaa_supported()
      if is_npu_available():
          return False
      return True
  
  
  
  
  
  def 				lowerCamelCase_		():
      _UpperCAmelCase							:						str       							=					_is_package_available('''bitsandbytes'''							)
      if package_exists:
          _UpperCAmelCase							:						Optional[int]       							=					version.parse(importlib.metadata.version('''bitsandbytes'''							)							)
          return compare_versions(UpperCamelCase__  , '''>='''  , '''0.39.0'''							)
      return False
  
  
  
  
  
  def 				lowerCamelCase_		():
      _UpperCAmelCase							:						List[Any]       							=					_is_package_available('''bitsandbytes'''							)
      if package_exists:
          _UpperCAmelCase							:						Optional[int]       							=					version.parse(importlib.metadata.version('''bitsandbytes'''							)							)
          return compare_versions(UpperCamelCase__  , '''>='''  , '''0.37.2'''							)
      return False
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''bitsandbytes'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      if strtobool(os.environ.get('''ACCELERATE_USE_MEGATRON_LM'''  , '''False'''							)							) == 1:
          _UpperCAmelCase							:						Optional[int]       							=					importlib.util.find_spec('''megatron'''							) is not None
          if package_exists:
              try:
                  _UpperCAmelCase							:						Any       							=					parse(importlib.metadata.version('''megatron-lm'''							)							)
                  return compare_versions(UpperCamelCase__  , '''>='''  , '''2.2.0'''							)
              except Exception as e:
                  warnings.warn(F'Parse Megatron version failed. Exception:{e}'							)
                  return False
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''safetensors'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''transformers'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''datasets'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''aim'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''tensorboard'''							) or _is_package_available('''tensorboardX'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''wandb'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''comet_ml'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''boto3'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      if _is_package_available('''rich'''							):
          if "ACCELERATE_DISABLE_RICH" in os.environ:
              warnings.warn(
                  '''`ACCELERATE_DISABLE_RICH` is deprecated and will be removed in v0.22.0 and deactivated by default. Please use `ACCELERATE_ENABLE_RICH` if you wish to use `rich`.'''							)
              return not parse_flag_from_env('''ACCELERATE_DISABLE_RICH'''  , UpperCamelCase__							)
          return parse_flag_from_env('''ACCELERATE_ENABLE_RICH'''  , UpperCamelCase__							)
      return False
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''sagemaker'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''tqdm'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return _is_package_available('''mlflow'''							)
  
  
  
  
  
  def 				lowerCamelCase_		():
      return is_torch_version('''>='''  , '''1.12'''							) and torch.backends.mps.is_available() and torch.backends.mps.is_built()
  
  
  
  
  
  def 				lowerCamelCase_		():
      def get_major_and_minor_from_version(UpperCamelCase__	:	Union[str, Any]							):
          return str(version.parse(UpperCamelCase__							).major							) + "." + str(version.parse(UpperCamelCase__							).minor							)
  
      _UpperCAmelCase							:						List[Any]       							=					importlib.metadata.version('''torch'''							)
      if importlib.util.find_spec('''intel_extension_for_pytorch'''							) is None:
          return False
      _UpperCAmelCase							:						Any       							=					'''N/A'''
      try:
          _UpperCAmelCase							:						int       							=					importlib.metadata.version('''intel_extension_for_pytorch'''							)
      except importlib.metadata.PackageNotFoundError:
          return False
      _UpperCAmelCase							:						List[str]       							=					get_major_and_minor_from_version(_torch_version							)
      _UpperCAmelCase							:						List[Any]       							=					get_major_and_minor_from_version(_ipex_version							)
      if torch_major_and_minor != ipex_major_and_minor:
          warnings.warn(
              F'Intel Extension for PyTorch {ipex_major_and_minor} needs to work with PyTorch {ipex_major_and_minor}.*,'
              F' but PyTorch {_torch_version} is found. Please switch to the matching version and run again.'							)
          return False
      return True
  
  
  
  
  
  @lru_cache
  def 				lowerCamelCase_		(UpperCamelCase__	:	Any=False							):
      if importlib.util.find_spec('''torch'''							) is None or importlib.util.find_spec('''torch_npu'''							) is None:
          return False
  
      import torch
      import torch_npu  # noqa: F401
  
      if check_device:
          try:
              # Will raise a RuntimeError if no NPU is found
              _UpperCAmelCase							:						Tuple       							=					torch.npu.device_count()
              return torch.npu.is_available()
          except RuntimeError:
              return False
      return hasattr(UpperCamelCase__  , '''npu'''							) and torch.npu.is_available()
  
  
  
  
  
  @lru_cache
  def 				lowerCamelCase_		(UpperCamelCase__	:	Any=False							):
      if not parse_flag_from_env('''ACCELERATE_USE_XPU'''  , default=UpperCamelCase__							):
          return False
      if is_ipex_available():
          import torch
  
          if is_torch_version('''<='''  , '''1.12'''							):
              return False
      else:
          return False
  
      import intel_extension_for_pytorch  # noqa: F401
  
      if check_device:
          try:
              # Will raise a RuntimeError if no XPU  is found
              _UpperCAmelCase							:						List[Any]       							=					torch.xpu.device_count()
              return torch.xpu.is_available()
          except RuntimeError:
              return False
      return hasattr(UpperCamelCase__  , '''xpu'''							) and torch.xpu.is_available()
  
  
  
style_context: 
  
  
  
  """simple docstring"""
  import json
  from typing import List, Optional, Tuple
  
  from tokenizers import normalizers
  
  from ...tokenization_utils import AddedToken
  from ...tokenization_utils_fast import PreTrainedTokenizerFast
  from ...utils import logging
  from .tokenization_mpnet import MPNetTokenizer
  
  
  _lowerCAmelCase					:Dict  =      logging.get_logger(__name__)
  
  _lowerCAmelCase					:Tuple  =      {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}
  
  _lowerCAmelCase					:Any  =      {
      'vocab_file': {
          'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/vocab.txt',
      },
      'tokenizer_file': {
          'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/tokenizer.json',
      },
  }
  
  _lowerCAmelCase					:str  =      {
      'microsoft/mpnet-base': 512,
  }
  
  _lowerCAmelCase					:Union[str, Any]  =      {
      'microsoft/mpnet-base': {'do_lower_case': True},
  }
  class 							_UpperCAmelCase							(				a   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       a__             =VOCAB_FILES_NAMES
       a__             =PRETRAINED_VOCAB_FILES_MAP
       a__             =PRETRAINED_INIT_CONFIGURATION
       a__             =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       a__             =MPNetTokenizer
       a__             =['''input_ids''', '''attention_mask''']
  
  
  
  
  
       def __init__(      self ,			A=None ,			A=None ,			A=True ,			A="<s>" ,			A="</s>" ,			A="</s>" ,			A="<s>" ,			A="[UNK]" ,			A="<pad>" ,			A="<mask>" ,			A=True ,			A=None ,			**A ,			)							->      Dict:
           super().__init__(
               A ,			tokenizer_file=A ,			do_lower_case=A ,			bos_token=A ,			eos_token=A ,			sep_token=A ,			cls_token=A ,			unk_token=A ,			pad_token=A ,			mask_token=A ,			tokenize_chinese_chars=A ,			strip_accents=A ,			**A ,			)
  
           _UpperCAmelCase							:						List[str]       							=					json.loads(self.backend_tokenizer.normalizer.__getstate__()	)
           if (
               pre_tok_state.get('''lowercase''' ,			A	) != do_lower_case
               or pre_tok_state.get('''strip_accents''' ,			A	) != strip_accents
           ):
               _UpperCAmelCase							:						Optional[int]       							=					getattr(A ,			pre_tok_state.pop('''type'''	)	)
               _UpperCAmelCase							:						List[Any]       							=					do_lower_case
               _UpperCAmelCase							:						List[Any]       							=					strip_accents
               _UpperCAmelCase							:						Tuple       							=					pre_tok_class(**A	)
  
           _UpperCAmelCase							:						Union[str, Any]       							=					do_lower_case
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      str:
           if self._mask_token is None:
               if self.verbose:
                   logger.error('''Using mask_token, but it is not set yet.'''	)
               return None
           return str(self._mask_token	)
  
  
  
  
  
       @mask_token.setter
       def 				__lowerCAmelCase			(      self ,			A	)							->      str:
           _UpperCAmelCase							:						Optional[int]       							=					AddedToken(A ,			lstrip=A ,			rstrip=A	) if isinstance(A ,			A	) else value
           _UpperCAmelCase							:						List[Any]       							=					value
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A=None	)							->      str:
           _UpperCAmelCase							:						List[str]       							=					[self.bos_token_id] + token_ids_a + [self.eos_token_id]
           if token_ids_a is None:
               return output
  
           return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = None	)							->      List[int]:
           _UpperCAmelCase							:						int       							=					[self.sep_token_id]
           _UpperCAmelCase							:						int       							=					[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 + sep + token_ids_a + sep	) * [0]
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = None	)							->      Tuple[str]:
           _UpperCAmelCase							:						str       							=					self._tokenizer.model.save(A ,			name=A	)
           return tuple(A	)
  
  
  