

import json
import os
import shutil
import tempfile
import unittest

from transformers import BatchEncoding, CanineTokenizer
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.tokenization_utils import AddedToken
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin



class SCREAMING_SNAKE_CASE     (  a_       ,							unittest.TestCase			):
  """simple docstring"""






  lowerCamelCase   :      int										=CanineTokenizer
  lowerCamelCase   :      List[str]										=False







  def 	SCREAMING_SNAKE_CASE   (      self			:   List[str]   )							->     Optional[int]:






     """simple docstring"""







     super().setUp()
     __lowerCAmelCase  :      str    =						CanineTokenizer()
     tokenizer.save_pretrained(self.tmpdirname   )







  @cached_property
  def 	SCREAMING_SNAKE_CASE   (      self			:   List[Any]   )							->     Optional[Any]:






     """simple docstring"""







     return CanineTokenizer.from_pretrained("""google/canine-s"""   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Dict	,							**lowerCAmelCase			:   Union[str, Any]   )							->     CanineTokenizer:






     """simple docstring"""







     __lowerCAmelCase  :      str    =						self.tokenizer_class.from_pretrained(self.tmpdirname	,							**lowerCAmelCase   )
     __lowerCAmelCase  :      List[Any]    =						10_24
     return tokenizer







  @require_torch
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     str:






     """simple docstring"""







     __lowerCAmelCase  :      Dict    =						self.canine_tokenizer
     __lowerCAmelCase  :      Any    =						["""Life is like a box of chocolates.""", """You never know what you're gonna get."""]
     # fmt: off
     __lowerCAmelCase  :      Optional[Any]    =						[5_73_44, 76, 1_05, 1_02, 1_01, 32, 1_05, 1_15, 32, 1_08, 1_05, 1_07, 1_01, 32, 97, 32, 98, 1_11, 1_20, 32, 1_11, 1_02, 32, 99, 1_04, 1_11, 99, 1_11, 1_08, 97, 1_16, 1_01, 1_15, 46, 5_73_45, 0, 0, 0, 0]
     # fmt: on
     __lowerCAmelCase  :      str    =						tokenizer(lowerCAmelCase	,							padding=lowerCAmelCase	,							return_tensors="""pt"""   )
     self.assertIsInstance(lowerCAmelCase	,							lowerCAmelCase   )

     __lowerCAmelCase  :      Optional[Any]    =						list(batch.input_ids.numpy()[0]   )

     self.assertListEqual(lowerCAmelCase	,							lowerCAmelCase   )

     self.assertEqual((2, 39)	,							batch.input_ids.shape   )
     self.assertEqual((2, 39)	,							batch.attention_mask.shape   )







  @require_torch
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     int:






     """simple docstring"""







     __lowerCAmelCase  :      Tuple    =						self.canine_tokenizer
     __lowerCAmelCase  :      List[str]    =						["""Once there was a man.""", """He wrote a test in HuggingFace Tranformers."""]
     __lowerCAmelCase  :      Dict    =						tokenizer(lowerCAmelCase	,							padding=lowerCAmelCase	,							return_tensors="""pt"""   )
     # check if input_ids, attention_mask and token_type_ids are returned
     self.assertIn("""input_ids"""	,							lowerCAmelCase   )
     self.assertIn("""attention_mask"""	,							lowerCAmelCase   )
     self.assertIn("""token_type_ids"""	,							lowerCAmelCase   )







  @require_torch
  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Dict:






     """simple docstring"""







     __lowerCAmelCase  :      str    =						self.canine_tokenizer
     __lowerCAmelCase  :      Optional[int]    =						[
         """What's the weater?""",
         """It's about 25 degrees.""",
     ]
     __lowerCAmelCase  :      Dict    =						tokenizer(
         text_target=lowerCAmelCase	,							max_length=32	,							padding="""max_length"""	,							truncation=lowerCAmelCase	,							return_tensors="""pt"""   )
     self.assertEqual(32	,							targets["""input_ids"""].shape[1]   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Union[str, Any]   )							->     Optional[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Dict    =						self.get_tokenizers()
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           self.assertNotEqual(tokenizer.model_max_length	,							42   )

        # Now let's start the test
     __lowerCAmelCase  :      Dict    =						self.get_tokenizers()
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           # Isolate this from the other tests because we save additional tokens/etc
           __lowerCAmelCase  :      List[Any]    =						tempfile.mkdtemp()

           __lowerCAmelCase  :      List[Any]    =						""" He is very happy, UNwant\u00E9d,running"""
           __lowerCAmelCase  :      Dict    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           tokenizer.save_pretrained(lowerCAmelCase   )

           __lowerCAmelCase  :      str    =						tokenizer.__class__.from_pretrained(lowerCAmelCase   )
           __lowerCAmelCase  :      int    =						after_tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           self.assertListEqual(lowerCAmelCase	,							lowerCAmelCase   )

           shutil.rmtree(lowerCAmelCase   )

     __lowerCAmelCase  :      str    =						self.get_tokenizers(model_max_length=42   )
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           # Isolate this from the other tests because we save additional tokens/etc
           __lowerCAmelCase  :      List[Any]    =						tempfile.mkdtemp()

           __lowerCAmelCase  :      List[Any]    =						""" He is very happy, UNwant\u00E9d,running"""

           __lowerCAmelCase  :      Union[str, Any]    =						tokenizer.additional_special_tokens

           # We can add a new special token for Canine as follows:
           __lowerCAmelCase  :      List[str]    =						chr(0Xe007   )
           additional_special_tokens.append(lowerCAmelCase   )
           tokenizer.add_special_tokens({"""additional_special_tokens""": additional_special_tokens}   )
           __lowerCAmelCase  :      Optional[int]    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           tokenizer.save_pretrained(lowerCAmelCase   )

           __lowerCAmelCase  :      Any    =						tokenizer.__class__.from_pretrained(lowerCAmelCase   )
           __lowerCAmelCase  :      Optional[int]    =						after_tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           self.assertListEqual(lowerCAmelCase	,							lowerCAmelCase   )
           self.assertIn(lowerCAmelCase	,							after_tokenizer.additional_special_tokens   )
           self.assertEqual(after_tokenizer.model_max_length	,							42   )

           __lowerCAmelCase  :      List[str]    =						tokenizer.__class__.from_pretrained(lowerCAmelCase	,							model_max_length=43   )
           self.assertEqual(tokenizer.model_max_length	,							43   )

           shutil.rmtree(lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     str:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[int]    =						self.get_tokenizers(do_lower_case=lowerCAmelCase   )
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           __lowerCAmelCase   ,__lowerCAmelCase  :      Tuple    =						self.get_clean_sequence(lowerCAmelCase   )

           # a special token for Canine can be defined as follows:
           __lowerCAmelCase  :      Union[str, Any]    =						0Xe005
           __lowerCAmelCase  :      str    =						chr(lowerCAmelCase   )

           tokenizer.add_special_tokens({"""cls_token""": special_token}   )
           __lowerCAmelCase  :      Optional[Any]    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           self.assertEqual(len(lowerCAmelCase   )	,							1   )

           __lowerCAmelCase  :      Optional[int]    =						tokenizer.decode(ids + encoded_special_token	,							clean_up_tokenization_spaces=lowerCAmelCase   )
           __lowerCAmelCase  :      List[str]    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )

           __lowerCAmelCase  :      Any    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           __lowerCAmelCase  :      List[Any]    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           self.assertEqual(lowerCAmelCase	,							input_encoded + special_token_id   )

           __lowerCAmelCase  :      Tuple    =						tokenizer.decode(lowerCAmelCase	,							skip_special_tokens=lowerCAmelCase   )
           self.assertTrue(special_token not in decoded   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Optional[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      int    =						self.get_tokenizers(do_lower_case=lowerCAmelCase   )
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           __lowerCAmelCase  :      Optional[Any]    =						chr(0Xe005   )
           __lowerCAmelCase  :      Tuple    =						chr(0Xe006   )

           # `add_tokens` method stores special tokens only in `tokenizer.unique_no_split_tokens`. (in tokenization_utils.py)
           tokenizer.add_tokens([SPECIAL_TOKEN_1]	,							special_tokens=lowerCAmelCase   )
           # `add_special_tokens` method stores special tokens in `tokenizer.additional_special_tokens`,
           # which also occur in `tokenizer.all_special_tokens`. (in tokenization_utils_base.py)
           tokenizer.add_special_tokens({"""additional_special_tokens""": [SPECIAL_TOKEN_2]}   )

           __lowerCAmelCase  :      Union[str, Any]    =						tokenizer.tokenize(lowerCAmelCase   )
           __lowerCAmelCase  :      Optional[Any]    =						tokenizer.tokenize(lowerCAmelCase   )

           self.assertEqual(len(lowerCAmelCase   )	,							1   )
           self.assertEqual(len(lowerCAmelCase   )	,							1   )
           self.assertEqual(token_a[0]	,							lowerCAmelCase   )
           self.assertEqual(token_a[0]	,							lowerCAmelCase   )







  @require_tokenizers
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Optional[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[Any]    =						self.get_tokenizers(do_lower_case=lowerCAmelCase   )
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           # a special token for Canine can be defined as follows:
           __lowerCAmelCase  :      str    =						0Xe006
           __lowerCAmelCase  :      Union[str, Any]    =						chr(lowerCAmelCase   )

           __lowerCAmelCase  :      Tuple    =						AddedToken(lowerCAmelCase	,							lstrip=lowerCAmelCase   )
           tokenizer.add_special_tokens({"""additional_special_tokens""": [new_token]}   )

           with tempfile.TemporaryDirectory() as tmp_dir_name:
              tokenizer.save_pretrained(lowerCAmelCase   )
              tokenizer.from_pretrained(lowerCAmelCase   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Any:






     """simple docstring"""







     __lowerCAmelCase  :      str    =						[]
     if self.test_slow_tokenizer:
        tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())   )

     if self.test_rust_tokenizer:
        tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())   )

     for tokenizer_class, tokenizer_utils in tokenizer_list:
        with tempfile.TemporaryDirectory() as tmp_dir:
           tokenizer_utils.save_pretrained(lowerCAmelCase   )

           with open(os.path.join(lowerCAmelCase	,							"""special_tokens_map.json"""   )	,							encoding="""utf-8"""   ) as json_file:
              __lowerCAmelCase  :      List[Any]    =						json.load(lowerCAmelCase   )

           with open(os.path.join(lowerCAmelCase	,							"""tokenizer_config.json"""   )	,							encoding="""utf-8"""   ) as json_file:
              __lowerCAmelCase  :      Any    =						json.load(lowerCAmelCase   )

           # a special token for Canine can be defined as follows:
           __lowerCAmelCase  :      List[Any]    =						0Xe006
           __lowerCAmelCase  :      Union[str, Any]    =						chr(lowerCAmelCase   )

           __lowerCAmelCase  :      str    =						[new_token_a]
           __lowerCAmelCase  :      Optional[int]    =						[new_token_a]

           with open(os.path.join(lowerCAmelCase	,							"""special_tokens_map.json"""   )	,							"""w"""	,							encoding="""utf-8"""   ) as outfile:
              json.dump(lowerCAmelCase	,							lowerCAmelCase   )
           with open(os.path.join(lowerCAmelCase	,							"""tokenizer_config.json"""   )	,							"""w"""	,							encoding="""utf-8"""   ) as outfile:
              json.dump(lowerCAmelCase	,							lowerCAmelCase   )

           # the following checks allow us to verify that our test works as expected, i.e. that the tokenizer takes
           # into account the new value of additional_special_tokens given in the "tokenizer_config.json" and
           # "special_tokens_map.json" files
           __lowerCAmelCase  :      List[Any]    =						tokenizer_class.from_pretrained(lowerCAmelCase	,							extra_ids=0   )
           self.assertIn(lowerCAmelCase	,							tokenizer_without_change_in_init.additional_special_tokens   )
           # self.assertIn("an_additional_special_token",tokenizer_without_change_in_init.get_vocab()) # ByT5Tokenization no vocab
           self.assertEqual(
               [new_token_a]	,							tokenizer_without_change_in_init.convert_ids_to_tokens(
                   tokenizer_without_change_in_init.convert_tokens_to_ids([new_token_a]   )   )	,							)

           __lowerCAmelCase  :      List[str]    =						0Xe007
           __lowerCAmelCase  :      Optional[Any]    =						chr(lowerCAmelCase   )
           # Now we test that we can change the value of additional_special_tokens in the from_pretrained
           __lowerCAmelCase  :      Union[str, Any]    =						[AddedToken(lowerCAmelCase	,							lstrip=lowerCAmelCase   )]
           __lowerCAmelCase  :      str    =						tokenizer_class.from_pretrained(
               lowerCAmelCase	,							additional_special_tokens=lowerCAmelCase	,							extra_ids=0   )

           self.assertIn(lowerCAmelCase	,							tokenizer.additional_special_tokens   )
           # self.assertIn(new_token_2,tokenizer.get_vocab()) # ByT5Tokenization no vocab
           self.assertEqual(
               [new_token_a]	,							tokenizer.convert_ids_to_tokens(tokenizer.convert_tokens_to_ids([new_token_a]   )   )   )







  @require_tokenizers
  def 	SCREAMING_SNAKE_CASE   (      self			:   Union[str, Any]   )							->     List[str]:






     """simple docstring"""







     __lowerCAmelCase  :      str    =						self.get_tokenizers(do_lower_case=lowerCAmelCase   )
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           __lowerCAmelCase  :      List[str]    =						"""hello world"""
           if self.space_between_special_tokens:
              __lowerCAmelCase  :      Optional[Any]    =						"""[CLS] hello world [SEP]"""
           else:
              __lowerCAmelCase  :      Union[str, Any]    =						input
           __lowerCAmelCase  :      List[str]    =						tokenizer.encode(lowerCAmelCase	,							add_special_tokens=lowerCAmelCase   )
           __lowerCAmelCase  :      Optional[Any]    =						tokenizer.decode(lowerCAmelCase	,							spaces_between_special_tokens=self.space_between_special_tokens   )
           self.assertIn(lowerCAmelCase	,							[output, output.lower()]   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     Dict:






     """simple docstring"""







     __lowerCAmelCase  :      Union[str, Any]    =						self.get_tokenizers()
     for tokenizer in tokenizers:
        with self.subTest(f'''{tokenizer.__class__.__name__}'''   ):
           __lowerCAmelCase  :      int    =						[
               """bos_token""",
               """eos_token""",
               """unk_token""",
               """sep_token""",
               """pad_token""",
               """cls_token""",
               """mask_token""",
           ]

     __lowerCAmelCase  :      Optional[Any]    =						"""a"""
     __lowerCAmelCase  :      List[Any]    =						ord(lowerCAmelCase   )

     for attr in attributes_list:
        setattr(lowerCAmelCase	,							attr + """_id"""	,							lowerCAmelCase   )
        self.assertEqual(getattr(lowerCAmelCase	,							lowerCAmelCase   )	,							lowerCAmelCase   )
        self.assertEqual(getattr(lowerCAmelCase	,							attr + """_id"""   )	,							lowerCAmelCase   )

        setattr(lowerCAmelCase	,							attr + """_id"""	,							lowerCAmelCase   )
        self.assertEqual(getattr(lowerCAmelCase	,							lowerCAmelCase   )	,							lowerCAmelCase   )
        self.assertEqual(getattr(lowerCAmelCase	,							attr + """_id"""   )	,							lowerCAmelCase   )

     setattr(lowerCAmelCase	,							"""additional_special_tokens_ids"""	,							[]   )
     self.assertListEqual(getattr(lowerCAmelCase	,							"""additional_special_tokens"""   )	,							[]   )
     self.assertListEqual(getattr(lowerCAmelCase	,							"""additional_special_tokens_ids"""   )	,							[]   )

     __lowerCAmelCase  :      Union[str, Any]    =						0Xe006
     __lowerCAmelCase  :      List[str]    =						chr(lowerCAmelCase   )
     setattr(lowerCAmelCase	,							"""additional_special_tokens_ids"""	,							[additional_special_token_id]   )
     self.assertListEqual(getattr(lowerCAmelCase	,							"""additional_special_tokens"""   )	,							[additional_special_token]   )
     self.assertListEqual(getattr(lowerCAmelCase	,							"""additional_special_tokens_ids"""   )	,							[additional_special_token_id]   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     Optional[Any]:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Union[str, Any]   )							->     Tuple:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   List[Any]   )							->     List[str]:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     str:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[Any]   )							->     Optional[Any]:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Dict   )							->     Dict:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   List[str]   )							->     List[str]:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Union[str, Any]   )							->     str:






     """simple docstring"""







     pass





