



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






	"""simple docstring"""


	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			Tuple:
							# 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_=       [[1, 2, 4], [1, 2, 3, 4]]
							UpperCAmelCase_=       DisjunctiveConstraint(__UpperCAmelCase					)
							self.assertTrue(isinstance(dc.token_ids						,  __UpperCAmelCase					)					)

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

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




	def   _SCREAMING_SNAKE_CASE		(     self     :						int					)      ->			List[str]:
							# 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_=       [[1, 2], [1, 2, 3, 4]]

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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]					)      ->			Tuple:
							UpperCAmelCase_=       [[1, 2, 3], [1, 2, 4]]

							UpperCAmelCase_=       DisjunctiveConstraint(__UpperCAmelCase					)

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

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

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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Any					)      ->			Optional[int]:
							UpperCAmelCase_=       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

							UpperCAmelCase_=       DisjunctiveConstraint(__UpperCAmelCase					)

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

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

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

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

							dc.reset()

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

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

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





from typing import TYPE_CHECKING

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


__A       =						{
    '''configuration_clip''': [
        '''CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPConfig''',
        '''CLIPOnnxConfig''',
        '''CLIPTextConfig''',
        '''CLIPVisionConfig''',
    ],
    '''processing_clip''': ['''CLIPProcessor'''],
    '''tokenization_clip''': ['''CLIPTokenizer'''],
}

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

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A       =						['''CLIPFeatureExtractor''']
	__A       =						['''CLIPImageProcessor''']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A       =						[
	    '''CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''CLIPModel''',
	    '''CLIPPreTrainedModel''',
	    '''CLIPTextModel''',
	    '''CLIPTextModelWithProjection''',
	    '''CLIPVisionModel''',
	    '''CLIPVisionModelWithProjection''',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A       =						[
	    '''TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFCLIPModel''',
	    '''TFCLIPPreTrainedModel''',
	    '''TFCLIPTextModel''',
	    '''TFCLIPVisionModel''',
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__A       =						[
	    '''FlaxCLIPModel''',
	    '''FlaxCLIPPreTrainedModel''',
	    '''FlaxCLIPTextModel''',
	    '''FlaxCLIPTextPreTrainedModel''',
	    '''FlaxCLIPVisionModel''',
	    '''FlaxCLIPVisionPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_clip import (
	    CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    CLIPConfig,
	    CLIPOnnxConfig,
	    CLIPTextConfig,
	    CLIPVisionConfig,
	)
	from .processing_clip import CLIPProcessor
	from .tokenization_clip import CLIPTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_clip_fast import CLIPTokenizerFast

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_clip import CLIPFeatureExtractor
		from .image_processing_clip import CLIPImageProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_clip import (
		    CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    CLIPModel,
		    CLIPPreTrainedModel,
		    CLIPTextModel,
		    CLIPTextModelWithProjection,
		    CLIPVisionModel,
		    CLIPVisionModelWithProjection,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_clip import (
		    TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFCLIPModel,
		    TFCLIPPreTrainedModel,
		    TFCLIPTextModel,
		    TFCLIPVisionModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_clip import (
		    FlaxCLIPModel,
		    FlaxCLIPPreTrainedModel,
		    FlaxCLIPTextModel,
		    FlaxCLIPTextPreTrainedModel,
		    FlaxCLIPVisionModel,
		    FlaxCLIPVisionPreTrainedModel,
		)


else:
	import sys

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




