





"""simple docstring"""




import dataclasses
import json
import sys
import types
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError
from copy import copy
from enum import Enum
from inspect import isclass
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, List, Literal, NewType, Optional, Tuple, Union, get_type_hints

import yaml


lowerCamelCase_     :						Dict						=					NewType('DataClass', Any)
lowerCamelCase_     :						Any						=					NewType('DataClassType', Any)





def 						UpperCAmelCase__		(     _UpperCAmelCase					):






  """simple docstring"""





  if isinstance(_UpperCAmelCase ,					_UpperCAmelCase					):
    return v
  if v.lower() in ("yes", "true", "t", "y", "1"):
    return True
  elif v.lower() in ("no", "false", "f", "n", "0"):
    return False
  else:
    raise ArgumentTypeError(
        f"""Truthy value expected: got {v} but expected one of yes/no, true/false, t/f, y/n, 1/0 (case insensitive)."""					)





def 						UpperCAmelCase__		(     _UpperCAmelCase					):






  """simple docstring"""





  A_  :       Tuple										=  {str(_UpperCAmelCase					): choice for choice in choices}
  return lambda _UpperCAmelCase					: str_to_choice.get(_UpperCAmelCase ,					_UpperCAmelCase					)





def 						UpperCAmelCase__		(     *,
    _UpperCAmelCase = None ,					_UpperCAmelCase = None ,					_UpperCAmelCase = dataclasses.MISSING ,					_UpperCAmelCase = dataclasses.MISSING ,					_UpperCAmelCase = None ,					**_UpperCAmelCase ,					):






  """simple docstring"""





  if metadata is None:
    # Important, don't use as default param in function signature because dict is mutable and shared across function calls
    A_  :       Optional[Any]										=  {}
  if aliases is not None:
    A_  :       Tuple										=  aliases
  if help is not None:
    A_  :       List[Any]										=  help

  return dataclasses.field(metadata=_UpperCAmelCase ,					default=_UpperCAmelCase ,					default_factory=_UpperCAmelCase ,					**_UpperCAmelCase					)





