code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  def    __a (     UpperCAmelCase    )      ->bool:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	A							  =      [list(UpperCAmelCase    ) for row in matrix]
  	if matrix and isinstance(UpperCAmelCase       ,			UpperCAmelCase    ):
  		if isinstance(matrix[0]       ,			UpperCAmelCase    ):
  			A							  =      0
  			for row in matrix:
  				if prev_len == 0:
  					A							  =      len(UpperCAmelCase    )
  					A							  =      True
  				else:
  					A							  =      prev_len == len(UpperCAmelCase    )
  		else:
  			A							  =      True
  	else:
  		A							  =      False
  
  	return result
  
  
  
  
  def    __a (     UpperCAmelCase    )      ->None:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	if check_matrix(UpperCAmelCase    ) and len(UpperCAmelCase    ) > 0:
  		A							  =      [list(UpperCAmelCase    ) for row in a]
  		A							  =      len(UpperCAmelCase    )
  		if isinstance(a[0]       ,			UpperCAmelCase    ):
  			A							  =      len(a[0]    )
  		else:
  			for dat in a:
  				print(UpperCAmelCase    )
  			return
  
  		# horizotal printing increasing
  		for i in range(0       ,			UpperCAmelCase    ):
  			print(a[0][i]    )
  		# vertical printing down
  		for i in range(1       ,			UpperCAmelCase    ):
  			print(a[i][mat_col - 1]    )
  		# horizotal printing decreasing
  		if mat_row > 1:
  			for i in range(mat_col - 2       ,			-1       ,			-1    ):
  				print(a[mat_row - 1][i]    )
          # vertical printing up
  		for i in range(mat_row - 2       ,			0       ,			-1    ):
  			print(a[i][0]    )
  		A							  =      [row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
  		if len(UpperCAmelCase    ) > 0:
  			spiral_print_clockwise(UpperCAmelCase    )
  		else:
  			return
  	else:
  		print("""Not a valid matrix"""    )
  		return
  
  
  
  
  def    __a (     UpperCAmelCase    )      ->list[int]:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  
  	if matrix:
  		return list(matrix.pop(0    )    ) + spiral_traversal(list(zip(*UpperCAmelCase    )    )[::-1]    )
  	else:
  		return []
  
  
  # driver code
  if __name__ == "__main__":
  				import doctest
  
  				doctest.testmod()
  
  				_lowerCamelCase				:	Union[str, Any]				    =       [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
  				spiral_print_clockwise(a)
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  import tempfile
  import unittest
  
  import numpy as np
  import torch
  
  from diffusers import DiffusionPipeline
  from diffusers.models.attention_processor import Attention, AttnAddedKVProcessor
  
  
  
  class 							__UpperCAmelCase  (       unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[int]      ,      _lowerCAmelCase						:      bool = False      ):
  			A							  =      10
  
  			if only_cross_attention:
  				A							  =      12
  			else:
  				# when only cross attention is not set, the cross attention dim must be the same as the query dim
  				A							  =      query_dim
  
  			return {
  			    "query_dim": query_dim,
  			    "cross_attention_dim": cross_attention_dim,
  			    "heads": 2,
  			    "dim_head": 4,
  			    "added_kv_proj_dim": 6,
  			    "norm_num_groups": 1,
  			    "only_cross_attention": only_cross_attention,
  			    "processor": AttnAddedKVProcessor(),
  			}
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[int]      ,      _lowerCAmelCase						:      Dict      ,      _lowerCAmelCase						:      Any      ):
  			A							  =      2
  
  			A							  =      torch.rand(_lowerCAmelCase      ,      _lowerCAmelCase      ,      3      ,      2      )
  			A							  =      torch.rand(_lowerCAmelCase      ,      4      ,      _lowerCAmelCase      )
  			A							  =      None
  
  			return {
  			    "hidden_states": hidden_states,
  			    "encoder_hidden_states": encoder_hidden_states,
  			    "attention_mask": attention_mask,
  			}
  
  
  
  
  
  
  
  		def        A     (self						:      Optional[Any]      ):
  			# self and cross attention
  
  			torch.manual_seed(0      )
  
  			A							  =      self.get_constructor_arguments(only_cross_attention=_lowerCAmelCase      )
  			A							  =      Attention(**_lowerCAmelCase      )
  
  			self.assertTrue(attn.to_k is not None      )
  			self.assertTrue(attn.to_v is not None      )
  
  			A							  =      self.get_forward_arguments(
  			    query_dim=constructor_args["""query_dim"""]      ,      added_kv_proj_dim=constructor_args["""added_kv_proj_dim"""]      )
  
  			A							  =      attn(**_lowerCAmelCase      )
  
  			# only self attention
  
  			torch.manual_seed(0      )
  
  			A							  =      self.get_constructor_arguments(only_cross_attention=_lowerCAmelCase      )
  			A							  =      Attention(**_lowerCAmelCase      )
  
  			self.assertTrue(attn.to_k is None      )
  			self.assertTrue(attn.to_v is None      )
  
  			A							  =      self.get_forward_arguments(
  			    query_dim=constructor_args["""query_dim"""]      ,      added_kv_proj_dim=constructor_args["""added_kv_proj_dim"""]      )
  
  			A							  =      attn(**_lowerCAmelCase      )
  
  			self.assertTrue((only_cross_attn_out != self_and_cross_attn_out).all()      )
  
  
  
  
  
  
  class 							__UpperCAmelCase  (       unittest.TestCase						):
  
  
  
  
  
  
  
  		'''simple docstring'''
  
  
  
  
  
  
  
  		def        A     (self						:      Any      ):
  			A							  =      DiffusionPipeline.from_pretrained("""hf-internal-testing/tiny-stable-diffusion-pipe"""      ,      safety_checker=_lowerCAmelCase      )
  
  			A							  =      pipe(
  			    """foo"""      ,      num_inference_steps=2      ,      generator=torch.Generator("""cpu"""      ).manual_seed(0      )      ,      output_type="""np"""      ,      ).images
  
  			# the initial conversion succeeds
  			A							  =      DiffusionPipeline.from_pretrained(
  			    """hf-internal-testing/tiny-stable-diffusion-pipe"""      ,      device_map="""sequential"""      ,      safety_checker=_lowerCAmelCase      )
  
  			A							  =      pipe(
  			    """foo"""      ,      num_inference_steps=2      ,      generator=torch.Generator("""cpu"""      ).manual_seed(0      )      ,      output_type="""np"""      ,      ).images
  
  			with tempfile.TemporaryDirectory() as tmpdir:
  				# save the converted model
  				pipe.save_pretrained(_lowerCAmelCase      )
  
  				# can also load the converted weights
  				A							  =      DiffusionPipeline.from_pretrained(_lowerCAmelCase      ,      device_map="""sequential"""      ,      safety_checker=_lowerCAmelCase      )
  
  			A							  =      pipe(
  			    """foo"""      ,      num_inference_steps=2      ,      generator=torch.Generator("""cpu"""      ).manual_seed(0      )      ,      output_type="""np"""      ,      ).images
  
  			self.assertTrue(np.allclose(_lowerCAmelCase      ,      _lowerCAmelCase      ,      atol=1e-5      )      )
  			self.assertTrue(np.allclose(_lowerCAmelCase      ,      _lowerCAmelCase      ,      atol=1e-5      )      )
  
  