

import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
lowercase			:				Dict   =     sys.version_info >= (3, 10)






def        snake_case__		(    lowerCamelCase_=None     ,				lowerCamelCase_=None		):
							return field(default_factory=lambda: default     ,				metadata=lowerCamelCase_		)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		int
							UpperCAmelCase_						:		float
							UpperCAmelCase_						:		str
							UpperCAmelCase_						:		bool







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		int								=	42
							UpperCAmelCase_						:		str								=	field(default='''toto'''		,       metadata={'''help''': '''help message'''}				)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		bool								=	False
							UpperCAmelCase_						:		bool								=	True
							UpperCAmelCase_						:		Optional[bool]								=	None







class 					__lowercase  (						_SCREAMING_SNAKE_CASE				):





							"""simple docstring"""

							UpperCAmelCase_						:		List[str]								=	'''titi'''
							UpperCAmelCase_						:		Optional[Any]								=	'''toto'''







class 					__lowercase  (						_SCREAMING_SNAKE_CASE				):





							"""simple docstring"""

							UpperCAmelCase_						:		List[Any]								=	'''titi'''
							UpperCAmelCase_						:		Any								=	'''toto'''
							UpperCAmelCase_						:		Dict								=	42







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		BasicEnum								=	"toto"




							def       snake_case			(					self						)		->       Dict:
														A      :					str      		=					BasicEnum(self.foo						)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		MixedTypeEnum								=	"toto"




							def       snake_case			(					self						)		->       Union[str, Any]:
														A      :					Optional[Any]      		=					MixedTypeEnum(self.foo						)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		Optional[int]								=	None
							UpperCAmelCase_						:		Optional[float]								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''help message'''}				)
							UpperCAmelCase_						:		Optional[str]								=	None
							UpperCAmelCase_						:		Optional[List[str]]								=	list_field(default=[]				)
							UpperCAmelCase_						:		Optional[List[int]]								=	list_field(default=[]				)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		List[int]								=	list_field(default=[]				)
							UpperCAmelCase_						:		List[int]								=	list_field(default=[1, 2, 3]				)
							UpperCAmelCase_						:		List[str]								=	list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']				)
							UpperCAmelCase_						:		List[float]								=	list_field(default=[0.1, 0.2, 0.3]				)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		List[int]								=	field()
							UpperCAmelCase_						:		str								=	field()
							UpperCAmelCase_						:		BasicEnum								=	field()




							def       snake_case			(					self						)		->       int:
														A      :					Union[str, Any]      		=					BasicEnum(self.required_enum						)







@dataclass
class 					__lowercase  :





							"""simple docstring"""

							UpperCAmelCase_						:		int
							UpperCAmelCase_						:		"BasicEnum"								=	field()
							UpperCAmelCase_						:		"Optional[bool]"								=	None
							UpperCAmelCase_						:		"str"								=	field(default='''toto'''		,       metadata={'''help''': '''help message'''}				)
							UpperCAmelCase_						:		"List[str]"								=	list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']				)


if is_python_no_less_than_3_10:







		@dataclass
		class 					__lowercase  :





									"""simple docstring"""

									UpperCAmelCase_						:		bool								=	False
									UpperCAmelCase_						:		bool								=	True
									UpperCAmelCase_						:		bool | None								=	None







		@dataclass
		class 					__lowercase  :





									"""simple docstring"""

									UpperCAmelCase_						:		int | None								=	None
									UpperCAmelCase_						:		float | None								=	field(default=_SCREAMING_SNAKE_CASE		,       metadata={'''help''': '''help message'''}				)
									UpperCAmelCase_						:		str | None								=	None
									UpperCAmelCase_						:		list[str] | None								=	list_field(default=[]				)
									UpperCAmelCase_						:		list[int] | None								=	list_field(default=[]				)







class 					__lowercase  (						unittest.TestCase				):





							"""simple docstring"""

							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase						)		->       int:
														self.assertEqual(len(a._actions						)    ,						len(b._actions						)						)
														for x, y in zip(a._actions    ,						b._actions						):
																					A      :					Any      		=					{k: v for k, v in vars(__UpperCAmelCase						).items() if k != '''container'''}
																					A      :					Union[str, Any]      		=					{k: v for k, v in vars(__UpperCAmelCase						).items() if k != '''container'''}

																					# Choices with mixed type have custom function as "type"
																					# So we need to compare results directly for equality
																					if xx.get('''choices'''    ,						__UpperCAmelCase						) and yy.get('''choices'''    ,						__UpperCAmelCase						):
																												for expected_choice in yy["choices"] + xx["choices"]:
																																			self.assertEqual(xx['''type'''](__UpperCAmelCase						)    ,						yy['''type'''](__UpperCAmelCase						)						)
																												del xx["type"], yy["type"]

																					self.assertEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[int]:
														A      :					Any      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					List[str]      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument('''--bar'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument('''--baz'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument('''--flag'''    ,						type=__UpperCAmelCase    ,						default=__UpperCAmelCase    ,						const=__UpperCAmelCase    ,						nargs='''?'''						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

														A      :					Optional[int]      		=					['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
														((A)		,		)      :					List[str]      		=					parser.parse_args_into_dataclasses(__UpperCAmelCase    ,						look_for_args_file=__UpperCAmelCase						)
														self.assertFalse(example.flag						)




							def       snake_case			(					self						)		->       Any:
														A      :					Optional[Any]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Dict      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo'''    ,						default=42    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--baz'''    ,						default='''toto'''    ,						type=__UpperCAmelCase    ,						help='''help message'''						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       List[Any]:
														A      :					Dict      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo'''    ,						type=__UpperCAmelCase    ,						default=__UpperCAmelCase    ,						const=__UpperCAmelCase    ,						nargs='''?'''						)
														expected.add_argument('''--baz'''    ,						type=__UpperCAmelCase    ,						default=__UpperCAmelCase    ,						const=__UpperCAmelCase    ,						nargs='''?'''						)
														# A boolean no_* argument always has to come after its "default: True" regular counter-part
														# and its default must be set to False
														expected.add_argument('''--no_baz'''    ,						action='''store_false'''    ,						default=__UpperCAmelCase    ,						dest='''baz'''						)
														expected.add_argument('''--opt'''    ,						type=__UpperCAmelCase    ,						default=__UpperCAmelCase						)

														A      :					str      		=					[WithDefaultBoolExample]
														if is_python_no_less_than_3_10:
																					dataclass_types.append(__UpperCAmelCase						)

														for dataclass_type in dataclass_types:
																					A      :					Union[str, Any]      		=					HfArgumentParser(__UpperCAmelCase						)
																					self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

																					A      :					List[str]      		=					parser.parse_args([]						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						opt=__UpperCAmelCase						)						)

																					A      :					List[Any]      		=					parser.parse_args(['''--foo''', '''--no_baz''']						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						opt=__UpperCAmelCase						)						)

																					A      :					List[Any]      		=					parser.parse_args(['''--foo''', '''--baz''']						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						opt=__UpperCAmelCase						)						)

																					A      :					Union[str, Any]      		=					parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True''']						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						opt=__UpperCAmelCase						)						)

																					A      :					Union[str, Any]      		=					parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						opt=__UpperCAmelCase						)						)




							def       snake_case			(					self						)		->       List[Any]:
														A      :					Any      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Union[str, Any]      		=					argparse.ArgumentParser()
														expected.add_argument(
														    '''--foo'''    ,						default='''toto'''    ,						choices=['''titi''', '''toto''', 42]    ,						type=make_choice_type_function(['''titi''', '''toto''', 42]						)    ,						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

														A      :					Dict      		=					parser.parse_args([]						)
														self.assertEqual(args.foo    ,						'''toto'''						)
														A      :					int      		=					parser.parse_args_into_dataclasses([]						)[0]
														self.assertEqual(enum_ex.foo    ,						MixedTypeEnum.toto						)

														A      :					Tuple      		=					parser.parse_args(['''--foo''', '''titi''']						)
														self.assertEqual(args.foo    ,						'''titi'''						)
														A      :					Union[str, Any]      		=					parser.parse_args_into_dataclasses(['''--foo''', '''titi''']						)[0]
														self.assertEqual(enum_ex.foo    ,						MixedTypeEnum.titi						)

														A      :					Dict      		=					parser.parse_args(['''--foo''', '''42''']						)
														self.assertEqual(args.foo    ,						42						)
														A      :					Tuple      		=					parser.parse_args_into_dataclasses(['''--foo''', '''42''']						)[0]
														self.assertEqual(enum_ex.foo    ,						MixedTypeEnum.fourtytwo						)




							def       snake_case			(					self						)		->       Any:







														@dataclass
														class 					__lowercase  :





																					"""simple docstring"""

																					UpperCAmelCase_						:		Literal["titi", "toto", 42]								=	"toto"



														A      :					List[Any]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Union[str, Any]      		=					argparse.ArgumentParser()
														expected.add_argument(
														    '''--foo'''    ,						default='''toto'''    ,						choices=('''titi''', '''toto''', 42)    ,						type=make_choice_type_function(['''titi''', '''toto''', 42]						)    ,						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

														A      :					Optional[int]      		=					parser.parse_args([]						)
														self.assertEqual(args.foo    ,						'''toto'''						)

														A      :					Dict      		=					parser.parse_args(['''--foo''', '''titi''']						)
														self.assertEqual(args.foo    ,						'''titi'''						)

														A      :					Optional[int]      		=					parser.parse_args(['''--foo''', '''42''']						)
														self.assertEqual(args.foo    ,						42						)




							def       snake_case			(					self						)		->       List[str]:
														A      :					Any      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Optional[int]      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo_int'''    ,						nargs='''+'''    ,						default=[]    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--bar_int'''    ,						nargs='''+'''    ,						default=[1, 2, 3]    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--foo_str'''    ,						nargs='''+'''    ,						default=['''Hallo''', '''Bonjour''', '''Hello''']    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--foo_float'''    ,						nargs='''+'''    ,						default=[0.1, 0.2, 0.3]    ,						type=__UpperCAmelCase						)

														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

														A      :					int      		=					parser.parse_args([]						)
														self.assertEqual(
														    __UpperCAmelCase    ,						Namespace(foo_int=[]    ,						bar_int=[1, 2, 3]    ,						foo_str=['''Hallo''', '''Bonjour''', '''Hello''']    ,						foo_float=[0.1, 0.2, 0.3]						)    ,						)

														A      :					Tuple      		=					parser.parse_args('''--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'''.split()						)
														self.assertEqual(__UpperCAmelCase    ,						Namespace(foo_int=[1]    ,						bar_int=[2, 3]    ,						foo_str=['''a''', '''b''', '''c''']    ,						foo_float=[0.1, 0.7]						)						)




							def       snake_case			(					self						)		->       Union[str, Any]:
														A      :					int      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo'''    ,						default=__UpperCAmelCase    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--bar'''    ,						default=__UpperCAmelCase    ,						type=__UpperCAmelCase    ,						help='''help message'''						)
														expected.add_argument('''--baz'''    ,						default=__UpperCAmelCase    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--ces'''    ,						nargs='''+'''    ,						default=[]    ,						type=__UpperCAmelCase						)
														expected.add_argument('''--des'''    ,						nargs='''+'''    ,						default=[]    ,						type=__UpperCAmelCase						)

														A      :					int      		=					[OptionalExample]
														if is_python_no_less_than_3_10:
																					dataclass_types.append(__UpperCAmelCase						)

														for dataclass_type in dataclass_types:
																					A      :					Any      		=					HfArgumentParser(__UpperCAmelCase						)

																					self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)

																					A      :					Dict      		=					parser.parse_args([]						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=__UpperCAmelCase    ,						bar=__UpperCAmelCase    ,						baz=__UpperCAmelCase    ,						ces=[]    ,						des=[]						)						)

																					A      :					str      		=					parser.parse_args('''--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'''.split()						)
																					self.assertEqual(__UpperCAmelCase    ,						Namespace(foo=12    ,						bar=3.1_4    ,						baz='''42'''    ,						ces=['''a''', '''b''', '''c''']    ,						des=[1, 2, 3]						)						)




							def       snake_case			(					self						)		->       List[Any]:
														A      :					Optional[int]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Tuple      		=					argparse.ArgumentParser()
														expected.add_argument('''--required_list'''    ,						nargs='''+'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument('''--required_str'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument(
														    '''--required_enum'''    ,						type=make_choice_type_function(['''titi''', '''toto''']						)    ,						choices=['''titi''', '''toto''']    ,						required=__UpperCAmelCase    ,						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       List[Any]:
														A      :					Optional[Any]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					str      		=					argparse.ArgumentParser()
														expected.add_argument('''--foo'''    ,						type=__UpperCAmelCase    ,						required=__UpperCAmelCase						)
														expected.add_argument(
														    '''--required_enum'''    ,						type=make_choice_type_function(['''titi''', '''toto''']						)    ,						choices=['''titi''', '''toto''']    ,						required=__UpperCAmelCase    ,						)
														expected.add_argument('''--opt'''    ,						type=__UpperCAmelCase    ,						default=__UpperCAmelCase						)
														expected.add_argument('''--baz'''    ,						default='''toto'''    ,						type=__UpperCAmelCase    ,						help='''help message'''						)
														expected.add_argument('''--foo_str'''    ,						nargs='''+'''    ,						default=['''Hallo''', '''Bonjour''', '''Hello''']    ,						type=__UpperCAmelCase						)
														self.argparsersEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       List[Any]:
														A      :					Optional[Any]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Optional[int]      		=					{
														    '''foo''': 12,
														    '''bar''': 3.1_4,
														    '''baz''': '''42''',
														    '''flag''': True,
														}

														A      :					Optional[int]      		=					parser.parse_dict(__UpperCAmelCase						)[0]
														A      :					Tuple      		=					BasicExample(**__UpperCAmelCase						)
														self.assertEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Tuple:
														A      :					Tuple      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Optional[Any]      		=					{
														    '''foo''': 12,
														    '''bar''': 3.1_4,
														    '''baz''': '''42''',
														    '''flag''': True,
														    '''extra''': 42,
														}

														self.assertRaises(__UpperCAmelCase    ,						parser.parse_dict    ,						__UpperCAmelCase    ,						allow_extra_keys=__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[int]:
														A      :					Tuple      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Optional[int]      		=					{
														    '''foo''': 12,
														    '''bar''': 3.1_4,
														    '''baz''': '''42''',
														    '''flag''': True,
														}
														with tempfile.TemporaryDirectory() as tmp_dir:
																					A      :					List[str]      		=					os.path.join(__UpperCAmelCase    ,						'''temp_json'''						)
																					os.mkdir(__UpperCAmelCase						)
																					with open(temp_local_path + '''.json'''    ,						'''w+'''						) as f:
																												json.dump(__UpperCAmelCase    ,						__UpperCAmelCase						)
																					A      :					Dict      		=					parser.parse_yaml_file(Path(temp_local_path + '''.json'''						)						)[0]

														A      :					Optional[Any]      		=					BasicExample(**__UpperCAmelCase						)
														self.assertEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[int]:
														A      :					Optional[int]      		=					HfArgumentParser(__UpperCAmelCase						)

														A      :					Tuple      		=					{
														    '''foo''': 12,
														    '''bar''': 3.1_4,
														    '''baz''': '''42''',
														    '''flag''': True,
														}
														with tempfile.TemporaryDirectory() as tmp_dir:
																					A      :					Tuple      		=					os.path.join(__UpperCAmelCase    ,						'''temp_yaml'''						)
																					os.mkdir(__UpperCAmelCase						)
																					with open(temp_local_path + '''.yaml'''    ,						'''w+'''						) as f:
																												yaml.dump(__UpperCAmelCase    ,						__UpperCAmelCase						)
																					A      :					List[str]      		=					parser.parse_yaml_file(Path(temp_local_path + '''.yaml'''						)						)[0]
														A      :					List[str]      		=					BasicExample(**__UpperCAmelCase						)
														self.assertEqual(__UpperCAmelCase    ,						__UpperCAmelCase						)






							def       snake_case			(					self						)		->       int:
														A      :					Dict      		=					HfArgumentParser(__UpperCAmelCase						)
														self.assertIsNotNone(__UpperCAmelCase						)









from typing import Tuple, Union

from ...modeling_outputs import BackboneOutput
from ...modeling_utils import PreTrainedModel
from ...utils import is_timm_available, is_torch_available, requires_backends
from ...utils.backbone_utils import BackboneMixin
from .configuration_timm_backbone import TimmBackboneConfig


if is_timm_available():
		import timm


if is_torch_available():
		from torch import Tensor







class 					__lowercase  (						_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE				):





							"""simple docstring"""

							UpperCAmelCase_						:		int								=	'''pixel_values'''
							UpperCAmelCase_						:		List[str]								=	False
							UpperCAmelCase_						:		Tuple								=	TimmBackboneConfig




							def __init__(					self    ,						__UpperCAmelCase    ,						**__UpperCAmelCase						)		->       int:
														requires_backends(self    ,						'''timm'''						)
														super().__init__(__UpperCAmelCase						)
														A      :					List[str]      		=					config

														if config.backbone is None:
																					raise ValueError('''backbone is not set in the config. Please set it to a timm model name.'''						)

														if config.backbone not in timm.list_models():
																					raise ValueError(f'backbone {config.backbone} is not supported by timm.'						)

														if hasattr(__UpperCAmelCase    ,						'''out_features'''						) and config.out_features is not None:
																					raise ValueError('''out_features is not supported by TimmBackbone. Please use out_indices instead.'''						)

														A      :					str      		=					getattr(__UpperCAmelCase    ,						'''use_pretrained_backbone'''    ,						__UpperCAmelCase						)
														if pretrained is None:
																					raise ValueError('''use_pretrained_backbone is not set in the config. Please set it to True or False.'''						)

														# We just take the final layer by default. This matches the default for the transformers models.
														A      :					Optional[int]      		=					config.out_indices if getattr(__UpperCAmelCase    ,						'''out_indices'''    ,						__UpperCAmelCase						) is not None else (-1,)

														A      :					str      		=					timm.create_model(
														    config.backbone    ,						pretrained=__UpperCAmelCase    ,						features_only=config.features_only    ,						in_chans=config.num_channels    ,						out_indices=__UpperCAmelCase    ,						**__UpperCAmelCase    ,						)
														# These are used to control the output of the model when called. If output_hidden_states is True, then
														# return_layers is modified to include all layers.
														A      :					str      		=					self._backbone.return_layers
														A      :					Any      		=					{layer['''module''']: str(__UpperCAmelCase						) for i, layer in enumerate(self._backbone.feature_info.info						)}
														super()._init_backbone(__UpperCAmelCase						)




							@classmethod
							def       snake_case			(					cls    ,						__UpperCAmelCase    ,						*__UpperCAmelCase    ,						**__UpperCAmelCase						)		->       Any:
														requires_backends(cls    ,						['''vision''', '''timm''']						)
														from ...models.timm_backbone import TimmBackboneConfig

														A      :					Optional[Any]      		=					kwargs.pop('''config'''    ,						TimmBackboneConfig()						)

														A      :					str      		=					kwargs.pop('''use_timm_backbone'''    ,						__UpperCAmelCase						)
														if not use_timm:
																					raise ValueError('''use_timm_backbone must be True for timm backbones'''						)

														A      :					Optional[int]      		=					kwargs.pop('''num_channels'''    ,						config.num_channels						)
														A      :					List[str]      		=					kwargs.pop('''features_only'''    ,						config.features_only						)
														A      :					Optional[int]      		=					kwargs.pop('''use_pretrained_backbone'''    ,						config.use_pretrained_backbone						)
														A      :					Optional[int]      		=					kwargs.pop('''out_indices'''    ,						config.out_indices						)
														A      :					int      		=					TimmBackboneConfig(
														    backbone=__UpperCAmelCase    ,						num_channels=__UpperCAmelCase    ,						features_only=__UpperCAmelCase    ,						use_pretrained_backbone=__UpperCAmelCase    ,						out_indices=__UpperCAmelCase    ,						)
														return super()._from_config(__UpperCAmelCase    ,						**__UpperCAmelCase						)




							def       snake_case			(					self    ,						__UpperCAmelCase						)		->       Any:
														pass






							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase=None    ,						__UpperCAmelCase=None    ,						__UpperCAmelCase=None    ,						**__UpperCAmelCase						)		->       Union[BackboneOutput, Tuple[Tensor, ...]]:
														A      :					Optional[int]      		=					return_dict if return_dict is not None else self.config.use_return_dict
														A      :					str      		=					(
														    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
														)
														A      :					Any      		=					output_attentions if output_attentions is not None else self.config.output_attentions

														if output_attentions:
																					raise ValueError('''Cannot output attentions for timm backbones at the moment'''						)

														if output_hidden_states:
																					# We modify the return layers to include all the stages of the backbone
																					A      :					Dict      		=					self._all_layers
																					A      :					int      		=					self._backbone(__UpperCAmelCase    ,						**__UpperCAmelCase						)
																					A      :					Any      		=					self._return_layers
																					A      :					Union[str, Any]      		=					tuple(hidden_states[i] for i in self.out_indices						)
														else:
																					A      :					Optional[int]      		=					self._backbone(__UpperCAmelCase    ,						**__UpperCAmelCase						)
																					A      :					List[Any]      		=					None

														A      :					str      		=					tuple(__UpperCAmelCase						)
														A      :					int      		=					tuple(__UpperCAmelCase						) if hidden_states is not None else None

														if not return_dict:
																					A      :					Optional[Any]      		=					(feature_maps,)
																					if output_hidden_states:
																												A      :					Tuple      		=					output + (hidden_states,)
																					return output

														return BackboneOutput(feature_maps=__UpperCAmelCase    ,						hidden_states=__UpperCAmelCase    ,						attentions=__UpperCAmelCase						)