class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_      : Iterable[DataClassType]

      def __init__(     self					,      snake_case_					,      **snake_case_  ):

        """simple docstring"""

        if "formatter_class" not in kwargs:
          A_  :       Union[str, Any]										=  ArgumentDefaultsHelpFormatter
        super().__init__(**snake_case_  )
        if dataclasses.is_dataclass(snake_case_  ):
          A_  :       List[str]										=  [dataclass_types]
        A_  :       Any										=  list(snake_case_  )
        for dtype in self.dataclass_types:
          self._add_dataclass_arguments(snake_case_  )

      @staticmethod
      def 					lowerCamelCase_			(     snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       List[Any]										=  F"""--{field.name}"""
        A_  :       Optional[int]										=  field.metadata.copy()
        # field.metadata is not used at all by Data Classes,
        # it is provided as a third-party extension mechanism.
        if isinstance(field.type					,      snake_case_  ):
          raise RuntimeError(
              'Unresolved type detected, which should have been done with the help of '
              '`typing.get_type_hints` method by default'  )

        A_  :       int										=  kwargs.pop('aliases'					,      []  )
        if isinstance(snake_case_					,      snake_case_  ):
          A_  :       List[str]										=  [aliases]

        A_  :       List[str]										=  getattr(field.type					,      '__origin__'					,      field.type  )
        if origin_type is Union or (hasattr(snake_case_					,      'UnionType'  ) and isinstance(snake_case_					,      types.UnionType  )):
          if str not in field.type.__args__ and (
              len(field.type.__args__  ) != 2 or type(snake_case_  ) not in field.type.__args__
          ):
            raise ValueError(
                'Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union` because'
                ' the argument parser only supports one type per argument.'
                F""" Problem encountered in field '{field.name}'."""  )
          if type(snake_case_  ) not in field.type.__args__:
            # filter `str` in Union
            A_  :       Optional[int]										=  field.type.__args__[0] if field.type.__args__[1] == str else field.type.__args__[1]
            A_  :       List[Any]										=  getattr(field.type					,      '__origin__'					,      field.type  )
          elif bool not in field.type.__args__:
            # filter `NoneType` in Union (except for `Union[bool, NoneType]`)
            A_  :       int										=  (
                field.type.__args__[0] if isinstance(snake_case_					,      field.type.__args__[1]  ) else field.type.__args__[1]
            )
            A_  :       Optional[int]										=  getattr(field.type					,      '__origin__'					,      field.type  )

        # A variable to store kwargs for a boolean field, if needed
        # so that we can init a `no_*` complement argument (see below)
        A_  :       Union[str, Any]										=  {}
        if origin_type is Literal or (isinstance(field.type					,      snake_case_  ) and issubclass(field.type					,      snake_case_  )):
          if origin_type is Literal:
            A_  :       Optional[int]										=  field.type.__args__
          else:
            A_  :       Optional[Any]										=  [x.value for x in field.type]

          A_  :       List[str]										=  make_choice_type_function(kwargs['choices']  )

          if field.default is not dataclasses.MISSING:
            A_  :       Tuple										=  field.default
          else:
            A_  :       Any										=  True
        elif field.type is bool or field.type == Optional[bool]:
          # Copy the currect kwargs to use to instantiate a `no_*` complement argument below.
          # We do not initialize it here because the `no_*` alternative must be instantiated after the real argument
          A_  :       Dict										=  copy(snake_case_  )

          # Hack because type=bool in argparse does not behave as we want.
          A_  :       List[Any]										=  string_to_bool
          if field.type is bool or (field.default is not None and field.default is not dataclasses.MISSING):
            # Default value is False if we have no default when of type bool.
            A_  :       Union[str, Any]										=  False if field.default is dataclasses.MISSING else field.default
            # This is the value that will get picked if we don't include --field_name in any way
            A_  :       int										=  default
            # This tells argparse we accept 0 or 1 value after --field_name
            A_  :       int										=  '?'
            # This is the value that will get picked if we do --field_name (without value)
            A_  :       Dict										=  True
        elif isclass(snake_case_  ) and issubclass(snake_case_					,      snake_case_  ):
          A_  :       int										=  field.type.__args__[0]
          A_  :       Tuple										=  '+'
          if field.default_factory is not dataclasses.MISSING:
            A_  :       Dict										=  field.default_factory()
          elif field.default is dataclasses.MISSING:
            A_  :       Dict										=  True
        else:
          A_  :       List[str]										=  field.type
          if field.default is not dataclasses.MISSING:
            A_  :       Union[str, Any]										=  field.default
          elif field.default_factory is not dataclasses.MISSING:
            A_  :       Tuple										=  field.default_factory()
          else:
            A_  :       Tuple										=  True
        parser.add_argument(snake_case_					,      *snake_case_					,      **snake_case_  )

        # Add a complement `no_*` argument for a boolean field AFTER the initial field has already been added.
        # Order is important for arguments with the same destination!
        # We use a copy of earlier kwargs because the original kwargs have changed a lot before reaching down
        # here and we do not need those changes/additional keys.
        if field.default is True and (field.type is bool or field.type == Optional[bool]):
          A_  :       List[str]										=  False
          parser.add_argument(F"""--no_{field.name}"""					,      action='store_false'					,      dest=field.name					,      **snake_case_  )

      def 					lowerCamelCase_			(     self					,      snake_case_  ):

        """simple docstring"""

        if hasattr(snake_case_					,      '_argument_group_name'  ):
          A_  :       List[str]										=  self.add_argument_group(dtype._argument_group_name  )
        else:
          A_  :       Union[str, Any]										=  self

        try:
          A_  :       Dict[str, type]										=  get_type_hints(snake_case_  )
        except NameError:
          raise RuntimeError(
              F"""Type resolution failed for {dtype}. Try declaring the class in global scope or """
              'removing line of `from __future__ import annotations` which opts in Postponed '
              'Evaluation of Annotations (PEP 563)'  )
        except TypeError as ex:
          # Remove this block when we drop Python 3.9 support
          if sys.version_info[:2] < (3, 1_0) and "unsupported operand type(s) for |" in str(snake_case_  ):
            A_  :       Optional[int]										=  '.'.join(map(snake_case_					,      sys.version_info[:3]  )  )
            raise RuntimeError(
                F"""Type resolution failed for {dtype} on Python {python_version}. Try removing """
                'line of `from __future__ import annotations` which opts in union types as '
                '`X | Y` (PEP 604) via Postponed Evaluation of Annotations (PEP 563). To '
                'support Python versions that lower than 3.10, you need to use '
                '`typing.Union[X, Y]` instead of `X | Y` and `typing.Optional[X]` instead of '
                '`X | None`.'  ) from ex
          raise

        for field in dataclasses.fields(snake_case_  ):
          if not field.init:
            continue
          A_  :       str										=  type_hints[field.name]
          self._parse_dataclass_field(snake_case_					,      snake_case_  )

      def 					lowerCamelCase_			(     self					,      snake_case_=None					,      snake_case_=False					,      snake_case_=True					,      snake_case_=None					,      snake_case_=None					,      ):

        """simple docstring"""

        if args_file_flag or args_filename or (look_for_args_file and len(sys.argv  )):
          A_  :       Dict										=  []

          if args_filename:
            args_files.append(Path(snake_case_  )  )
          elif look_for_args_file and len(sys.argv  ):
            args_files.append(Path(sys.argv[0]  ).with_suffix('.args'  )  )

          # args files specified via command line flag should overwrite default args files so we add them last
          if args_file_flag:
            # Create special parser just to extract the args_file_flag values
            A_  :       Optional[Any]										=  ArgumentParser()
            args_file_parser.add_argument(snake_case_					,      type=snake_case_					,      action='append'  )

            # Use only remaining args for further parsing (remove the args_file_flag)
            A_						,       A_  :       List[Any]										=  args_file_parser.parse_known_args(args=snake_case_  )
            A_  :       Any										=  vars(snake_case_  ).get(args_file_flag.lstrip('-'  )					,      snake_case_  )

            if cmd_args_file_paths:
              args_files.extend([Path(snake_case_  ) for p in cmd_args_file_paths]  )

          A_  :       List[Any]										=  []
          for args_file in args_files:
            if args_file.exists():
              file_args += args_file.read_text().split()

            # in case of duplicate arguments the last one has precedence
            # args specified via the command line should overwrite args from files, so we add them last
          A_  :       Tuple										=  file_args + args if args is not None else file_args + sys.argv[1:]
        A_						,       A_  :       str										=  self.parse_known_args(args=snake_case_  )
        A_  :       Optional[int]										=  []
        for dtype in self.dataclass_types:
          A_  :       int										=  {f.name for f in dataclasses.fields(snake_case_  ) if f.init}
          A_  :       List[str]										=  {k: v for k, v in vars(snake_case_  ).items() if k in keys}
          for k in keys:
            delattr(snake_case_					,      snake_case_  )
          A_  :       List[Any]										=  dtype(**snake_case_  )
          outputs.append(snake_case_  )
        if len(namespace.__dict__  ) > 0:
          # additional namespace.
          outputs.append(snake_case_  )
        if return_remaining_strings:
          return (*outputs, remaining_args)
        else:
          if remaining_args:
            raise ValueError(F"""Some specified arguments are not used by the HfArgumentParser: {remaining_args}"""  )

          return (*outputs,)

      def 					lowerCamelCase_			(     self					,      snake_case_					,      snake_case_ = False  ):

        """simple docstring"""

        A_  :       Optional[int]										=  set(args.keys()  )
        A_  :       int										=  []
        for dtype in self.dataclass_types:
          A_  :       Dict										=  {f.name for f in dataclasses.fields(snake_case_  ) if f.init}
          A_  :       int										=  {k: v for k, v in args.items() if k in keys}
          unused_keys.difference_update(inputs.keys()  )
          A_  :       Union[str, Any]										=  dtype(**snake_case_  )
          outputs.append(snake_case_  )
        if not allow_extra_keys and unused_keys:
          raise ValueError(F"""Some keys are not used by the HfArgumentParser: {sorted(snake_case_  )}"""  )
        return tuple(snake_case_  )

      def 					lowerCamelCase_			(     self					,      snake_case_					,      snake_case_ = False  ):

        """simple docstring"""

        with open(Path(snake_case_  )					,      encoding='utf-8'  ) as open_json_file:
          A_  :       Optional[Any]										=  json.loads(open_json_file.read()  )
        A_  :       List[str]										=  self.parse_dict(snake_case_					,      allow_extra_keys=snake_case_  )
        return tuple(snake_case_  )

      def 					lowerCamelCase_			(     self					,      snake_case_					,      snake_case_ = False  ):

        """simple docstring"""

        A_  :       str										=  self.parse_dict(yaml.safe_load(Path(snake_case_  ).read_text()  )					,      allow_extra_keys=snake_case_  )
        return tuple(snake_case_  )






"""simple docstring"""




import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


lowerCamelCase_     :						Dict						=					get_logger(__name__)


lowerCamelCase_     :						List[str]						=					r'\n    Args:\n        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):\n            Indices of input sequence tokens in the vocabulary.\n\n            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and\n            [`PreTrainedTokenizer.__call__`] for details.\n\n            [What are input IDs?](../glossary#input-ids)\n        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):\n            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam\n            search or log softmax for each vocabulary token when using beam search\n        kwargs (`Dict[str, Any]`, *optional*):\n            Additional logits processor specific kwargs.\n\n    Return:\n        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.\n\n'

class  _UpperCAmelCase  :



      '''simple docstring'''

      @add_start_docstrings(snake_case_  )
      def __call__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        raise NotImplementedError(
            F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""  )


class  _UpperCAmelCase  :



      '''simple docstring'''

      @add_start_docstrings(snake_case_  )
      def __call__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        raise NotImplementedError(
            F"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""  )


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      @add_start_docstrings(snake_case_  )
      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_					,      **snake_case_  ):

        """simple docstring"""

        for processor in self:
          A_  :       Tuple										=  inspect.signature(processor.__call__  ).parameters
          if len(snake_case_  ) > 3:
            if not all(arg in kwargs for arg in list(function_args.keys()  )[2:]  ):
              raise ValueError(
                  F"""Make sure that all the required parameters: {list(function_args.keys()  )} for """
                  F"""{processor.__class__} are passed to the logits processor."""  )
            A_  :       Tuple										=  processor(snake_case_					,      snake_case_					,      snake_case_					,      **snake_case_  )
          else:
            A_  :       Optional[Any]										=  processor(snake_case_					,      snake_case_					,      snake_case_  )
        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_  ):

        """simple docstring"""

        if not isinstance(snake_case_					,      snake_case_  ) or not (temperature > 0):
          raise ValueError(F"""`temperature` has to be a strictly positive float, but is {temperature}"""  )

        A_  :       Optional[int]										=  temperature

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       int										=  scores / self.temperature
        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_ = -float('Inf'  )					,      snake_case_ = 1  ):

        """simple docstring"""

        if not isinstance(snake_case_					,      snake_case_  ) or (top_p < 0 or top_p > 1.0):
          raise ValueError(F"""`top_p` has to be a float > 0 and < 1, but is {top_p}"""  )
        if not isinstance(snake_case_					,      snake_case_  ) or (min_tokens_to_keep < 1):
          raise ValueError(F"""`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}"""  )

        A_  :       str										=  top_p
        A_  :       Union[str, Any]										=  filter_value
        A_  :       int										=  min_tokens_to_keep

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_						,       A_  :       Tuple										=  lax.top_k(snake_case_					,      scores.shape[-1]  )

        A_  :       List[Any]										=  jnp.full_like(snake_case_					,      self.filter_value  )
        A_  :       List[str]										=  jax.nn.softmax(snake_case_					,      axis=-1  ).cumsum(axis=-1  )
        A_  :       Optional[int]										=  cumulative_probs < self.top_p

        # include the token that is higher than top_p as well
        A_  :       Union[str, Any]										=  jnp.roll(snake_case_					,      1  )
        score_mask |= score_mask.at[:, 0].set(snake_case_  )

        # min tokens to keep
        A_  :       int										=  score_mask.at[:, : self.min_tokens_to_keep].set(snake_case_  )

        A_  :       Optional[Any]										=  jnp.where(snake_case_					,      snake_case_					,      snake_case_  )
        A_  :       List[Any]										=  jax.lax.sort_key_val(snake_case_					,      snake_case_  )[-1]

        return next_scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_ = -float('Inf'  )					,      snake_case_ = 1  ):

        """simple docstring"""

        if not isinstance(snake_case_					,      snake_case_  ) or top_k <= 0:
          raise ValueError(F"""`top_k` has to be a strictly positive integer, but is {top_k}"""  )

        A_  :       str										=  max(snake_case_					,      snake_case_  )
        A_  :       Union[str, Any]										=  filter_value

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_						,       A_  :       int										=  scores.shape
        A_  :       Tuple										=  jnp.full(batch_size * vocab_size					,      self.filter_value  )

        A_  :       Union[str, Any]										=  min(self.top_k					,      scores.shape[-1]  )  # Safety check
        A_						,       A_  :       Dict										=  lax.top_k(snake_case_					,      snake_case_  )
        A_  :       Optional[int]										=  jnp.broadcast_to((jnp.arange(snake_case_  ) * vocab_size)[:, None]					,      (batch_size, topk)  ).flatten()
        A_  :       int										=  topk_scores.flatten()
        A_  :       Any										=  topk_indices.flatten() + shift

        A_  :       List[str]										=  next_scores_flat.at[topk_indices_flat].set(snake_case_  )
        A_  :       Union[str, Any]										=  next_scores_flat.reshape(snake_case_					,      snake_case_  )
        return next_scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       Union[str, Any]										=  bos_token_id

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Optional[Any]										=  jnp.full(scores.shape					,      -float('inf'  )  )

        A_  :       Union[str, Any]										=  1 - jnp.bool_(cur_len - 1  )

        A_  :       str										=  jnp.where(snake_case_					,      new_scores.at[:, self.bos_token_id].set(0  )					,      snake_case_  )

        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Dict										=  max_length
        A_  :       Optional[int]										=  eos_token_id

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Union[str, Any]										=  jnp.full(scores.shape					,      -float('inf'  )  )

        A_  :       Dict										=  1 - jnp.bool_(cur_len - self.max_length + 1  )

        A_  :       Dict										=  jnp.where(snake_case_					,      new_scores.at[:, self.eos_token_id].set(0  )					,      snake_case_  )

        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        if not isinstance(snake_case_					,      snake_case_  ) or min_length < 0:
          raise ValueError(F"""`min_length` has to be a positive integer, but is {min_length}"""  )

        if not isinstance(snake_case_					,      snake_case_  ) or eos_token_id < 0:
          raise ValueError(F"""`eos_token_id` has to be a positive integer, but is {eos_token_id}"""  )

        A_  :       Any										=  min_length
        A_  :       List[Any]										=  eos_token_id

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       int										=  1 - jnp.clip(cur_len - self.min_length					,      0					,      1  )

        A_  :       Optional[Any]										=  jnp.where(snake_case_					,      scores.at[:, self.eos_token_id].set(-float('inf'  )  )					,      snake_case_  )

        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       List[Any]										=  list(snake_case_  )
        A_  :       Tuple										=  begin_index

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Dict										=  1 - jnp.bool_(cur_len - self.begin_index  )

        A_  :       int										=  jnp.where(snake_case_					,      scores.at[:, self.begin_suppress_tokens].set(-float('inf'  )  )					,      snake_case_  )

        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       List[Any]										=  list(snake_case_  )

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Optional[Any]										=  scores.at[..., self.suppress_tokens].set(-float('inf'  )  )

        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       Any										=  dict(snake_case_  )
        # Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
        # index of the array corresponds to the index of the token to be forced, for XLA compatibility.
        # Indexes without forced tokens will have a negative value.
        A_  :       Tuple										=  jnp.ones((max(force_token_map.keys()  ) + 1)					,      dtype=jnp.intaa  ) * -1
        for index, token in force_token_map.items():
          if token is not None:
            A_  :       Tuple										=  force_token_array.at[index].set(snake_case_  )
        A_  :       Any										=  jnp.intaa(snake_case_  )

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        def _force_token(snake_case_  ):
          A_  :       List[Any]										=  scores.shape[0]
          A_  :       Any										=  self.force_token_array[generation_idx]

          A_  :       Tuple										=  jnp.ones_like(snake_case_					,      dtype=scores.dtype  ) * -float('inf'  )
          A_  :       List[Any]										=  jnp.zeros((batch_size, 1)					,      dtype=scores.dtype  )
          A_  :       int										=  lax.dynamic_update_slice(snake_case_					,      snake_case_					,      (0, current_token)  )
          return new_scores

        A_  :       int										=  lax.cond(
            cur_len >= self.force_token_array.shape[0]					,      lambda: scores					,      lambda: lax.cond(
                self.force_token_array[cur_len] >= 0					,      lambda: _force_token(snake_case_  )					,      lambda: scores					,      )					,      )
        return scores


