


import collections
import importlib.util
import os
import re
from pathlib import Path


_snake_case  :	List[Any]			      =       "src/transformers"


# Matches is_xxx_available()
_snake_case  :	int			      =       re.compile(R"is\_([a-z_]*)_available()")
# Catches a one-line _import_struct = {xxx}
_snake_case  :	List[Any]			      =       re.compile(R"^_import_structure\s+=\s+\{([^\}]+)\}")
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
_snake_case  :	Optional[Any]			      =       re.compile(R"\s+\"\S*\":\s+\[([^\]]*)\]")
# Catches a line if not is_foo_available
_snake_case  :	Tuple			      =       re.compile(R"^\s*if\s+not\s+is\_[a-z_]*\_available\(\)")
# Catches a line _import_struct["bla"].append("foo")
_snake_case  :	Tuple			      =       re.compile(R"^\s*_import_structure\[\"\S*\"\]\.append\(\"(\S*)\"\)")
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
_snake_case  :	str			      =       re.compile(R"^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]")
# Catches a line with an object between quotes and a comma:     "MyModel",
_snake_case  :	str			      =       re.compile("^\s+\"([^\"]+)\",")
# Catches a line with objects between brackets only:    ["foo", "bar"],
_snake_case  :	Any			      =       re.compile("^\s+\[([^\]]+)\]")
# Catches a line with from foo import bar, bla, boo
_snake_case  :	int			      =       re.compile(R"\s+from\s+\S*\s+import\s+([^\(\s].*)\n")
# Catches a line with try:
_snake_case  :	str			      =       re.compile(R"^\s*try:")
# Catches a line with else:
_snake_case  :	Dict			      =       re.compile(R"^\s*else:")







def        lowerCAmelCase_  (      __lowerCamelCase			):
							if _re_test_backend.search(__lowerCamelCase			) is None:
														return None
							__snake_case	:    List[str]											=     [b[0] for b in _re_backend.findall(__lowerCamelCase			)]
							backends.sort()
							return "_and_".join(__lowerCamelCase			)







