


import os

from ...utils import logging
from .utils import DataProcessor, InputExample


_snake_case					=					logging.get_logger(__name__)
class      UpperCAmelCase_ ( lowercase_   ):

   '''simple docstring'''




   def __init__(		self						,    __A						,    __A=None			):






     """simple docstring"""





     lowerCamelCase			: Optional[Any]   =    language
     lowerCamelCase			: str   =    train_language






   def _snake_case   (		self						,    __A			):






     """simple docstring"""





     lowerCamelCase			: Tuple   =    self.language if self.train_language is None else self.train_language
     lowerCamelCase			: str   =    self._read_tsv(os.path.join(__UpperCamelCase						,    F"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""			)			)
     lowerCamelCase			: Optional[int]   =    []
     for i, line in enumerate(__UpperCamelCase			):
       if i == 0:
         continue
       lowerCamelCase			: int   =    F"""train-{i}"""
       lowerCamelCase			: Optional[Any]   =    line[0]
       lowerCamelCase			: Dict   =    line[1]
       lowerCamelCase			: Any   =    "contradiction" if line[2] == "contradictory" else line[2]
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training input {text_a} is not a string"""			)
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training input {text_b} is not a string"""			)
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training label {label} is not a string"""			)
       examples.append(InputExample(guid=__UpperCamelCase						,    text_a=__UpperCamelCase						,    text_b=__UpperCamelCase						,    label=__UpperCamelCase			)			)
     return examples






   def _snake_case   (		self						,    __A			):






     """simple docstring"""





     lowerCamelCase			: int   =    self._read_tsv(os.path.join(__UpperCamelCase						,    "XNLI-1.0/xnli.test.tsv"			)			)
     lowerCamelCase			: Optional[Any]   =    []
     for i, line in enumerate(__UpperCamelCase			):
       if i == 0:
         continue
       lowerCamelCase			: Optional[int]   =    line[0]
       if language != self.language:
         continue
       lowerCamelCase			: Tuple   =    F"""test-{i}"""
       lowerCamelCase			: Tuple   =    line[6]
       lowerCamelCase			: Optional[int]   =    line[7]
       lowerCamelCase			: List[Any]   =    line[1]
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training input {text_a} is not a string"""			)
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training input {text_b} is not a string"""			)
       if not isinstance(__UpperCamelCase						,    __UpperCamelCase			):
         raise ValueError(F"""Training label {label} is not a string"""			)
       examples.append(InputExample(guid=__UpperCamelCase						,    text_a=__UpperCamelCase						,    text_b=__UpperCamelCase						,    label=__UpperCamelCase			)			)
     return examples






   def _snake_case   (		self			):






     """simple docstring"""





     return ["contradiction", "entailment", "neutral"]



_snake_case					=					{
    'xnli': XnliProcessor,
}

_snake_case					=					{
    'xnli': 'classification',
}

_snake_case					=					{
    'xnli': 3,
}








import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp






def 		lowercase_(  ):


  '''simple docstring'''

  lowerCamelCase			: str   =    ArgumentParser(
      description=(
          "PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"
      )     )

  # Optional arguments for the launch helper
  parser.add_argument("--num_cores"				,						type=SCREAMING_SNAKE_CASE_				,						default=1				,						help="Number of TPU cores to use (1 or 8)."     )

  # positional
  parser.add_argument(
      "training_script"				,						type=SCREAMING_SNAKE_CASE_				,						help=(
          "The full path to the single TPU training "
          "program/script to be launched in parallel, "
          "followed by all the arguments for the "
          "training script"
      )				,						)

  # rest from the training program
  parser.add_argument("training_script_args"				,						nargs=SCREAMING_SNAKE_CASE_     )

  return parser.parse_args()






def 		lowercase_(  ):


  '''simple docstring'''

  lowerCamelCase			: Optional[Any]   =    parse_args()

  # Import training_script as a module.
  lowerCamelCase			: Tuple   =    Path(args.training_script     )
  sys.path.append(str(script_fpath.parent.resolve()     )     )
  lowerCamelCase			: int   =    script_fpath.stem
  lowerCamelCase			: Tuple   =    importlib.import_module(SCREAMING_SNAKE_CASE_     )

  # Patch sys.argv
  lowerCamelCase			: Union[str, Any]   =    [args.training_script] + args.training_script_args + ["--tpu_num_cores", str(args.num_cores     )]

  xmp.spawn(mod._mp_fn				,						args=()				,						nprocs=args.num_cores     )


if __name__ == "__main__":
   main()



