code: 
  
  
  import unittest
  
  from transformers import SpeechaTextaConfig
  from transformers.testing_utils import is_torch_available, require_torch, torch_device
  
  from ...generation.test_utils import GenerationTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
      import torch
  
      from transformers.models.speech_to_text_a.modeling_speech_to_text_a import (
          SpeechaTextaDecoder,
          SpeechaTextaForCausalLM,
      )
  
  
  
  
  
  
  
  @require_torch
  class   lowerCAmelCase__ :
  
  
  
  
       '''simple docstring'''
  
  
       def __init__(		self				,		__lowerCamelCase				,		__lowerCamelCase=9_9				,		__lowerCamelCase=1_3				,		__lowerCamelCase=1_6				,		__lowerCamelCase=7				,		__lowerCamelCase=True				,		__lowerCamelCase=True				,		__lowerCamelCase=True				,		__lowerCamelCase=False				,		__lowerCamelCase=True				,		__lowerCamelCase=2				,		__lowerCamelCase=3_2				,		__lowerCamelCase=4				,		__lowerCamelCase=4				,		__lowerCamelCase=3_0				,		__lowerCamelCase=0				,		__lowerCamelCase=1				,		__lowerCamelCase=2				,		__lowerCamelCase=None				,		)    ->       Union[str, Any]:
              _A   : Optional[Any]       					=				parent
              _A   : Optional[Any]       					=				batch_size
              _A   : Tuple       					=				decoder_seq_length
              # For common tests
              _A   : int       					=				self.decoder_seq_length
              _A   : Union[str, Any]       					=				is_training
              _A   : List[str]       					=				use_attention_mask
              _A   : List[Any]       					=				use_labels
  
              _A   : Tuple       					=				vocab_size
              _A   : int       					=				d_model
              _A   : Optional[Any]       					=				d_model
              _A   : Any       					=				decoder_layers
              _A   : Dict       					=				decoder_layers
              _A   : List[Any]       					=				decoder_ffn_dim
              _A   : List[Any]       					=				decoder_attention_heads
              _A   : Union[str, Any]       					=				decoder_attention_heads
              _A   : Any       					=				eos_token_id
              _A   : List[str]       					=				bos_token_id
              _A   : str       					=				pad_token_id
              _A   : List[str]       					=				decoder_start_token_id
              _A   : List[Any]       					=				use_cache
              _A   : Dict       					=				max_position_embeddings
  
              _A   : Optional[Any]       					=				None
              _A   : Tuple       					=				decoder_seq_length
              _A   : Optional[int]       					=				2
              _A   : Tuple       					=				1
  
  
       def 				_lowerCamelCase				(		self)    ->       List[str]:
              _A   : Any       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		self.vocab_size)
  
              _A   : List[Any]       					=				None
              if self.use_attention_mask:
                     _A   : List[Any]       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		vocab_size=2)
  
              _A   : int       					=				None
              if self.use_labels:
                     _A   : int       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		self.vocab_size)
  
              _A   : str       					=				SpeechaTextaConfig(
                  vocab_size=self.vocab_size				,		d_model=self.d_model				,		decoder_layers=self.decoder_layers				,		decoder_ffn_dim=self.decoder_ffn_dim				,		decoder_attention_heads=self.decoder_attention_heads				,		eos_token_id=self.eos_token_id				,		bos_token_id=self.bos_token_id				,		use_cache=self.use_cache				,		pad_token_id=self.pad_token_id				,		decoder_start_token_id=self.decoder_start_token_id				,		max_position_embeddings=self.max_position_embeddings				,		)
  
              return (
                  config,
                  input_ids,
                  attention_mask,
                  lm_labels,
              )
  
  
       def 				_lowerCamelCase				(		self				,		__lowerCamelCase				,		__lowerCamelCase				,		__lowerCamelCase				,		__lowerCamelCase				,		)    ->       Optional[Any]:
              _A   : Union[str, Any]       					=				True
              _A   : Any       					=				SpeechaTextaDecoder(config=__lowerCamelCase).to(__lowerCamelCase).eval()
              _A   : Dict       					=				input_ids[:2]
  
              input_ids[input_ids == 0] += 1
              # first forward pass
              _A   : List[str]       					=				model(__lowerCamelCase				,		use_cache=__lowerCamelCase)
              _A   : Dict       					=				model(__lowerCamelCase)
              _A   : Union[str, Any]       					=				model(__lowerCamelCase				,		use_cache=__lowerCamelCase)
  
              self.parent.assertTrue(len(__lowerCamelCase) == len(__lowerCamelCase))
              self.parent.assertTrue(len(__lowerCamelCase) == len(__lowerCamelCase) + 1)
  
              _A   : Dict       					=				outputs["past_key_values"]
  
              # create hypothetical next token and extent to next_input_ids
              _A   : Union[str, Any]       					=				ids_tensor((2, 1)				,		config.vocab_size - 1) + 1
  
              # append to next input_ids and
              _A   : List[str]       					=				torch.cat([input_ids, next_tokens]				,		dim=-1)
  
              print(__lowerCamelCase)
  
              _A   : Tuple       					=				model(__lowerCamelCase)["last_hidden_state"]
              _A   : Tuple       					=				model(__lowerCamelCase				,		past_key_values=__lowerCamelCase)["last_hidden_state"]
  
              # select random slice
              _A   : Optional[Any]       					=				ids_tensor((1,)				,		output_from_past.shape[-1]).item()
              _A   : int       					=				output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
              _A   : Optional[Any]       					=				output_from_past[:, 0, random_slice_idx].detach()
  
              # test that outputs are equal for slice
              assert torch.allclose(__lowerCamelCase				,		__lowerCamelCase				,		atol=1e-3)
  
  
       def 				_lowerCamelCase				(		self)    ->       List[Any]:
              _A   : Tuple       					=				self.prepare_config_and_inputs()
              (
                  _A    
              )   : Dict       					=				config_and_inputs
  
              _A   : Dict       					=				{
                  "input_ids": input_ids,
                  "attention_mask": attention_mask,
              }
              return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class   lowerCAmelCase__ (       a  ,					a  ,					a  ,					unittest.TestCase):
  
  
  
  
       '''simple docstring'''
       __SCREAMING_SNAKE_CASE						    =				(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
       __SCREAMING_SNAKE_CASE						    =				(SpeechaTextaForCausalLM,) if is_torch_available() else ()
       __SCREAMING_SNAKE_CASE						    =				{"text-generation": SpeechaTextaForCausalLM} if is_torch_available() else {}
       __SCREAMING_SNAKE_CASE						    =				True
       __SCREAMING_SNAKE_CASE						    =				False
  
  
       def 				_lowerCamelCase				(		self				,		)    ->       List[str]:
              _A   : List[Any]       					=				SpeechaTextaStandaloneDecoderModelTester(self				,		is_training=__lowerCamelCase)
              _A   : Union[str, Any]       					=				ConfigTester(self				,		config_class=__lowerCamelCase)
  
  
       def 				_lowerCamelCase				(		self)    ->       Optional[int]:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       Optional[Any]:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       Tuple:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       List[Any]:
              self.config_tester.run_common_tests()
  
  
       def 				_lowerCamelCase				(		self)    ->       str:
              _A   : Optional[Any]       					=				self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_decoder_model_past(*__lowerCamelCase)
  
  
       def 				_lowerCamelCase				(		self)    ->       str:
              return
style_context: 
  
  
  import cva
  import numpy as np
  
  from digital_image_processing.filters.convolve import img_convolve
  from digital_image_processing.filters.sobel_filter import sobel_filter
  
  lowerCAmelCase__   	=				1_80
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Optional[Any]		):
         _A   : int       					=				k_size // 2
         _A					,    _A   : Tuple       					=				np.mgrid[0 - center : k_size - center, 0 - center : k_size - center]
         _A   : Union[str, Any]       					=				(
             1
             / (2 * np.pi * sigma)
             * np.exp(-(np.square(UpperCamelCase__		) + np.square(UpperCamelCase__		)) / (2 * np.square(UpperCamelCase__		))		)
         )
         return g
  def 							_UpperCAmelCase       (UpperCamelCase__  :						str       ,							UpperCamelCase__  :						Any       ,							UpperCamelCase__  :						Tuple		):
         _A   : Optional[int]       					=				np.zeros(UpperCamelCase__		)
  
         for row in range(1       ,							image_shape[0] - 1		):
                for col in range(1       ,							image_shape[1] - 1		):
                       _A   : Dict       					=				gradient_direction[row, col]
  
                       if (
                           0 <= direction < PI / 8
                           or 15 * PI / 8 <= direction <= 2 * PI
                           or 7 * PI / 8 <= direction <= 9 * PI / 8
                       ):
                              _A   : Dict       					=				sobel_grad[row, col - 1]
                              _A   : Any       					=				sobel_grad[row, col + 1]
                              if sobel_grad[row, col] >= w and sobel_grad[row, col] >= e:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
                       elif (
                           PI / 8 <= direction < 3 * PI / 8
                           or 9 * PI / 8 <= direction < 11 * PI / 8
                       ):
                              _A   : List[str]       					=				sobel_grad[row + 1, col - 1]
                              _A   : str       					=				sobel_grad[row - 1, col + 1]
                              if sobel_grad[row, col] >= sw and sobel_grad[row, col] >= ne:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
                       elif (
                           3 * PI / 8 <= direction < 5 * PI / 8
                           or 11 * PI / 8 <= direction < 13 * PI / 8
                       ):
                              _A   : Any       					=				sobel_grad[row - 1, col]
                              _A   : int       					=				sobel_grad[row + 1, col]
                              if sobel_grad[row, col] >= n and sobel_grad[row, col] >= s:
                                     _A   : Any       					=				sobel_grad[row, col]
  
                       elif (
                           5 * PI / 8 <= direction < 7 * PI / 8
                           or 13 * PI / 8 <= direction < 15 * PI / 8
                       ):
                              _A   : List[str]       					=				sobel_grad[row - 1, col - 1]
                              _A   : Optional[Any]       					=				sobel_grad[row + 1, col + 1]
                              if sobel_grad[row, col] >= nw and sobel_grad[row, col] >= se:
                                     _A   : List[Any]       					=				sobel_grad[row, col]
  
         return destination
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						str       ,							UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Any		):
         for row in range(1       ,							image_shape[0] - 1		):
                for col in range(1       ,							image_shape[1] - 1		):
                       if destination[row, col] >= threshold_high:
                              _A   : Optional[int]       					=				strong
                       elif destination[row, col] <= threshold_low:
                              _A   : Optional[int]       					=				0
                       else:
                              _A   : Union[str, Any]       					=				weak
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Optional[Any]       ,							UpperCamelCase__  :						Optional[int]       ,							UpperCamelCase__  :						Any       ,							UpperCamelCase__  :						Any		):
         for row in range(1       ,							image_shape[0]		):
                for col in range(1       ,							image_shape[1]		):
                       if destination[row, col] == weak:
                              if 255 in (
                                  destination[row, col + 1],
                                  destination[row, col - 1],
                                  destination[row - 1, col],
                                  destination[row + 1, col],
                                  destination[row - 1, col - 1],
                                  destination[row + 1, col - 1],
                                  destination[row - 1, col + 1],
                                  destination[row + 1, col + 1],
                              ):
                                     _A   : str       					=				strong
                              else:
                                     _A   : Any       					=				0
  def 							_UpperCAmelCase       (UpperCamelCase__  :						Dict       ,							UpperCamelCase__  :						int=15       ,							UpperCamelCase__  :						Dict=30       ,							UpperCamelCase__  :						int=128       ,							UpperCamelCase__  :						Union[str, Any]=255		):
         # gaussian_filter
         _A   : Union[str, Any]       					=				img_convolve(UpperCamelCase__       ,							gen_gaussian_kernel(9       ,							sigma=1.4		)		)
         # get the gradient and degree by sobel_filter
         _A					,    _A   : Dict       					=				sobel_filter(UpperCamelCase__		)
         _A   : Tuple       					=				PI + np.radadeg(UpperCamelCase__		)
  
         _A   : Optional[int]       					=				suppress_non_maximum(image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         detect_high_low_threshold(
             image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         track_edge(image.shape       ,							UpperCamelCase__       ,							UpperCamelCase__       ,							UpperCamelCase__		)
  
         return destination
  
  
  if __name__ == "__main__":
      # read original image in gray mode
      lowerCAmelCase__   	=				cva.imread(R'../image_data/lena.jpg', 0)
      # canny edge detection
      lowerCAmelCase__   	=				canny(lena)
      cva.imshow('canny', canny_destination)
      cva.waitKey(0)
  