def        lowerCAmelCase_  (      __lowerCamelCase			):
							with open(__lowerCamelCase							,			"r"							,			encoding="utf-8"							,			newline="\n"			) as f:
														__snake_case	:    int											=     f.readlines()

							__snake_case	:    Dict											=     0
							while line_index < len(__lowerCamelCase			) and not lines[line_index].startswith("_import_structure = {"			):
														line_index += 1

							# If this is a traditional init, just return.
							if line_index >= len(__lowerCamelCase			):
														return None

							# First grab the objects without a specific backend in _import_structure
							__snake_case	:    int											=     []
							while not lines[line_index].startswith("if TYPE_CHECKING"			) and find_backend(lines[line_index]			) is None:
														__snake_case	:    Dict											=     lines[line_index]
														# If we have everything on a single line, let's deal with it.
														if _re_one_line_import_struct.search(__lowerCamelCase			):
																					__snake_case	:    Any											=     _re_one_line_import_struct.search(__lowerCamelCase			).groups()[0]
																					__snake_case	:    Optional[Any]											=     re.findall("\[([^\]]+)\]"							,			__lowerCamelCase			)
																					for imp in imports:
																												objects.extend([obj[1:-1] for obj in imp.split(", "			)]			)
																					line_index += 1
																					continue
														__snake_case	:    List[Any]											=     _re_import_struct_key_value.search(__lowerCamelCase			)
														if single_line_import_search is not None:
																					__snake_case	:    Tuple											=     [obj[1:-1] for obj in single_line_import_search.groups()[0].split(", "			) if len(__lowerCamelCase			) > 0]
																					objects.extend(__lowerCamelCase			)
														elif line.startswith(" " * 8 + "\""			):
																					objects.append(line[9:-3]			)
														line_index += 1

							__snake_case	:    Any											=     {"none": objects}
							# Let's continue with backend-specific objects in _import_structure
							while not lines[line_index].startswith("if TYPE_CHECKING"			):
														# If the line is an if not is_backend_available, we grab all objects associated.
														__snake_case	:    Optional[Any]											=     find_backend(lines[line_index]			)
														# Check if the backend declaration is inside a try block:
														if _re_try.search(lines[line_index - 1]			) is None:
																					__snake_case	:    Any											=     None

														if backend is not None:
																					line_index += 1

																					# Scroll until we hit the else block of try-except-else
																					while _re_else.search(lines[line_index]			) is None:
																												line_index += 1

																					line_index += 1

																					__snake_case	:    str											=     []
																					# Until we unindent, add backend objects to the list
																					while len(lines[line_index]			) <= 1 or lines[line_index].startswith(" " * 4			):
																												__snake_case	:    int											=     lines[line_index]
																												if _re_import_struct_add_one.search(__lowerCamelCase			) is not None:
																																			objects.append(_re_import_struct_add_one.search(__lowerCamelCase			).groups()[0]			)
																												elif _re_import_struct_add_many.search(__lowerCamelCase			) is not None:
																																			__snake_case	:    Optional[int]											=     _re_import_struct_add_many.search(__lowerCamelCase			).groups()[0].split(", "			)
																																			__snake_case	:    str											=     [obj[1:-1] for obj in imports if len(__lowerCamelCase			) > 0]
																																			objects.extend(__lowerCamelCase			)
																												elif _re_between_brackets.search(__lowerCamelCase			) is not None:
																																			__snake_case	:    int											=     _re_between_brackets.search(__lowerCamelCase			).groups()[0].split(", "			)
																																			__snake_case	:    Union[str, Any]											=     [obj[1:-1] for obj in imports if len(__lowerCamelCase			) > 0]
																																			objects.extend(__lowerCamelCase			)
																												elif _re_quote_object.search(__lowerCamelCase			) is not None:
																																			objects.append(_re_quote_object.search(__lowerCamelCase			).groups()[0]			)
																												elif line.startswith(" " * 8 + "\""			):
																																			objects.append(line[9:-3]			)
																												elif line.startswith(" " * 1_2 + "\""			):
																																			objects.append(line[1_3:-3]			)
																												line_index += 1

																					__snake_case	:    Tuple											=     objects
														else:
																					line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
							__snake_case	:    int											=     []
							while (
							    line_index < len(__lowerCamelCase			)
							    and find_backend(lines[line_index]			) is None
							    and not lines[line_index].startswith("else"			)
							):
														__snake_case	:    List[str]											=     lines[line_index]
														__snake_case	:    Union[str, Any]											=     _re_import.search(__lowerCamelCase			)
														if single_line_import_search is not None:
																					objects.extend(single_line_import_search.groups()[0].split(", "			)			)
														elif line.startswith(" " * 8			):
																					objects.append(line[8:-2]			)
														line_index += 1

							__snake_case	:    Optional[int]											=     {"none": objects}
							# Let's continue with backend-specific objects
							while line_index < len(__lowerCamelCase			):
														# If the line is an if is_backend_available, we grab all objects associated.
														__snake_case	:    List[str]											=     find_backend(lines[line_index]			)
														# Check if the backend declaration is inside a try block:
														if _re_try.search(lines[line_index - 1]			) is None:
																					__snake_case	:    List[Any]											=     None

														if backend is not None:
																					line_index += 1

																					# Scroll until we hit the else block of try-except-else
																					while _re_else.search(lines[line_index]			) is None:
																												line_index += 1

																					line_index += 1

																					__snake_case	:    Union[str, Any]											=     []
																					# Until we unindent, add backend objects to the list
																					while len(lines[line_index]			) <= 1 or lines[line_index].startswith(" " * 8			):
																												__snake_case	:    Optional[Any]											=     lines[line_index]
																												__snake_case	:    Dict											=     _re_import.search(__lowerCamelCase			)
																												if single_line_import_search is not None:
																																			objects.extend(single_line_import_search.groups()[0].split(", "			)			)
																												elif line.startswith(" " * 1_2			):
																																			objects.append(line[1_2:-2]			)
																												line_index += 1

																					__snake_case	:    int											=     objects
														else:
																					line_index += 1

							return import_dict_objects, type_hint_objects