import importlib.util
import json
import os
import warnings
from dataclasses import dataclass, field

import torch

from ..training_args import TrainingArguments
from ..utils import cached_property, is_sagemaker_dp_enabled, logging


__UpperCAmelCase								=			logging.get_logger(__name__)





def      snake_case_				()      ->     str:
   # Get the sagemaker specific mp parameters from smp_options variable.
   __lowerCAmelCase  :      List[Any]    =						os.getenv("""SM_HP_MP_PARAMETERS""" ,       """{}"""					)
   try:
      # Parse it and check the field "partitions" is included, it is required for model parallel.
      __lowerCAmelCase  :      Any    =						json.loads(__A					)
      if "partitions" not in smp_options:
         return False
   except json.JSONDecodeError:
      return False

   # Get the sagemaker specific framework parameters from mpi_options variable.
   __lowerCAmelCase  :      Any    =						os.getenv("""SM_FRAMEWORK_PARAMS""" ,       """{}"""					)
   try:
      # Parse it and check the field "sagemaker_distributed_dataparallel_enabled".
      __lowerCAmelCase  :      Union[str, Any]    =						json.loads(__A					)
      if not mpi_options.get("""sagemaker_mpi_enabled""" ,       __A					):
         return False
   except json.JSONDecodeError:
      return False
   # Lastly, check if the `smdistributed` module is present.
   return importlib.util.find_spec("""smdistributed"""					) is not None


