


'''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 					_snake_case  (self		):
										# For consistency across different places the DisjunctiveConstraint is called,
										# dc.token_ids is a list of integers. It is also initialized only by integers.

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

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

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




				def 					_snake_case  (self		):
										# 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).
										__lowerCAmelCase							       =				[[1, 2], [1, 2, 3, 4]]

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




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				[[1, 2, 3], [1, 2, 4]]

										__lowerCAmelCase							       =				DisjunctiveConstraint(__lowercase		)

										__lowerCAmelCase       ,					__lowerCAmelCase       ,					__lowerCAmelCase							       =				dc.update(1		)
										__lowerCAmelCase							       =				stepped is True and completed is False and reset is False
										self.assertTrue(__lowercase		)
										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(__lowercase		)
										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(__lowercase		)
										self.assertTrue(dc.completed		)  # Completed!
										self.assertTrue(dc.current_seq == [1, 2, 3]		)




				def 					_snake_case  (self		):
										__lowerCAmelCase							       =				[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

										__lowerCAmelCase							       =				DisjunctiveConstraint(__lowercase		)

										__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]		)





'''simple docstring'''

from torch import nn

def 							__magic_name__(						lowerCamelCase):
						if act_fn in ["swish", "silu"]:
												return nn.SiLU()
						elif act_fn == "mish":
												return nn.Mish()
						elif act_fn == "gelu":
												return nn.GELU()
						else:
												raise ValueError(F"""Unsupported activation function: {act_fn}""")

