



'''simple docstring'''




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
							import torch

							from transformers.generation import DisjunctiveConstraint

@require_torch
class     UpperCamelCase_				(							unittest.TestCase    ):





	def 				_lowercase(						self					)    ->    str:
								# For consistency across different places the DisjunctiveConstraint is called,
								# dc.token_ids is a list of integers. It is also initialized only by integers.

								UpperCAmelCase  :	Optional[Any]							  =	[[1, 2, 4], [1, 2, 3, 4]]
								UpperCAmelCase  :	List[Any]							  =	DisjunctiveConstraint(A					)
								self.assertTrue(isinstance(dc.token_ids	,	A					)					)

								with self.assertRaises(A					):
															DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]					)					)

								with self.assertRaises(A					):
															DisjunctiveConstraint([torch.LongTensor([1, 2, 4]					), torch.LongTensor([1, 2, 3, 4, 5]					)]					)





	def 				_lowercase(						self					)    ->    Dict:
								# We can't have constraints that are complete subsets of another. This leads to a preverse
								# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
								# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
								# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
								# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
								UpperCAmelCase  :	List[Any]							  =	[[1, 2], [1, 2, 3, 4]]

								with self.assertRaises(A					):
															DisjunctiveConstraint(A					)  # fails here





	def 				_lowercase(						self					)    ->    Tuple:
								UpperCAmelCase  :	List[Any]							  =	[[1, 2, 3], [1, 2, 4]]

								UpperCAmelCase  :	List[Any]							  =	DisjunctiveConstraint(A					)

								UpperCAmelCase  :	List[Any]							  =	dc.update(1					)
								UpperCAmelCase  :	Optional[Any]							  =	stepped is True and completed is False and reset is False
								self.assertTrue(A					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.current_seq == [1]					)

								UpperCAmelCase  :	Optional[Any]							  =	dc.update(2					)
								UpperCAmelCase  :	List[str]							  =	stepped is True and completed is False and reset is False
								self.assertTrue(A					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.current_seq == [1, 2]					)

								UpperCAmelCase  :	Any							  =	dc.update(3					)
								UpperCAmelCase  :	str							  =	stepped is True and completed is True and reset is False
								self.assertTrue(A					)
								self.assertTrue(dc.completed					)  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 3]					)






	def 				_lowercase(						self					)    ->    Optional[Any]:
								UpperCAmelCase  :	str							  =	[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

								UpperCAmelCase  :	str							  =	DisjunctiveConstraint(A					)

								UpperCAmelCase  :	Any							  =	dc.update(1					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.current_seq == [1]					)

								UpperCAmelCase  :	Optional[int]							  =	dc.update(2					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.current_seq == [1, 2]					)

								UpperCAmelCase  :	Any							  =	dc.update(4					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.current_seq == [1, 2, 4]					)

								UpperCAmelCase  :	Tuple							  =	dc.update(5					)
								self.assertTrue(dc.completed					)  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 4, 5]					)

								dc.reset()

								UpperCAmelCase  :	Dict							  =	dc.update(1					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.remaining() == 3					)
								self.assertTrue(dc.current_seq == [1]					)

								UpperCAmelCase  :	Tuple							  =	dc.update(2					)
								self.assertTrue(not dc.completed					)
								self.assertTrue(dc.remaining() == 2					)
								self.assertTrue(dc.current_seq == [1, 2]					)

								UpperCAmelCase  :	int							  =	dc.update(5					)
								self.assertTrue(dc.completed					)  # Completed!
								self.assertTrue(dc.remaining() == 0					)
								self.assertTrue(dc.current_seq == [1, 2, 5]					)






'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


a     :    Any      						=					{
    """configuration_nezha""": ["""NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """NezhaConfig"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a     :    Any      						=					[
							    """NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """NezhaForNextSentencePrediction""",
							    """NezhaForMaskedLM""",
							    """NezhaForPreTraining""",
							    """NezhaForMultipleChoice""",
							    """NezhaForQuestionAnswering""",
							    """NezhaForSequenceClassification""",
							    """NezhaForTokenClassification""",
							    """NezhaModel""",
							    """NezhaPreTrainedModel""",
							]


if TYPE_CHECKING:
							from .configuration_nezha import NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP, NezhaConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_nezha import (
														    NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    NezhaForMaskedLM,
														    NezhaForMultipleChoice,
														    NezhaForNextSentencePrediction,
														    NezhaForPreTraining,
														    NezhaForQuestionAnswering,
														    NezhaForSequenceClassification,
														    NezhaForTokenClassification,
														    NezhaModel,
														    NezhaPreTrainedModel,
														)


else:
							import sys

							a     :    Union[str, Any]      						=					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