if is_sagemaker_model_parallel_available():
   import smdistributed.modelparallel.torch as smp

   smp.init()



@dataclass
class SCREAMING_SNAKE_CASE     (  a_			):
  """simple docstring"""






  lowerCamelCase   :      str										=field(
      default=""       ,							metadata={"help": "Used by the SageMaker launcher to send mp-specific args. Ignored in SageMakerTrainer"}       ,							)







  def 	SCREAMING_SNAKE_CASE   (      self			:   List[Any]   )							->     Optional[int]:






     """simple docstring"""







     super().__post_init__()
     warnings.warn(
         """`SageMakerTrainingArguments` is deprecated and will be removed in v5 of Transformers. You can use """
         """`TrainingArguments` instead."""	,							lowerCAmelCase	,							)







  @cached_property
  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     "torch.device":






     """simple docstring"""







     logger.info("""PyTorch: setting up devices"""   )
     if torch.distributed.is_available() and torch.distributed.is_initialized() and self.local_rank == -1:
        logger.warning(
            """torch.distributed process group is initialized, but local_rank == -1. """
            """In order to use Torch DDP, launch your script with `python -m torch.distributed.launch"""   )
     if self.no_cuda:
        __lowerCAmelCase  :      Optional[Any]    =						torch.device("""cpu"""   )
        __lowerCAmelCase  :      Union[str, Any]    =						0
     elif is_sagemaker_model_parallel_available():
        __lowerCAmelCase  :      int    =						smp.local_rank()
        __lowerCAmelCase  :      str    =						torch.device("""cuda"""	,							lowerCAmelCase   )
        __lowerCAmelCase  :      Tuple    =						1
     elif is_sagemaker_dp_enabled():
        import smdistributed.dataparallel.torch.torch_smddp  # noqa: F401

        torch.distributed.init_process_group(backend="""smddp"""	,							timeout=self.ddp_timeout_delta   )
        __lowerCAmelCase  :      List[str]    =						int(os.getenv("""SMDATAPARALLEL_LOCAL_RANK"""   )   )
        __lowerCAmelCase  :      Tuple    =						torch.device("""cuda"""	,							self.local_rank   )
        __lowerCAmelCase  :      Optional[int]    =						1
     elif self.local_rank == -1:
        # if n_gpu is > 1 we'll use nn.DataParallel.
        # If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
        # Explicitly set CUDA to the first (index 0) CUDA device, otherwise `set_device` will
        # trigger an error that a device index is missing. Index 0 takes into account the
        # GPUs available in the environment, so `CUDA_VISIBLE_DEVICES=1,2` with `cuda:0`
        # will use the first GPU in that env, i.e. GPU#1
        __lowerCAmelCase  :      List[Any]    =						torch.device("""cuda:0""" if torch.cuda.is_available() else """cpu"""   )
        # Sometimes the line in the postinit has not been run before we end up here, so just checking we're not at
        # the default value.
        __lowerCAmelCase  :      Optional[int]    =						torch.cuda.device_count()
     else:
        # Here, we'll use torch.distributed.
        # Initializes the distributed backend which will take care of synchronizing nodes/GPUs
        if not torch.distributed.is_initialized():
           torch.distributed.init_process_group(backend="""nccl"""	,							timeout=self.ddp_timeout_delta   )
        __lowerCAmelCase  :      List[str]    =						torch.device("""cuda"""	,							self.local_rank   )
        __lowerCAmelCase  :      int    =						1

     if device.type == "cuda":
        torch.cuda.set_device(lowerCAmelCase   )

     return device







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     Any:






     """simple docstring"""







     if is_sagemaker_model_parallel_available():
        return smp.dp_size()

     return super().world_size







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Tuple:






     """simple docstring"""







     return not is_sagemaker_model_parallel_available()







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     Tuple:






     """simple docstring"""







     return False


