



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 ):

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

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

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

						UpperCAmelCase_:						int					=			DisjunctiveConstraint(_UpperCamelCase )

						UpperCAmelCase_	,				UpperCAmelCase_	,				UpperCAmelCase_:						Union[str, Any]					=			dc.update(1 )
						UpperCAmelCase_:						List[str]					=			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_:						List[Any]					=			dc.update(2 )
						UpperCAmelCase_:						Dict					=			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_:						List[Any]					=			dc.update(3 )
						UpperCAmelCase_:						Optional[int]					=			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 			__snake_case    (self )    ->					List[str]:
						UpperCAmelCase_:						str					=			[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

						UpperCAmelCase_:						List[Any]					=			DisjunctiveConstraint(_UpperCamelCase )

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

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

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

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

						dc.reset()

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

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

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








from argparse import ArgumentParser

from .add_new_model import AddNewModelCommand
from .add_new_model_like import AddNewModelLikeCommand
from .convert import ConvertCommand
from .download import DownloadCommand
from .env import EnvironmentCommand
from .lfs import LfsCommands
from .pt_to_tf import PTtoTFCommand
from .run import RunCommand
from .serving import ServeCommand
from .user import UserCommands






def    lowerCamelCase__				(				):




			"""simple docstring"""


			lowerCAmelCase_						=	ArgumentParser("Transformers CLI tool"    ,							usage="transformers-cli <command> [<args>]"				)
			lowerCAmelCase_						=	parser.add_subparsers(help="transformers-cli command helpers"				)

			# Register commands
			ConvertCommand.register_subcommand(__lowerCAmelCase				)
			DownloadCommand.register_subcommand(__lowerCAmelCase				)
			EnvironmentCommand.register_subcommand(__lowerCAmelCase				)
			RunCommand.register_subcommand(__lowerCAmelCase				)
			ServeCommand.register_subcommand(__lowerCAmelCase				)
			UserCommands.register_subcommand(__lowerCAmelCase				)
			AddNewModelCommand.register_subcommand(__lowerCAmelCase				)
			AddNewModelLikeCommand.register_subcommand(__lowerCAmelCase				)
			LfsCommands.register_subcommand(__lowerCAmelCase				)
			PTtoTFCommand.register_subcommand(__lowerCAmelCase				)

			# Let's go
			lowerCAmelCase_						=	parser.parse_args()

			if not hasattr(__lowerCAmelCase    ,							"func"				):
						parser.print_help()
						exit(1				)

			# Run
			lowerCAmelCase_						=	args.func(__lowerCAmelCase				)
			service.run()


if __name__ == "__main__":
			main()