def        lowerCAmelCase_  (      __lowerCamelCase							,			__lowerCamelCase			):

							def find_duplicates(__lowerCamelCase			):
														return [k for k, v in collections.Counter(__lowerCamelCase			).items() if v > 1]

							if list(import_dict_objects.keys()			) != list(type_hint_objects.keys()			):
														return ["Both sides of the init do not have the same backends!"]

							__snake_case	:    str											=     []
							for key in import_dict_objects.keys():
														__snake_case	:    Tuple											=     find_duplicates(import_dict_objects[key]			)
														if duplicate_imports:
																					errors.append(F'Duplicate _import_structure definitions for: {duplicate_imports}'			)
														__snake_case	:    Dict											=     find_duplicates(type_hint_objects[key]			)
														if duplicate_type_hints:
																					errors.append(F'Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}'			)

														if sorted(set(import_dict_objects[key]			)			) != sorted(set(type_hint_objects[key]			)			):
																					__snake_case	:    str											=     "base imports" if key == "none" else F'{key} backend'
																					errors.append(F'Differences for {name}:'			)
																					for a in type_hint_objects[key]:
																												if a not in import_dict_objects[key]:
																																			errors.append(F'  {a} in TYPE_HINT but not in _import_structure.'			)
																					for a in import_dict_objects[key]:
																												if a not in type_hint_objects[key]:
																																			errors.append(F'  {a} in _import_structure but not in TYPE_HINT.'			)
							return errors







def        lowerCAmelCase_  (      ):
							__snake_case	:    Tuple											=     []
							for root, _, files in os.walk(__lowerCamelCase			):
														if "__init__.py" in files:
																					__snake_case	:    int											=     os.path.join(__lowerCamelCase							,			"__init__.py"			)
																					__snake_case	:    List[Any]											=     parse_init(__lowerCamelCase			)
																					if objects is not None:
																												__snake_case	:    Optional[int]											=     analyze_results(*__lowerCamelCase			)
																												if len(__lowerCamelCase			) > 0:
																																			__snake_case	:    Union[str, Any]											=     F'Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'
																																			failures.append("\n".join(__lowerCamelCase			)			)
							if len(__lowerCamelCase			) > 0:
														raise ValueError("\n\n".join(__lowerCamelCase			)			)







def        lowerCAmelCase_  (      ):
							__snake_case	:    str											=     []
							for path, directories, files in os.walk(__lowerCamelCase			):
														for folder in directories:
																					# Ignore private modules
																					if folder.startswith("_"			):
																												directories.remove(__lowerCamelCase			)
																												continue
																					# Ignore leftovers from branches (empty folders apart from pycache)
																					if len(list((Path(__lowerCamelCase			) / folder).glob("*.py"			)			)			) == 0:
																												continue
																					__snake_case	:    Dict											=     str((Path(__lowerCamelCase			) / folder).relative_to(__lowerCamelCase			)			)
																					__snake_case	:    str											=     short_path.replace(os.path.sep							,			"."			)
																					submodules.append(__lowerCamelCase			)
														for fname in files:
																					if fname == "__init__.py":
																												continue
																					__snake_case	:    Dict											=     str((Path(__lowerCamelCase			) / fname).relative_to(__lowerCamelCase			)			)
																					__snake_case	:    List[str]											=     short_path.replace(".py"							,			""			).replace(os.path.sep							,			"."			)
																					if len(submodule.split("."			)			) == 1:
																												submodules.append(__lowerCamelCase			)
							return submodules


_snake_case  :	str			      =       [
    "convert_pytorch_checkpoint_to_tf2",
    "modeling_flax_pytorch_utils",
]







