

from typing import Optional, Union

from ...file_utils import TensorType
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, TruncationStrategy







class 							a__							( UpperCAmelCase							):







  """simple docstring"""




  UpperCAmelCase__   :			Optional[Any]      							="""MarkupLMFeatureExtractor"""
  UpperCAmelCase__   :			Dict      							=("""MarkupLMTokenizer""", """MarkupLMTokenizerFast""")
  UpperCAmelCase__   :			Optional[int]      							=True


  def __call__(      self     :			Optional[int]					,					UpperCAmelCase__     :			Union[str, Any]=None					,					UpperCAmelCase__     :			Dict=None					,					UpperCAmelCase__     :			int=None					,					UpperCAmelCase__     :			str=None					,					UpperCAmelCase__     :			int=None					,					UpperCAmelCase__     :			bool = True					,					UpperCAmelCase__     :			Union[bool, str, PaddingStrategy] = False					,					UpperCAmelCase__     :			Union[bool, str, TruncationStrategy] = None					,					UpperCAmelCase__     :			Optional[int] = None					,					UpperCAmelCase__     :			int = 0					,					UpperCAmelCase__     :			Optional[int] = None					,					UpperCAmelCase__     :			Optional[bool] = None					,					UpperCAmelCase__     :			Optional[bool] = None					,					UpperCAmelCase__     :			bool = False					,					UpperCAmelCase__     :			bool = False					,					UpperCAmelCase__     :			bool = False					,					UpperCAmelCase__     :			bool = False					,					UpperCAmelCase__     :			bool = True					,					UpperCAmelCase__     :			Optional[Union[str, TensorType]] = None					,					**UpperCAmelCase__     :			Any					,					)       ->BatchEncoding:
        """simple docstring"""







        if self.parse_html:
              if html_strings is None:
                    raise ValueError("""Make sure to pass HTML strings in case `parse_html` is set to `True`"""		)

              if nodes is not None or xpaths is not None or node_labels is not None:
                    raise ValueError(
                        """Please don't pass nodes, xpaths nor node labels in case `parse_html` is set to `True`"""		)

              SCREAMING_SNAKE_CASE			:   Union[str, Any]	  = self.feature_extractor(UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE			:   List[str]	  = features["""nodes"""]
              SCREAMING_SNAKE_CASE			:   Tuple	  = features["""xpaths"""]
        else:
              if html_strings is not None:
                    raise ValueError("""You have passed HTML strings but `parse_html` is set to `False`."""		)
              if nodes is None or xpaths is None:
                    raise ValueError("""Make sure to pass nodes and xpaths in case `parse_html` is set to `False`"""		)

        # # second, apply the tokenizer
        if questions is not None and self.parse_html:
              if isinstance(UpperCAmelCase__					,					UpperCAmelCase__		):
                    SCREAMING_SNAKE_CASE			:   Any	  = [questions]  # add batch dimension (as the feature extractor always adds a batch dimension)

        SCREAMING_SNAKE_CASE			:   Union[str, Any]	  = self.tokenizer(
            text=questions if questions is not None else nodes					,					text_pair=nodes if questions is not None else None					,					xpaths=UpperCAmelCase__					,					node_labels=UpperCAmelCase__					,					add_special_tokens=UpperCAmelCase__					,					padding=UpperCAmelCase__					,					truncation=UpperCAmelCase__					,					max_length=UpperCAmelCase__					,					stride=UpperCAmelCase__					,					pad_to_multiple_of=UpperCAmelCase__					,					return_token_type_ids=UpperCAmelCase__					,					return_attention_mask=UpperCAmelCase__					,					return_overflowing_tokens=UpperCAmelCase__					,					return_special_tokens_mask=UpperCAmelCase__					,					return_offsets_mapping=UpperCAmelCase__					,					return_length=UpperCAmelCase__					,					verbose=UpperCAmelCase__					,					return_tensors=UpperCAmelCase__					,					**UpperCAmelCase__					,					)

        return encoded_inputs


  def 			_lowercase   (      self     :			Any					,					*UpperCAmelCase__     :			List[str]					,					**UpperCAmelCase__     :			Union[str, Any]		)       ->Optional[Any]:
        """simple docstring"""







        return self.tokenizer.batch_decode(*UpperCAmelCase__					,					**UpperCAmelCase__		)


  def 			_lowercase   (      self     :			Optional[int]					,					*UpperCAmelCase__     :			Any					,					**UpperCAmelCase__     :			Union[str, Any]		)       ->List[Any]:
        """simple docstring"""







        return self.tokenizer.decode(*UpperCAmelCase__					,					**UpperCAmelCase__		)




  @property
  def 			_lowercase   (      self     :			int		)       ->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   Tuple	  = self.tokenizer.model_input_names
        return tokenizer_input_names







from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
  import torch

UpperCAmelCase__			:  int					     =     logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
  from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):






  def        __lowercase   (  cls      )  ->    Any:
        return cls






def        __lowercase   (  _A    ,     _A = None    ,     _A = None    ,     _A = None    ,     _A = None    ,     )  ->    Tuple:
      SCREAMING_SNAKE_CASE			:   Optional[Any]	  = device
      SCREAMING_SNAKE_CASE			:   Tuple	  = shape[0]

      SCREAMING_SNAKE_CASE			:   Optional[int]	  = layout or torch.strided
      SCREAMING_SNAKE_CASE			:   Dict	  = device or torch.device("""cpu"""      )

      if generator is not None:
            SCREAMING_SNAKE_CASE			:   Optional[Any]	  = generator.device.type if not isinstance(_A    ,     _A      ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  SCREAMING_SNAKE_CASE			:   Tuple	  = """cpu"""
                  if device != "mps":
                        logger.info(
                            F"The passed generator was created on 'cpu' even though a tensor on {device} was expected."
                            F" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"
                            F" slighly speed up this function by passing a generator that was created on the {device} device."      )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(F"Cannot generate a {device} tensor from a generator of type {gen_device_type}."      )

      if isinstance(_A    ,     _A      ):
            SCREAMING_SNAKE_CASE			:   int	  = (1,) + shape[1:]
            SCREAMING_SNAKE_CASE			:   Any	  = [
                torch.randn(_A    ,     generator=generator[i]    ,     device=_A    ,     dtype=_A    ,     layout=_A      )
                for i in range(_A      )
            ]
            SCREAMING_SNAKE_CASE			:   Any	  = torch.cat(_A    ,     dim=0      ).to(_A      )
      else:
            SCREAMING_SNAKE_CASE			:   int	  = torch.randn(_A    ,     generator=_A    ,     device=_A    ,     dtype=_A    ,     layout=_A      ).to(_A      )

      return latents







def        __lowercase   (  _A      )  ->    Dict:
      if is_torch_version("""<"""    ,     """2.0.0"""      ) or not hasattr(_A    ,     """_dynamo"""      ):
            return False
      return isinstance(_A    ,     torch._dynamo.eval_frame.OptimizedModule      )




