
"""simple docstring"""


import time
import warnings
from abc import ABC
from copy import deepcopy
from typing import Optional

import torch

from ..utils import add_start_docstrings, logging


A_    							=					logging.get_logger(__name__)


A_    							=					R"""
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
            or scores for each vocabulary token after SoftMax.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional stopping criteria specific kwargs.

    Return:
        `bool`. `False` indicates we should continue, `True` indicates we should stop.

"""




class  __lowerCamelCase  ( lowerCAmelCase			):




				@add_start_docstrings(UpperCAmelCase   )
				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						**UpperCAmelCase   ):
							raise NotImplementedError('''StoppingCriteria needs to be subclassed'''   )




class  __lowerCamelCase  ( lowerCAmelCase			):




				def __init__(				self							,						UpperCAmelCase							,						UpperCAmelCase = None   ):
							lowerCamelCase_					=  max_length
							lowerCamelCase_					=  max_position_embeddings





				@add_start_docstrings(UpperCAmelCase   )
				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						**UpperCAmelCase   ):
							lowerCamelCase_					=  input_ids.shape[-1]
							lowerCamelCase_					=  cur_len >= self.max_length
							if self.max_position_embeddings is not None and not is_done and cur_len >= self.max_position_embeddings:
										logger.warning_once(
										    '''This is a friendly reminder - the current text generation call will exceed the model\'s predefined '''
										    f"maximum length ({self.max_position_embeddings}). Depending on the model, you may observe "
										    '''exceptions, performance degradation, or nothing at all.'''   )
							return is_done




class  __lowerCamelCase  ( lowerCAmelCase			):




				def __init__(				self							,						UpperCAmelCase							,						UpperCAmelCase   ):
							warnings.warn(
							    '''The class `MaxNewTokensCriteria` is deprecated. '''
							    f"Please use `MaxLengthCriteria(max_length={start_length + max_new_tokens})` "
							    '''with `max_length = start_length + max_new_tokens` instead.'''							,						UpperCAmelCase							,						)
							lowerCamelCase_					=  start_length
							lowerCamelCase_					=  max_new_tokens
							lowerCamelCase_					=  start_length + max_new_tokens





				@add_start_docstrings(UpperCAmelCase   )
				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						**UpperCAmelCase   ):
							return input_ids.shape[-1] >= self.max_length




class  __lowerCamelCase  ( lowerCAmelCase			):




				def __init__(				self							,						UpperCAmelCase							,						UpperCAmelCase = None   ):
							lowerCamelCase_					=  max_time
							lowerCamelCase_					=  time.time() if initial_timestamp is None else initial_timestamp





				@add_start_docstrings(UpperCAmelCase   )
				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						**UpperCAmelCase   ):
							return time.time() - self.initial_timestamp > self.max_time




class  __lowerCamelCase  ( lowerCAmelCase			):




				@add_start_docstrings(UpperCAmelCase   )
				def __call__(				self							,						UpperCAmelCase							,						UpperCAmelCase							,						**UpperCAmelCase   ):
							return any(criteria(UpperCAmelCase							,						UpperCAmelCase   ) for criteria in self   )





				@property
				def        UpperCAmelCase__						(				self   ):
							for stopping_criterium in self:
										if isinstance(UpperCAmelCase							,						UpperCAmelCase   ):
													return stopping_criterium.max_length
										elif isinstance(UpperCAmelCase							,						UpperCAmelCase   ):
													return stopping_criterium.max_length
							return None






def  lowercase						(	lowerCAmelCase__	,lowerCAmelCase__						):
			lowerCamelCase_					=  stopping_criteria.max_length
			lowerCamelCase_					=  deepcopy(lowerCAmelCase__						)
			if stopping_max_length is not None and stopping_max_length != max_length:
						warnings.warn('''You set different `max_length` for stopping criteria and `max_length` parameter'''	,lowerCAmelCase__						)
			elif stopping_max_length is None:
						new_stopping_criteria.append(MaxLengthCriteria(max_length=lowerCAmelCase__						)						)
			return new_stopping_criteria





"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A_    							=					{
    """configuration_nllb_moe""": [
        """NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """NllbMoeConfig""",
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_    							=					[
						    """NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """NllbMoeForConditionalGeneration""",
						    """NllbMoeModel""",
						    """NllbMoePreTrainedModel""",
						    """NllbMoeTop2Router""",
						    """NllbMoeSparseMLP""",
						]


if TYPE_CHECKING:
						from .configuration_nllb_moe import (
						    NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    NllbMoeConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_nllb_moe import (
												    NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST,
												    NllbMoeForConditionalGeneration,
												    NllbMoeModel,
												    NllbMoePreTrainedModel,
												    NllbMoeSparseMLP,
												    NllbMoeTopaRouter,
												)


else:
						import sys

						A_    							=					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



