


import copy
import inspect

from transformers.testing_utils import require_torch, torch_device
from transformers.utils.backbone_utils import BackboneType




@require_torch
class  A_ :







 """simple docstring"""





 _UpperCamelCase					:			List[str]     	=       ()
 _UpperCamelCase					:			str     	=       True
 def 	_UpperCamelCase     (      self       :			Dict					)     ->      List[Any]:
      UpperCAmelCase    :					Optional[int]			=      self.config_class

      # test default config
      UpperCAmelCase    :					int			=      config_class()
      self.assertIsNotNone(__snake_case					)
      UpperCAmelCase    :					Optional[Any]			=      ["stem"] + [f'stage{idx}' for idx in range(1							,     len(config.depths					) + 1					)]
      self.assertEqual(config.stage_names							,     __snake_case					)
      self.assertTrue(set(config.out_features					).issubset(set(config.stage_names					)					)					)

      # Test out_features and out_indices are correctly set
      # out_features and out_indices both None
      UpperCAmelCase    :					Optional[int]			=      config_class(out_features=__snake_case							,     out_indices=__snake_case					)
      self.assertEqual(config.out_features							,     [config.stage_names[-1]]					)
      self.assertEqual(config.out_indices							,     [len(config.stage_names					) - 1]					)

      # out_features and out_indices both set
      UpperCAmelCase    :					Tuple			=      config_class(out_features=["stem", "stage1"]							,     out_indices=[0, 1]					)
      self.assertEqual(config.out_features							,     ["stem", "stage1"]					)
      self.assertEqual(config.out_indices							,     [0, 1]					)

      # Only out_features set
      UpperCAmelCase    :					Optional[int]			=      config_class(out_features=["stage1", "stage3"]					)
      self.assertEqual(config.out_features							,     ["stage1", "stage3"]					)
      self.assertEqual(config.out_indices							,     [1, 3]					)

      # Only out_indices set
      UpperCAmelCase    :					List[str]			=      config_class(out_indices=[0, 2]					)
      self.assertEqual(config.out_features							,     [config.stage_names[0], config.stage_names[2]]					)
      self.assertEqual(config.out_indices							,     [0, 2]					)

      # Error raised when out_indices do not correspond to out_features
      with self.assertRaises(__snake_case					):
           UpperCAmelCase    :					int			=      config_class(out_features=["stage1", "stage2"]							,     out_indices=[0, 2]					)
 def 	_UpperCamelCase     (      self       :			Any					)     ->      int:
      UpperCAmelCase    :					str			=      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           UpperCAmelCase    :					str			=      model_class(__snake_case					)
           UpperCAmelCase    :					List[Any]			=      inspect.signature(model.forward					)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           UpperCAmelCase    :					List[str]			=      [*signature.parameters.keys()]
           UpperCAmelCase    :					str			=      ["pixel_values"]
           self.assertListEqual(arg_names[:1]							,     __snake_case					)
 def 	_UpperCamelCase     (      self       :			Any					)     ->      Optional[Any]:
      UpperCAmelCase    :					str			=      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           UpperCAmelCase    :					Union[str, Any]			=      model_class(__snake_case					)
           self.assertEqual(len(model.channels					)							,     len(config.out_features					)					)
           UpperCAmelCase    :					List[Any]			=      model.num_features
           UpperCAmelCase    :					int			=      [config.stage_names.index(__snake_case					) for feat in config.out_features]
           UpperCAmelCase    :					Any			=      [num_features[idx] for idx in out_indices]
           self.assertListEqual(model.channels							,     __snake_case					)

           UpperCAmelCase    :					int			=      copy.deepcopy(__snake_case					)
           UpperCAmelCase    :					str			=      None
           UpperCAmelCase    :					Any			=      model_class(__snake_case					)
           self.assertEqual(len(model.channels					)							,     1					)
           self.assertListEqual(model.channels							,     [num_features[-1]]					)

           UpperCAmelCase    :					Optional[int]			=      copy.deepcopy(__snake_case					)
           UpperCAmelCase    :					Optional[Any]			=      None
           UpperCAmelCase    :					int			=      model_class(__snake_case					)
           self.assertEqual(len(model.channels					)							,     1					)
           self.assertListEqual(model.channels							,     [num_features[-1]]					)
 def 	_UpperCamelCase     (      self       :			Tuple					)     ->      List[Any]:
      UpperCAmelCase    :					int			=      self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           UpperCAmelCase    :					Optional[int]			=      model_class(__snake_case					)
           model.to(__snake_case					)
           model.eval()
           UpperCAmelCase    :					Optional[int]			=      model(**__snake_case					)

           self.assertEqual(len(result.feature_maps					)							,     len(config.out_features					)					)
           self.assertEqual(len(model.channels					)							,     len(config.out_features					)					)
           self.assertEqual(len(result.feature_maps					)							,     len(config.out_indices					)					)
           self.assertEqual(len(model.channels					)							,     len(config.out_indices					)					)

           # Check output of last stage is taken if out_features=None, out_indices=None
           UpperCAmelCase    :					List[Any]			=      copy.deepcopy(__snake_case					)
           UpperCAmelCase    :					str			=      None
           UpperCAmelCase    :					int			=      model_class(__snake_case					)
           model.to(__snake_case					)
           model.eval()
           UpperCAmelCase    :					Union[str, Any]			=      model(**__snake_case					)

           self.assertEqual(len(result.feature_maps					)							,     1					)
           self.assertEqual(len(model.channels					)							,     1					)

           UpperCAmelCase    :					Tuple			=      copy.deepcopy(__snake_case					)
           UpperCAmelCase    :					List[Any]			=      None
           UpperCAmelCase    :					Any			=      model_class(__snake_case					)
           model.to(__snake_case					)
           model.eval()
           UpperCAmelCase    :					Union[str, Any]			=      model(**__snake_case					)

           self.assertEqual(len(result.feature_maps					)							,     1					)
           self.assertEqual(len(model.channels					)							,     1					)

           # Check backbone can be initialized with fresh weights
           UpperCAmelCase    :					List[str]			=      copy.deepcopy(__snake_case					)
           UpperCAmelCase    :					List[str]			=      False
           UpperCAmelCase    :					int			=      model_class(__snake_case					)
           model.to(__snake_case					)
           model.eval()
           UpperCAmelCase    :					Union[str, Any]			=      model(**__snake_case					)
 def 	_UpperCamelCase     (      self       :			List[Any]					)     ->      int:
      UpperCAmelCase    :					Union[str, Any]			=      self.model_tester.prepare_config_and_inputs_for_common()

      for backbone_class in self.all_model_classes:
           UpperCAmelCase    :					Any			=      backbone_class(__snake_case					)

           self.assertTrue(hasattr(__snake_case							,     "backbone_type"					)					)
           self.assertTrue(hasattr(__snake_case							,     "stage_names"					)					)
           self.assertTrue(hasattr(__snake_case							,     "num_features"					)					)
           self.assertTrue(hasattr(__snake_case							,     "out_indices"					)					)
           self.assertTrue(hasattr(__snake_case							,     "out_features"					)					)
           self.assertTrue(hasattr(__snake_case							,     "out_feature_channels"					)					)
           self.assertTrue(hasattr(__snake_case							,     "channels"					)					)

           self.assertIsInstance(backbone.backbone_type							,     __snake_case					)
           # Verify num_features has been initialized in the backbone init
           self.assertIsNotNone(backbone.num_features					)
           self.assertTrue(len(backbone.channels					) == len(backbone.out_indices					)					)
           self.assertTrue(len(backbone.stage_names					) == len(backbone.num_features					)					)
           self.assertTrue(len(backbone.channels					) <= len(backbone.num_features					)					)
           self.assertTrue(len(backbone.out_feature_channels					) == len(backbone.stage_names					)					)

 def 	_UpperCamelCase     (      self       :			Union[str, Any]					)     ->      Any:
      UpperCAmelCase    :					List[str]			=      self.model_tester.prepare_config_and_inputs_for_common()
      UpperCAmelCase    :					Dict			=      inputs_dict["pixel_values"].shape[0]

      for backbone_class in self.all_model_classes:
           UpperCAmelCase    :					str			=      backbone_class(__snake_case					)
           backbone.to(__snake_case					)
           backbone.eval()

           UpperCAmelCase    :					List[str]			=      backbone(**__snake_case					)

           # Test default outputs and verify feature maps
           self.assertIsInstance(outputs.feature_maps							,     __snake_case					)
           self.assertTrue(len(outputs.feature_maps					) == len(backbone.channels					)					)
           for feature_map, n_channels in zip(outputs.feature_maps							,     backbone.channels					):
                self.assertTrue(feature_map.shape[:2]							,     (batch_size, n_channels)					)
           self.assertIsNone(outputs.hidden_states					)
           self.assertIsNone(outputs.attentions					)

           # Test output_hidden_states=True
           UpperCAmelCase    :					List[str]			=      backbone(**__snake_case							,     output_hidden_states=__snake_case					)
           self.assertIsNotNone(outputs.hidden_states					)
           self.assertTrue(len(outputs.hidden_states					)							,     len(backbone.stage_names					)					)
           for hidden_state, n_channels in zip(outputs.hidden_states							,     backbone.channels					):
                self.assertTrue(hidden_state.shape[:2]							,     (batch_size, n_channels)					)

           # Test output_attentions=True
           if self.has_attentions:
                UpperCAmelCase    :					int			=      backbone(**__snake_case							,     output_attentions=__snake_case					)
                self.assertIsNotNone(outputs.attentions					)










from __future__ import annotations

from collections.abc import Generator







def  A					(				UpperCAmelCase					):
					if not isinstance(UpperCAmelCase	,	UpperCAmelCase					) or n < 1:
										raise Exception("Sequence only defined for positive integers"					)

					yield n
					while n != 1:
										if n % 2 == 0:
															n //= 2
										else:
															_snake_case							:       Any												= 3 * n + 1
										yield n







def  A					(				):
					_snake_case							:       Dict												= 43
					_snake_case							:       List[str]												= tuple(collatz_sequence(UpperCAmelCase					)					)
					print(UpperCAmelCase					)
					print(F"""Collatz sequence from {n} took {len(UpperCAmelCase					)} steps."""					)


if __name__ == "__main__":
							main()