def        lowerCAmelCase_  (      ):
							# This is to make sure the transformers module imported is the one in the repo.
							__snake_case	:    str											=     importlib.util.spec_from_file_location(
							    "transformers"							,			os.path.join(__lowerCamelCase							,			"__init__.py"			)							,			submodule_search_locations=[PATH_TO_TRANSFORMERS]							,			)
							__snake_case	:    Optional[int]											=     spec.loader.load_module()

							__snake_case	:    int											=     [
							    module
							    for module in get_transformers_submodules()
							    if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
							]
							if len(__lowerCamelCase			) > 0:
														__snake_case	:    Union[str, Any]											=     "\n".join(F'- {module}' for module in module_not_registered			)
														raise ValueError(
														    "The following submodules are not properly registered in the main init of Transformers:\n"
														    F'{list_of_modules}\n'
														    "Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value."			)


if __name__ == "__main__":
			check_all_inits()
			check_submodules()





import collections
import inspect
import unittest

from transformers import FocalNetConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import (
			    FocalNetBackbone,
			    FocalNetForImageClassification,
			    FocalNetForMaskedImageModeling,
			    FocalNetModel,
			)
			from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class        a	:




							"""simple docstring"""


							def __init__(							self :						Union[str, Any]					,			lowerCamelCase :						str					,			lowerCamelCase :						Tuple=13					,			lowerCamelCase :						Tuple=32					,			lowerCamelCase :						Any=2					,			lowerCamelCase :						Union[str, Any]=3					,			lowerCamelCase :						Tuple=16					,			lowerCamelCase :						Any=[32, 64, 128]					,			lowerCamelCase :						str=[1, 2, 1]					,			lowerCamelCase :						Union[str, Any]=[2, 2, 4]					,			lowerCamelCase :						Union[str, Any]=2					,			lowerCamelCase :						Optional[int]=2.0					,			lowerCamelCase :						Tuple=True					,			lowerCamelCase :						Optional[int]=0.0					,			lowerCamelCase :						List[str]=0.0					,			lowerCamelCase :						Dict=0.1					,			lowerCamelCase :						Optional[int]="gelu"					,			lowerCamelCase :						Any=False					,			lowerCamelCase :						Any=True					,			lowerCamelCase :						str=0.02					,			lowerCamelCase :						Tuple=1E-5					,			lowerCamelCase :						str=True					,			lowerCamelCase :						Optional[Any]=None					,			lowerCamelCase :						List[str]=True					,			lowerCamelCase :						Union[str, Any]=10					,			lowerCamelCase :						Any=8					,			lowerCamelCase :						List[str]=["stage1", "stage2"]					,			lowerCamelCase :						Optional[int]=[1, 2]					,			)			->					Optional[int]:
														__snake_case	:    Any											=     parent
														__snake_case	:    int											=     batch_size
														__snake_case	:    Optional[int]											=     image_size
														__snake_case	:    int											=     patch_size
														__snake_case	:    Any											=     num_channels
														__snake_case	:    List[Any]											=     embed_dim
														__snake_case	:    str											=     hidden_sizes
														__snake_case	:    int											=     depths
														__snake_case	:    Any											=     num_heads
														__snake_case	:    Any											=     window_size
														__snake_case	:    Optional[Any]											=     mlp_ratio
														__snake_case	:    Any											=     qkv_bias
														__snake_case	:    List[Any]											=     hidden_dropout_prob
														__snake_case	:    Dict											=     attention_probs_dropout_prob
														__snake_case	:    Tuple											=     drop_path_rate
														__snake_case	:    Tuple											=     hidden_act
														__snake_case	:    Optional[int]											=     use_absolute_embeddings
														__snake_case	:    Optional[int]											=     patch_norm
														__snake_case	:    int											=     layer_norm_eps
														__snake_case	:    Any											=     initializer_range
														__snake_case	:    Any											=     is_training
														__snake_case	:    Tuple											=     scope
														__snake_case	:    Tuple											=     use_labels
														__snake_case	:    Any											=     type_sequence_label_size
														__snake_case	:    Dict											=     encoder_stride
														__snake_case	:    Union[str, Any]											=     out_features
														__snake_case	:    Union[str, Any]											=     out_indices

							def 					__snake_case      (							self :						Optional[Any]       )			->					str:
														__snake_case	:    List[Any]											=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

														__snake_case	:    Optional[Any]											=     None
														if self.use_labels:
																					__snake_case	:    Tuple											=     ids_tensor([self.batch_size]					,			self.type_sequence_label_size       )

														__snake_case	:    Optional[Any]											=     self.get_config()

														return config, pixel_values, labels

							def 					__snake_case      (							self :						Union[str, Any]       )			->					List[Any]:
														return FocalNetConfig(
														    image_size=self.image_size					,			patch_size=self.patch_size					,			num_channels=self.num_channels					,			embed_dim=self.embed_dim					,			hidden_sizes=self.hidden_sizes					,			depths=self.depths					,			num_heads=self.num_heads					,			window_size=self.window_size					,			mlp_ratio=self.mlp_ratio					,			qkv_bias=self.qkv_bias					,			hidden_dropout_prob=self.hidden_dropout_prob					,			attention_probs_dropout_prob=self.attention_probs_dropout_prob					,			drop_path_rate=self.drop_path_rate					,			hidden_act=self.hidden_act					,			use_absolute_embeddings=self.use_absolute_embeddings					,			path_norm=self.patch_norm					,			layer_norm_eps=self.layer_norm_eps					,			initializer_range=self.initializer_range					,			encoder_stride=self.encoder_stride					,			out_features=self.out_features					,			out_indices=self.out_indices					,			)

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						Optional[int]					,			lowerCamelCase :						Dict					,			lowerCamelCase :						str       )			->					str:
														__snake_case	:    Tuple											=     FocalNetModel(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    List[str]											=     model(lowerCamelCase       )

														__snake_case	:    Tuple											=     ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths       ) - 1))
														__snake_case	:    Optional[Any]											=     int(config.embed_dim * 2 ** (len(config.depths       ) - 1)       )

														self.parent.assertEqual(result.last_hidden_state.shape					,			(self.batch_size, expected_seq_len, expected_dim)       )

							def 					__snake_case      (							self :						Tuple					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						int					,			lowerCamelCase :						List[Any]       )			->					Optional[int]:
														__snake_case	:    Union[str, Any]											=     FocalNetBackbone(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    int											=     model(lowerCamelCase       )

														# verify feature maps
														self.parent.assertEqual(len(result.feature_maps       )					,			len(config.out_features       )       )
														self.parent.assertListEqual(list(result.feature_maps[0].shape       )					,			[self.batch_size, self.image_size, 8, 8]       )

														# verify channels
														self.parent.assertEqual(len(model.channels       )					,			len(config.out_features       )       )
														self.parent.assertListEqual(model.channels					,			config.hidden_sizes[:-1]       )

														# verify backbone works with out_features=None
														__snake_case	:    Dict											=     None
														__snake_case	:    Any											=     FocalNetBackbone(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Optional[int]											=     model(lowerCamelCase       )

														# verify feature maps
														self.parent.assertEqual(len(result.feature_maps       )					,			1       )
														self.parent.assertListEqual(list(result.feature_maps[0].shape       )					,			[self.batch_size, self.image_size * 2, 4, 4]       )

														# verify channels
														self.parent.assertEqual(len(model.channels       )					,			1       )
														self.parent.assertListEqual(model.channels					,			[config.hidden_sizes[-1]]       )

							def 					__snake_case      (							self :						Any					,			lowerCamelCase :						Optional[Any]					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Any       )			->					Optional[int]:
														__snake_case	:    List[Any]											=     FocalNetForMaskedImageModeling(config=lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    List[str]											=     model(lowerCamelCase       )
														self.parent.assertEqual(
														    result.reconstruction.shape					,			(self.batch_size, self.num_channels, self.image_size, self.image_size)       )

														# test greyscale images
														__snake_case	:    List[str]											=     1
														__snake_case	:    Any											=     FocalNetForMaskedImageModeling(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()

														__snake_case	:    Optional[Any]											=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]       )
														__snake_case	:    int											=     model(lowerCamelCase       )
														self.parent.assertEqual(result.reconstruction.shape					,			(self.batch_size, 1, self.image_size, self.image_size)       )

							def 					__snake_case      (							self :						str					,			lowerCamelCase :						Dict					,			lowerCamelCase :						Any					,			lowerCamelCase :						str       )			->					Optional[Any]:
														__snake_case	:    Tuple											=     self.type_sequence_label_size
														__snake_case	:    List[Any]											=     FocalNetForImageClassification(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()
														__snake_case	:    Optional[Any]											=     model(lowerCamelCase					,			labels=lowerCamelCase       )
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.type_sequence_label_size)       )

														# test greyscale images
														__snake_case	:    Optional[int]											=     1
														__snake_case	:    str											=     FocalNetForImageClassification(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()

														__snake_case	:    Optional[Any]											=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]       )
														__snake_case	:    Optional[Any]											=     model(lowerCamelCase       )
														self.parent.assertEqual(result.logits.shape					,			(self.batch_size, self.type_sequence_label_size)       )






							def 					__snake_case      (							self :						Optional[int]       )			->					Optional[int]:
														__snake_case	:    str											=     self.prepare_config_and_inputs()

														__snake_case				,    __snake_case				,    __snake_case	:    List[str]											=     config_and_inputs
														__snake_case	:    Union[str, Any]											=     {"pixel_values": pixel_values}
														return config, inputs_dict

