"""simple docstring"""







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      _SCREAMING_SNAKE_CASE							:



   '''simple docstring'''



   def __init__(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE=99 ,				_SCREAMING_SNAKE_CASE=13 ,				_SCREAMING_SNAKE_CASE=16 ,				_SCREAMING_SNAKE_CASE=7 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=32 ,				_SCREAMING_SNAKE_CASE=4 ,				_SCREAMING_SNAKE_CASE=4 ,				_SCREAMING_SNAKE_CASE=30 ,				_SCREAMING_SNAKE_CASE=0 ,				_SCREAMING_SNAKE_CASE=1 ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=None ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					parent
      __lowerCamelCase    		=					batch_size
      __lowerCamelCase    		=					decoder_seq_length
      # For common tests
      __lowerCamelCase    		=					self.decoder_seq_length
      __lowerCamelCase    		=					is_training
      __lowerCamelCase    		=					use_attention_mask
      __lowerCamelCase    		=					use_labels

      __lowerCamelCase    		=					vocab_size
      __lowerCamelCase    		=					d_model
      __lowerCamelCase    		=					d_model
      __lowerCamelCase    		=					decoder_layers
      __lowerCamelCase    		=					decoder_layers
      __lowerCamelCase    		=					decoder_ffn_dim
      __lowerCamelCase    		=					decoder_attention_heads
      __lowerCamelCase    		=					decoder_attention_heads
      __lowerCamelCase    		=					eos_token_id
      __lowerCamelCase    		=					bos_token_id
      __lowerCamelCase    		=					pad_token_id
      __lowerCamelCase    		=					decoder_start_token_id
      __lowerCamelCase    		=					use_cache
      __lowerCamelCase    		=					max_position_embeddings

      __lowerCamelCase    		=					None
      __lowerCamelCase    		=					decoder_seq_length
      __lowerCamelCase    		=					2
      __lowerCamelCase    		=					1







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					ids_tensor([self.batch_size, self.decoder_seq_length] ,				self.vocab_size	)

      __lowerCamelCase    		=					None
      if self.use_attention_mask:
         __lowerCamelCase    		=					ids_tensor([self.batch_size, self.decoder_seq_length] ,				vocab_size=2	)

      __lowerCamelCase    		=					None
      if self.use_labels:
         __lowerCamelCase    		=					ids_tensor([self.batch_size, self.decoder_seq_length] ,				self.vocab_size	)

      __lowerCamelCase    		=					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    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					True
      __lowerCamelCase    		=					SpeechaTextaDecoder(config=_SCREAMING_SNAKE_CASE	).to(_SCREAMING_SNAKE_CASE	).eval()
      __lowerCamelCase    		=					input_ids[:2]

      input_ids[input_ids == 0] += 1
      # first forward pass
      __lowerCamelCase    		=					model(_SCREAMING_SNAKE_CASE ,				use_cache=_SCREAMING_SNAKE_CASE	)
      __lowerCamelCase    		=					model(_SCREAMING_SNAKE_CASE	)
      __lowerCamelCase    		=					model(_SCREAMING_SNAKE_CASE ,				use_cache=_SCREAMING_SNAKE_CASE	)

      self.parent.assertTrue(len(_SCREAMING_SNAKE_CASE	) == len(_SCREAMING_SNAKE_CASE	)	)
      self.parent.assertTrue(len(_SCREAMING_SNAKE_CASE	) == len(_SCREAMING_SNAKE_CASE	) + 1	)

      __lowerCamelCase    		=					outputs['past_key_values']

      # create hypothetical next token and extent to next_input_ids
      __lowerCamelCase    		=					ids_tensor((2, 1) ,				config.vocab_size - 1	) + 1

      # append to next input_ids and
      __lowerCamelCase    		=					torch.cat([input_ids, next_tokens] ,				dim=-1	)

      print(_SCREAMING_SNAKE_CASE	)

      __lowerCamelCase    		=					model(_SCREAMING_SNAKE_CASE	)['last_hidden_state']
      __lowerCamelCase    		=					model(_SCREAMING_SNAKE_CASE ,				past_key_values=_SCREAMING_SNAKE_CASE	)['last_hidden_state']

      # select random slice
      __lowerCamelCase    		=					ids_tensor((1,) ,				output_from_past.shape[-1]	).item()
      __lowerCamelCase    		=					output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
      __lowerCamelCase    		=					output_from_past[:, 0, random_slice_idx].detach()

      # test that outputs are equal for slice
      assert torch.allclose(_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				atol=1E-3	)







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.prepare_config_and_inputs()
      (
          (
          __lowerCamelCase
      )		,(
          __lowerCamelCase
      )		,(
          __lowerCamelCase
      )		,(
          __lowerCamelCase
      )		,
      )    		=					config_and_inputs

      __lowerCamelCase    		=					{
          'input_ids': input_ids,
          'attention_mask': attention_mask,
      }
      return config, inputs_dict






@require_torch
class      _SCREAMING_SNAKE_CASE							(			UpperCAmelCase    ,				UpperCAmelCase    ,				UpperCAmelCase    ,				unittest.TestCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							Union[str, Any]    =    (SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
   __UpperCAmelCase	:							Any    =    (SpeechaTextaForCausalLM,) if is_torch_available() else ()
   __UpperCAmelCase	:							Union[str, Any]    =    {"text-generation": SpeechaTextaForCausalLM} if is_torch_available() else {}
   __UpperCAmelCase	:							int    =    True
   __UpperCAmelCase	:							Union[str, Any]    =    False







   def    _A				(	self ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					SpeechaTextaStandaloneDecoderModelTester(self ,				is_training=_SCREAMING_SNAKE_CASE	)
      __lowerCamelCase    		=					ConfigTester(self ,				config_class=_SCREAMING_SNAKE_CASE	)







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self	):


      '''simple docstring'''

      pass







   def    _A				(	self	):


      '''simple docstring'''

      self.config_tester.run_common_tests()







   def    _A				(	self	):


      '''simple docstring'''

      __lowerCamelCase    		=					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_decoder_model_past(*_SCREAMING_SNAKE_CASE	)







   def    _A				(	self	):


      '''simple docstring'''

      return









from __future__ import annotations




def        __UpperCamelCase     (      _A					:							int      ,  _A					:							list[int]      ,  _A					:							list[int]      ,  _A					:							int		)				->int:



							"""simple docstring"""

							# Base Case
							if counter == 0 or capacity == 0:
														return 0

							# If weight of the nth item is more than Knapsack of capacity,
							#   then this item cannot be included in the optimal solution,
							# else return the maximum of two cases:
							#   (1) nth item included
							#   (2) not included
							if weights[counter - 1] > capacity:
														return knapsack(_A      ,  _A      ,  _A      ,  counter - 1		)
							else:
														lowerCamelCase_								=capacity - weights[counter - 1]
														lowerCamelCase_								=values[counter - 1] + knapsack(
														    _A      ,  _A      ,  _A      ,  counter - 1		)
														lowerCamelCase_								=knapsack(_A      ,  _A      ,  _A      ,  counter - 1		)
														return max(_A      ,  _A		)


if __name__ == "__main__":
	import doctest

	doctest.testmod()
