


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 	snake_case_       (unittest.TestCase				):
					def 			lowerCamelCase__(				self       :List[str]				) ->   Optional[Any]:
												# For consistency across different places the DisjunctiveConstraint is called,
												# dc.token_ids is a list of integers. It is also initialized only by integers.

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

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

												with self.assertRaises(__snake_case				):
																			DisjunctiveConstraint([torch.LongTensor([1, 2, 4]				), torch.LongTensor([1, 2, 3, 4, 5]				)]				)
					def 			lowerCamelCase__(				self       :int				) ->   int:
												# 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).
												a__					=					[[1, 2], [1, 2, 3, 4]]

												with self.assertRaises(__snake_case				):
																			DisjunctiveConstraint(__snake_case				)  # fails here
					def 			lowerCamelCase__(				self       :Optional[Any]				) ->   int:
												a__					=					[[1, 2, 3], [1, 2, 4]]

												a__					=					DisjunctiveConstraint(__snake_case				)

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

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

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



					def 			lowerCamelCase__(				self       :Any				) ->   str:
												a__					=					[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

												a__					=					DisjunctiveConstraint(__snake_case				)

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

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

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

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

												dc.reset()

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

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

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








from typing import List

from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case							:	Tuple					      =				logging.get_logger(__name__)

snake_case							:	List[Any]					      =				{
    '''snap-research/efficientformer-l1-300''': (
        '''https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json'''
    ),
}







class 	snake_case_       (lowerCamelCase_				):
					UpperCAmelCase__ :   int   				=      '''efficientformer'''
					def __init__(				self       :List[str]      ,__snake_case       :List[int] = [3, 2, 6, 4]      ,__snake_case       :List[int] = [48, 96, 2_24, 4_48]      ,__snake_case       :List[bool] = [True, True, True, True]      ,__snake_case       :int = 4_48      ,__snake_case       :int = 32      ,__snake_case       :int = 4      ,__snake_case       :int = 7      ,__snake_case       :int = 5      ,__snake_case       :int = 8      ,__snake_case       :int = 4      ,__snake_case       :float = 0.0      ,__snake_case       :int = 16      ,__snake_case       :int = 3      ,__snake_case       :int = 3      ,__snake_case       :int = 3      ,__snake_case       :int = 2      ,__snake_case       :int = 1      ,__snake_case       :float = 0.0      ,__snake_case       :int = 1      ,__snake_case       :bool = True      ,__snake_case       :bool = True      ,__snake_case       :float = 1E-5      ,__snake_case       :str = "gelu"      ,__snake_case       :float = 0.02      ,__snake_case       :float = 1E-12      ,__snake_case       :int = 2_24      ,__snake_case       :float = 1E-05      ,**__snake_case       :Dict      ,) ->   None:
												super().__init__(**__snake_case				)

												a__					=					hidden_act
												a__					=					hidden_dropout_prob
												a__					=					hidden_sizes
												a__					=					num_hidden_layers
												a__					=					num_attention_heads
												a__					=					initializer_range
												a__					=					layer_norm_eps
												a__					=					patch_size
												a__					=					num_channels
												a__					=					depths
												a__					=					mlp_expansion_ratio
												a__					=					downsamples
												a__					=					dim
												a__					=					key_dim
												a__					=					attention_ratio
												a__					=					resolution
												a__					=					pool_size
												a__					=					downsample_patch_size
												a__					=					downsample_stride
												a__					=					downsample_pad
												a__					=					drop_path_rate
												a__					=					num_metaad_blocks
												a__					=					distillation
												a__					=					use_layer_scale
												a__					=					layer_scale_init_value
												a__					=					image_size
												a__					=					batch_norm_eps




