


'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_lowercase    :    int			     =  logging.get_logger(__name__)

_lowercase    :    Union[str, Any]			     =  {
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}






class  UpperCamelCase__(     lowerCAmelCase		,       lowerCAmelCase ):
				__magic_name__       :   List[str]							= "focalnet"




				def __init__(	self    :				List[Any]   ,					lowerCAmelCase    :				Any=224   ,					lowerCAmelCase    :				Any=4   ,					lowerCAmelCase    :				Optional[int]=3   ,					lowerCAmelCase    :				str=96   ,					lowerCAmelCase    :				List[str]=False   ,					lowerCAmelCase    :				int=[192, 384, 768, 768]   ,					lowerCAmelCase    :				List[Any]=[2, 2, 6, 2]   ,					lowerCAmelCase    :				Tuple=[2, 2, 2, 2]   ,					lowerCAmelCase    :				Optional[Any]=[3, 3, 3, 3]   ,					lowerCAmelCase    :				Dict="gelu"   ,					lowerCAmelCase    :				str=4.0   ,					lowerCAmelCase    :				int=0.0   ,					lowerCAmelCase    :				Dict=0.1   ,					lowerCAmelCase    :				Optional[int]=False   ,					lowerCAmelCase    :				Optional[int]=1E-4   ,					lowerCAmelCase    :				Optional[int]=False   ,					lowerCAmelCase    :				Any=False   ,					lowerCAmelCase    :				Tuple=False   ,					lowerCAmelCase    :				Any=0.02   ,					lowerCAmelCase    :				Tuple=1E-5   ,					lowerCAmelCase    :				Dict=32   ,					lowerCAmelCase    :				Dict=None   ,					lowerCAmelCase    :				Any=None   ,					**lowerCAmelCase    :				Optional[Any]   ,					)->  Dict:

										"""simple docstring"""




										super().__init__(**lowerCAmelCase   )

										UpperCAmelCase         =			image_size
										UpperCAmelCase         =			patch_size
										UpperCAmelCase         =			num_channels
										UpperCAmelCase         =			embed_dim
										UpperCAmelCase         =			use_conv_embed
										UpperCAmelCase         =			hidden_sizes
										UpperCAmelCase         =			depths
										UpperCAmelCase         =			focal_levels
										UpperCAmelCase         =			focal_windows
										UpperCAmelCase         =			hidden_act
										UpperCAmelCase         =			mlp_ratio
										UpperCAmelCase         =			hidden_dropout_prob
										UpperCAmelCase         =			drop_path_rate
										UpperCAmelCase         =			use_layerscale
										UpperCAmelCase         =			layerscale_value
										UpperCAmelCase         =			use_post_layernorm
										UpperCAmelCase         =			use_post_layernorm_in_modulation
										UpperCAmelCase         =			normalize_modulator
										UpperCAmelCase         =			initializer_range
										UpperCAmelCase         =			layer_norm_eps
										UpperCAmelCase         =			encoder_stride
										UpperCAmelCase         =			['''stem'''] + [F"""stage{idx}""" for idx in range(1   ,					len(self.depths   ) + 1   )]
										UpperCAmelCase       ,       UpperCAmelCase         =			get_aligned_output_features_output_indices(
										    out_features=lowerCAmelCase   ,					out_indices=lowerCAmelCase   ,					stage_names=self.stage_names   )









'''simple docstring'''



import time
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
	import torch

	from transformers.generation import (
	    MaxLengthCriteria,
	    MaxNewTokensCriteria,
	    MaxTimeCriteria,
	    StoppingCriteriaList,
	    validate_stopping_criteria,
	)






@require_torch
class  UpperCamelCase__(     unittest.TestCase ):




				def   a__(	self    :				List[Any]   ,					lowerCAmelCase    :				Optional[Any]   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase         =			3
										UpperCAmelCase         =			250

										UpperCAmelCase         =			ids_tensor((batch_size, length)   ,					lowerCAmelCase   )
										UpperCAmelCase         =			torch.ones((batch_size, length)   ,					device=lowerCAmelCase   ,					dtype=torch.float   ) / length
										return input_ids, scores




				def   a__(	self    :				Dict   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(5   )

										UpperCAmelCase         =			StoppingCriteriaList(
										    [
										        MaxLengthCriteria(max_length=10   ),
										        MaxTimeCriteria(max_time=0.1   ),
										    ]   )

										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(9   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(10   )
										self.assertTrue(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )




				def   a__(	self    :				Union[str, Any]   )->  Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase         =			MaxLengthCriteria(max_length=10   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(5   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(9   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(10   )
										self.assertTrue(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )




				def   a__(	self    :				Optional[Any]   )->  List[Any]:

										"""simple docstring"""




										UpperCAmelCase         =			MaxNewTokensCriteria(start_length=5   ,					max_new_tokens=5   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(5   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(9   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(10   )
										self.assertTrue(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase         =			StoppingCriteriaList([criteria]   )
										self.assertEqual(criteria_list.max_length   ,					10   )




				def   a__(	self    :				Tuple   )->  Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase       ,       UpperCAmelCase         =			self._get_tensors(5   )

										UpperCAmelCase         =			MaxTimeCriteria(max_time=0.1   )
										self.assertFalse(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )

										UpperCAmelCase         =			MaxTimeCriteria(max_time=0.1   ,					initial_timestamp=time.time() - 0.2   )
										self.assertTrue(criteria(lowerCAmelCase   ,					lowerCAmelCase   )   )





				def   a__(	self    :				int   )->  Any:

										"""simple docstring"""




										validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10   )]   )   ,					10   )

										with self.assertWarns(lowerCAmelCase   ):
																validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10   )]   )   ,					11   )

										UpperCAmelCase         =			validate_stopping_criteria(StoppingCriteriaList()   ,					11   )

										self.assertEqual(len(lowerCAmelCase   )   ,					1   )





