





import importlib
import os
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Union

import torch

from ..utils import BaseOutput


_a 						=      '''scheduler_config.json'''






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						1
			lowerCAmelCase_							     =						2
			lowerCAmelCase_							     =						3
			lowerCAmelCase_							     =						4
			lowerCAmelCase_							     =						5
			lowerCAmelCase_							     =						6
			lowerCAmelCase_							     =						7
			lowerCAmelCase_							     =						8
			lowerCAmelCase_							     =						9
			lowerCAmelCase_							     =						10
			lowerCAmelCase_							     =						11
			lowerCAmelCase_							     =						12
			lowerCAmelCase_							     =						13
			lowerCAmelCase_							     =						14






@dataclass
class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						42






class 					__A    :

			'''simple docstring'''







			lowerCAmelCase_							     =						SCHEDULER_CONFIG_NAME
			lowerCAmelCase_							     =						[]
			lowerCAmelCase_							     =						True





			@classmethod
			def 		__lowerCamelCase				(    cls       ,  __lowerCAmelCase = None       ,  __lowerCAmelCase = None       ,  __lowerCAmelCase=False       ,  **__lowerCAmelCase       ,  ):



				'''simple docstring'''







				lowerCamelCase__				,	lowerCamelCase__				,	lowerCamelCase__								=		cls.load_config(
				    pretrained_model_name_or_path=__lowerCAmelCase       ,  subfolder=__lowerCAmelCase       ,  return_unused_kwargs=__lowerCAmelCase       ,  return_commit_hash=__lowerCAmelCase       ,  **__lowerCAmelCase       ,  )
				return cls.from_config(__lowerCAmelCase       ,  return_unused_kwargs=__lowerCAmelCase       ,  **__lowerCAmelCase							)





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase = False       ,  **__lowerCAmelCase							):



				'''simple docstring'''







				self.save_config(save_directory=__lowerCAmelCase       ,  push_to_hub=__lowerCAmelCase       ,  **__lowerCAmelCase							)





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return self._get_compatibles()





			@classmethod
			def 		__lowerCamelCase				(    cls							):



				'''simple docstring'''







				lowerCamelCase__								=		list(set([cls.__name__] + cls._compatibles							)							)
				lowerCamelCase__								=		importlib.import_module(__name__.split('''.'''							)[0]							)
				lowerCamelCase__								=		[
				    getattr(__lowerCAmelCase       ,  __lowerCAmelCase							) for c in compatible_classes_str if hasattr(__lowerCAmelCase       ,  __lowerCAmelCase							)
				]
				return compatible_classes










import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)


class   A			(unittest.TestCase    ):
			'''simple docstring'''




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







					"""simple docstring"""






					A__        =   ["""a""", """b""", """c"""]

					# Defaults to last layer if both are None
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[2]   )

					# Out indices set to match out features
					A__      ,			A__        =   get_aligned_output_features_output_indices(["""a""", """c"""]							,	__lowerCAmelCase							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features set to match out indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[0, 2]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[0, 2]   )

					# Out features selected from negative indices
					A__      ,			A__        =   get_aligned_output_features_output_indices(__lowerCAmelCase							,	[-3, -1]							,	__lowerCAmelCase   )
					self.assertEqual(__lowerCAmelCase							,	["""a""", """c"""]   )
					self.assertEqual(__lowerCAmelCase							,	[-3, -1]   )






			def    a_       (			self   :    Optional[Any]   )	->	Optional[Any]:







					"""simple docstring"""






					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	__lowerCAmelCase   )

					# Out features must be a list
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(("""a""", """b""")							,	(0, 1)							,	["""a""", """b"""]   )

					# Out features must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 1)							,	["""a"""]   )

					# Out indices must be a list or tuple
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	0							,	["""a""", """b"""]   )

					# Out indices must be a subset of stage names
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(__lowerCAmelCase							,	(0, 1)							,	["""a"""]   )

					# Out features and out indices must be the same length
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0,)							,	["""a""", """b""", """c"""]   )

					# Out features should match out indices
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""a""", """b"""]							,	(0, 2)							,	["""a""", """b""", """c"""]   )

					# Out features and out indices should be in order
					with self.assertRaises(__lowerCAmelCase   ):
							verify_out_features_out_indices(["""b""", """a"""]							,	(0, 1)							,	["""a""", """b"""]   )

					# Check passes with valid inputs
					verify_out_features_out_indices(["""a""", """b""", """d"""]							,	(0, 1, -1)							,	["""a""", """b""", """c""", """d"""]   )







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







					"""simple docstring"""






					A__        =   BackboneMixin()

					A__        =   ["""a""", """b""", """c"""]
					A__        =   ["""a""", """c"""]
					A__        =   [0, 2]

					# Check that the output features and indices are set correctly
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 2]   )

					# Check out features and indices are updated correctly
					A__        =   ["""a""", """b"""]
					self.assertEqual(backbone.out_features							,	["""a""", """b"""]   )
					self.assertEqual(backbone.out_indices							,	[0, 1]   )

					A__        =   [-3, -1]
					self.assertEqual(backbone.out_features							,	["""a""", """c"""]   )
					self.assertEqual(backbone.out_indices							,	[-3, -1]   )