class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       Tuple										=  generate_config.eos_token_id
        A_  :       Optional[int]										=  generate_config.no_timestamps_token_id
        A_  :       List[str]										=  generate_config.no_timestamps_token_id + 1

        A_  :       Any										=  decoder_input_length + 1

        if generate_config.is_multilingual:
          # room for language token and task token
          self.begin_index += 2
        if hasattr(snake_case_					,      'max_initial_timestamp_index'  ):
          A_  :       List[Any]										=  generate_config.max_initial_timestamp_index
        else:
          A_  :       Any										=  model_config.vocab_size
        if self.max_initial_timestamp_index is None:
          A_  :       Optional[Any]										=  model_config.vocab_size

      def __call__(     self					,      snake_case_					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        A_  :       List[str]										=  scores.at[:, self.no_timestamps_token_id].set(-float('inf'  )  )

        def handle_pairs(snake_case_					,      snake_case_  ):
          A_  :       Any										=  jnp.where((cur_len - self.begin_index) >= 1					,      snake_case_					,      snake_case_  )
          A_  :       Tuple										=  jnp.where(
              input_ids_k[cur_len - 1] >= self.timestamp_begin					,      True and last_was_timestamp					,      snake_case_					,      )

          A_  :       Tuple										=  jnp.where((cur_len - self.begin_index) < 2					,      snake_case_					,      snake_case_  )
          A_  :       Any										=  jnp.where(
              input_ids_k[cur_len - 2] >= self.timestamp_begin					,      snake_case_					,      snake_case_					,      )

          return jnp.where(
              snake_case_					,      jnp.where(
                  penultimate_was_timestamp > 0					,      scores_k.at[self.timestamp_begin :].set(-float('inf'  )  )					,      scores_k.at[: self.eos_token_id].set(-float('inf'  )  )					,      )					,      snake_case_					,      )

        A_  :       Tuple										=  jax.vmap(snake_case_  )(snake_case_					,      snake_case_  )

        A_  :       Optional[Any]										=  jnp.where(cur_len == self.begin_index					,      snake_case_					,      snake_case_  )
        A_  :       Tuple										=  jnp.where(
            self.max_initial_timestamp_index is not None					,      True and apply_max_initial_timestamp					,      snake_case_					,      )

        A_  :       int										=  self.timestamp_begin + self.max_initial_timestamp_index

        A_  :       List[Any]										=  jnp.where(
            snake_case_					,      scores.at[:, last_allowed + 1 :].set(-float('inf'  )  )					,      snake_case_					,      )

        # if sum of probability over timestamps is above any other token, sample timestamp
        A_  :       Any										=  jax.nn.log_softmax(snake_case_					,      axis=-1  )

        def handle_cumulative_probs(snake_case_					,      snake_case_  ):
          A_  :       Dict										=  jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]					,      axis=-1  )
          A_  :       Optional[Any]										=  jnp.max(logprobs_k[: self.timestamp_begin]  )
          return jnp.where(
              timestamp_logprob > max_text_token_logprob					,      scores_k.at[: self.timestamp_begin].set(-float('inf'  )  )					,      snake_case_					,      )

        A_  :       Union[str, Any]										=  jax.vmap(snake_case_  )(snake_case_					,      snake_case_  )

        return scores