@require_torch
class        a	(_lowerCAmelCase  ,       _lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							int  						=						(
							    (
							        FocalNetModel,
							        FocalNetForImageClassification,
							        FocalNetForMaskedImageModeling,
							        FocalNetBackbone,
							    )
							    if is_torch_available()
							    else ()
							)
							__UpperCAmelCase					:							Optional[int]  						=						(
							    {"feature-extraction": FocalNetModel, "image-classification": FocalNetForImageClassification}
							    if is_torch_available()
							    else {}
							)
							__UpperCAmelCase					:							List[str]  						=						False

							__UpperCAmelCase					:							str  						=						False
							__UpperCAmelCase					:							List[Any]  						=						False
							__UpperCAmelCase					:							Optional[int]  						=						False
							__UpperCAmelCase					:							List[str]  						=						False

							def 					__snake_case      (							self :						List[str]       )			->					Tuple:
														__snake_case	:    Optional[Any]											=     FocalNetModelTester(self       )
														__snake_case	:    int											=     ConfigTester(self					,			config_class=lowerCamelCase					,			embed_dim=37					,			has_text_modality=lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[int]       )			->					int:
														self.create_and_test_config_common_properties()
														self.config_tester.create_and_test_config_to_json_string()
														self.config_tester.create_and_test_config_to_json_file()
														self.config_tester.create_and_test_config_from_and_save_pretrained()
														self.config_tester.create_and_test_config_with_num_labels()
														self.config_tester.check_config_can_be_init_without_params()
														self.config_tester.check_config_arguments_init()

							def 					__snake_case      (							self :						str       )			->					Tuple:
														return

							def 					__snake_case      (							self :						Union[str, Any]       )			->					str:
														__snake_case	:    Optional[int]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCamelCase       )

							def 					__snake_case      (							self :						str       )			->					int:
														__snake_case	:    Optional[int]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_backbone(*lowerCamelCase       )

							def 					__snake_case      (							self :						List[str]       )			->					Optional[int]:
														__snake_case	:    Tuple											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_image_modeling(*lowerCamelCase       )

							def 					__snake_case      (							self :						str       )			->					List[str]:
														__snake_case	:    Optional[int]											=     self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*lowerCamelCase       )

							@unittest.skip(reason="FocalNet does not use inputs_embeds"       )
							def 					__snake_case      (							self :						Dict       )			->					List[str]:
														pass

							@unittest.skip(reason="FocalNet does not use feedforward chunking"       )
							def 					__snake_case      (							self :						str       )			->					int:
														pass

							def 					__snake_case      (							self :						Optional[int]       )			->					Tuple:
														__snake_case				,    __snake_case	:    str											=     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes[:-1]:
																					__snake_case	:    Dict											=     model_class(lowerCamelCase       )
																					self.assertIsInstance(model.get_input_embeddings()					,			(nn.Module)       )
																					__snake_case	:    Any											=     model.get_output_embeddings()
																					self.assertTrue(x is None or isinstance(lowerCamelCase					,			nn.Linear       )       )

							def 					__snake_case      (							self :						List[str]       )			->					Optional[int]:
														__snake_case				,    __snake_case	:    Dict											=     self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes[:-1]:
																					__snake_case	:    List[str]											=     model_class(lowerCamelCase       )
																					__snake_case	:    Optional[Any]											=     inspect.signature(model.forward       )
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					__snake_case	:    List[Any]											=     [*signature.parameters.keys()]

																					__snake_case	:    Tuple											=     ["pixel_values"]
																					self.assertListEqual(arg_names[:1]					,			lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[int]					,			lowerCamelCase :						List[str]					,			lowerCamelCase :						Tuple					,			lowerCamelCase :						List[Any]					,			lowerCamelCase :						Union[str, Any]       )			->					str:
														__snake_case	:    Tuple											=     model_class(lowerCamelCase       )
														model.to(lowerCamelCase       )
														model.eval()

														with torch.no_grad():
																					__snake_case	:    List[Any]											=     model(**self._prepare_for_class(lowerCamelCase					,			lowerCamelCase       )       )

														__snake_case	:    List[str]											=     outputs.hidden_states

														__snake_case	:    Tuple											=     getattr(
														    self.model_tester					,			"expected_num_hidden_layers"					,			len(self.model_tester.depths       ) + 1       )
														self.assertEqual(len(lowerCamelCase       )					,			lowerCamelCase       )

														# FocalNet has a different seq_length
														__snake_case	:    Tuple											=     (
														    config.patch_size
														    if isinstance(config.patch_size					,			collections.abc.Iterable       )
														    else (config.patch_size, config.patch_size)
														)

														__snake_case	:    int											=     (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

														self.assertListEqual(
														    list(hidden_states[0].shape[-2:]       )					,			[num_patches, self.model_tester.embed_dim]					,			)

														__snake_case	:    List[Any]											=     outputs.reshaped_hidden_states
														self.assertEqual(len(lowerCamelCase       )					,			lowerCamelCase       )

														__snake_case				,    __snake_case				,    __snake_case				,    __snake_case	:    Tuple											=     reshaped_hidden_states[0].shape
														__snake_case	:    Optional[int]											=     (
														    reshaped_hidden_states[0].view(lowerCamelCase					,			lowerCamelCase					,			height * width       ).permute(0					,			2					,			1       )
														)
														self.assertListEqual(
														    list(reshaped_hidden_states.shape[-2:]       )					,			[num_patches, self.model_tester.embed_dim]					,			)

							def 					__snake_case      (							self :						Tuple       )			->					int:
														__snake_case				,    __snake_case	:    Any											=     self.model_tester.prepare_config_and_inputs_for_common()

														__snake_case	:    Dict											=     (
														    self.model_tester.image_size
														    if isinstance(self.model_tester.image_size					,			collections.abc.Iterable       )
														    else (self.model_tester.image_size, self.model_tester.image_size)
														)

														for model_class in self.all_model_classes[:-1]:
																					__snake_case	:    Optional[Any]											=     True
																					self.check_hidden_states_output(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					__snake_case	:    Dict											=     True

																					self.check_hidden_states_output(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase       )

							def 					__snake_case      (							self :						Optional[int]       )			->					Any:
														__snake_case				,    __snake_case	:    Union[str, Any]											=     self.model_tester.prepare_config_and_inputs_for_common()
														__snake_case	:    Optional[int]											=     3

														__snake_case	:    List[str]											=     (
														    self.model_tester.image_size
														    if isinstance(self.model_tester.image_size					,			collections.abc.Iterable       )
														    else (self.model_tester.image_size, self.model_tester.image_size)
														)
														__snake_case	:    Any											=     (
														    config.patch_size
														    if isinstance(config.patch_size					,			collections.abc.Iterable       )
														    else (config.patch_size, config.patch_size)
														)

														__snake_case	:    Dict											=     image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
														__snake_case	:    List[Any]											=     image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

														for model_class in self.all_model_classes[:-1]:
																					__snake_case	:    List[str]											=     True
																					self.check_hidden_states_output(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			(padded_height, padded_width)       )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					__snake_case	:    Tuple											=     True
																					self.check_hidden_states_output(lowerCamelCase					,			lowerCamelCase					,			lowerCamelCase					,			(padded_height, padded_width)       )

							@slow
							def 					__snake_case      (							self :						List[Any]       )			->					Union[str, Any]:
														for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					__snake_case	:    List[str]											=     FocalNetModel.from_pretrained(lowerCamelCase       )
																					self.assertIsNotNone(lowerCamelCase       )






							def 					__snake_case      (							self :						Tuple       )			->					List[Any]:
														__snake_case				,    __snake_case	:    str											=     self.model_tester.prepare_config_and_inputs_for_common()

														__snake_case	:    Optional[Any]											=     _config_zero_init(lowerCamelCase       )
														for model_class in self.all_model_classes:
																					__snake_case	:    Tuple											=     model_class(config=lowerCamelCase       )
																					for name, param in model.named_parameters():
																												if "embeddings" not in name and param.requires_grad:
																																			self.assertIn(
																																			    ((param.data.mean() * 1E9).round() / 1E9).item()					,			[0.0, 1.0]					,			msg=F'Parameter {name} of model {model_class} seems not properly initialized'					,			)

@require_vision
@require_torch
class        a	(unittest.TestCase   ):




							"""simple docstring"""


							@cached_property
							def 					__snake_case      (							self :						Union[str, Any]       )			->					List[Any]:
														# TODO update organization
														return AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny"       ) if is_vision_available() else None






							@slow
							def 					__snake_case      (							self :						int       )			->					Optional[int]:
														__snake_case	:    List[str]											=     FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny"       ).to(lowerCamelCase       )
														__snake_case	:    str											=     self.default_image_processor

														__snake_case	:    Dict											=     Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
														__snake_case	:    Optional[Any]											=     image_processor(images=lowerCamelCase					,			return_tensors="pt"       ).to(lowerCamelCase       )

														# forward pass
														with torch.no_grad():
																					__snake_case	:    int											=     model(**lowerCamelCase       )

														# verify the logits
														__snake_case	:    List[str]											=     torch.Size((1, 1000)       )
														self.assertEqual(outputs.logits.shape					,			lowerCamelCase       )
														__snake_case	:    Optional[int]											=     torch.tensor([0.21_66, -0.43_68, 0.21_91]       ).to(lowerCamelCase       )
														self.assertTrue(torch.allclose(outputs.logits[0, :3]					,			lowerCamelCase					,			atol=1E-4       )       )
														self.assertTrue(outputs.logits.argmax(dim=-1       ).item()					,			281       )

@require_torch
class        a	(_lowerCAmelCase  ,       unittest.TestCase   ):




							"""simple docstring"""


							__UpperCAmelCase					:							Tuple  						=						(FocalNetBackbone,) if is_torch_available() else ()
							__UpperCAmelCase					:							Dict  						=						FocalNetConfig

							__UpperCAmelCase					:							Any  						=						False

							def 					__snake_case      (							self :						str       )			->					List[str]:
														__snake_case	:    Tuple											=     FocalNetModelTester(self       )

