'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__lowercase        =    {
    '''configuration_convbert''': ['''CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ConvBertConfig''', '''ConvBertOnnxConfig'''],
    '''tokenization_convbert''': ['''ConvBertTokenizer'''],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase        =    ['''ConvBertTokenizerFast''']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase        =    [
						    '''CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''ConvBertForMaskedLM''',
						    '''ConvBertForMultipleChoice''',
						    '''ConvBertForQuestionAnswering''',
						    '''ConvBertForSequenceClassification''',
						    '''ConvBertForTokenClassification''',
						    '''ConvBertLayer''',
						    '''ConvBertModel''',
						    '''ConvBertPreTrainedModel''',
						    '''load_tf_weights_in_convbert''',
						]


try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__lowercase        =    [
						    '''TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TFConvBertForMaskedLM''',
						    '''TFConvBertForMultipleChoice''',
						    '''TFConvBertForQuestionAnswering''',
						    '''TFConvBertForSequenceClassification''',
						    '''TFConvBertForTokenClassification''',
						    '''TFConvBertLayer''',
						    '''TFConvBertModel''',
						    '''TFConvBertPreTrainedModel''',
						]


if TYPE_CHECKING:
						from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
						from .tokenization_convbert import ConvBertTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_convbert_fast import ConvBertTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_convbert import (
												    CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    ConvBertForMaskedLM,
												    ConvBertForMultipleChoice,
												    ConvBertForQuestionAnswering,
												    ConvBertForSequenceClassification,
												    ConvBertForTokenClassification,
												    ConvBertLayer,
												    ConvBertModel,
												    ConvBertPreTrainedModel,
												    load_tf_weights_in_convbert,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_convbert import (
												    TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFConvBertForMaskedLM,
												    TFConvBertForMultipleChoice,
												    TFConvBertForQuestionAnswering,
												    TFConvBertForSequenceClassification,
												    TFConvBertForTokenClassification,
												    TFConvBertLayer,
												    TFConvBertModel,
												    TFConvBertPreTrainedModel,
												)


else:
						import sys

						__lowercase        =    _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





'''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 							a__(   unittest.TestCase      ):


			'''simple docstring'''






			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    [[1, 2, 4], [1, 2, 3, 4]]
					lowerCAmelCase     =    DisjunctiveConstraint(__lowerCAmelCase)
					self.assertTrue(isinstance(dc.token_ids			,       __lowerCAmelCase))

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

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



			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    [[1, 2], [1, 2, 3, 4]]

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



			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    [[1, 2, 3], [1, 2, 4]]

					lowerCAmelCase     =    DisjunctiveConstraint(__lowerCAmelCase)

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(1)
					lowerCAmelCase     =    stepped is True and completed is False and reset is False
					self.assertTrue(__lowerCAmelCase)
					self.assertTrue(not dc.completed)
					self.assertTrue(dc.current_seq == [1])

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(2)
					lowerCAmelCase     =    stepped is True and completed is False and reset is False
					self.assertTrue(__lowerCAmelCase)
					self.assertTrue(not dc.completed)
					self.assertTrue(dc.current_seq == [1, 2])

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(3)
					lowerCAmelCase     =    stepped is True and completed is True and reset is False
					self.assertTrue(__lowerCAmelCase)
					self.assertTrue(dc.completed)  # Completed!
					self.assertTrue(dc.current_seq == [1, 2, 3])







			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

					lowerCAmelCase     =    DisjunctiveConstraint(__lowerCAmelCase)

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(1)
					self.assertTrue(not dc.completed)
					self.assertTrue(dc.current_seq == [1])

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(2)
					self.assertTrue(not dc.completed)
					self.assertTrue(dc.current_seq == [1, 2])

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

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

					dc.reset()

					lowerCAmelCase   ,	lowerCAmelCase   ,	lowerCAmelCase     =    dc.update(1)
					self.assertTrue(not dc.completed)
					self.assertTrue(dc.remaining() == 3)
					self.assertTrue(dc.current_seq == [1])

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

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




