code: 
  
  from typing import Callable, Optional, Union
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import logging
  
  
  __A   :     int      =			logging.get_logger(__name__)
  
  __A   :     Optional[int]      =			{
      '''microsoft/prophetnet-large-uncased''': (
          '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
      ),
  }
  
  
  
  
  
  
  class    __A				(							lowerCAmelCase ):
      lowerCAmelCase_							:		List[Any]						=							"prophetnet"
      lowerCAmelCase_							:		List[Any]						=							["past_key_values"]
      lowerCAmelCase_							:		Any						=							{
          "num_attention_heads": "num_encoder_attention_heads",
      }
  
  
  
  
  
  
      def __init__(	self			:    str    ,				UpperCAmelCase_			:    Optional[float] = 0.1    ,				UpperCAmelCase_			:    Optional[Union[str, Callable]] = "gelu"    ,				UpperCAmelCase_			:    Optional[int] = 30522    ,				UpperCAmelCase_			:    Optional[int] = 1024    ,				UpperCAmelCase_			:    Optional[int] = 4096    ,				UpperCAmelCase_			:    Optional[int] = 12    ,				UpperCAmelCase_			:    Optional[int] = 16    ,				UpperCAmelCase_			:    Optional[int] = 4096    ,				UpperCAmelCase_			:    Optional[int] = 12    ,				UpperCAmelCase_			:    Optional[int] = 16    ,				UpperCAmelCase_			:    Optional[float] = 0.1    ,				UpperCAmelCase_			:    Optional[float] = 0.1    ,				UpperCAmelCase_			:    Optional[int] = 512    ,				UpperCAmelCase_			:    Optional[float] = 0.02    ,				UpperCAmelCase_			:    Optional[bool] = True    ,				UpperCAmelCase_			:    Optional[bool] = True    ,				UpperCAmelCase_			:    Optional[int] = 0    ,				UpperCAmelCase_			:    Optional[int] = 2    ,				UpperCAmelCase_			:    Optional[int] = 32    ,				UpperCAmelCase_			:    Optional[int] = 128    ,				UpperCAmelCase_			:    Optional[bool] = False    ,				UpperCAmelCase_			:    Optional[float] = 0.0    ,				UpperCAmelCase_			:    Optional[bool] = True    ,				UpperCAmelCase_			:    Optional[int] = 0    ,				UpperCAmelCase_			:    Optional[int] = 1    ,				UpperCAmelCase_			:    Optional[int] = 2    ,				**UpperCAmelCase_			:    Tuple    ,				):
          lowerCAmelCase				:			List[Any]    			=      vocab_size
          lowerCAmelCase				:			str    			=      hidden_size
          lowerCAmelCase				:			Optional[int]    			=      encoder_ffn_dim
          lowerCAmelCase				:			List[Any]    			=      num_encoder_layers
          lowerCAmelCase				:			str    			=      num_encoder_attention_heads
          lowerCAmelCase				:			Any    			=      decoder_ffn_dim
          lowerCAmelCase				:			Optional[Any]    			=      num_decoder_layers
          lowerCAmelCase				:			Optional[int]    			=      num_decoder_attention_heads
          lowerCAmelCase				:			Any    			=      max_position_embeddings
          lowerCAmelCase				:			Optional[Any]    			=      init_std  # Normal(0, this parameter)
          lowerCAmelCase				:			List[Any]    			=      activation_function
  
          # parameters for prophetnet
          lowerCAmelCase				:			Union[str, Any]    			=      ngram
          lowerCAmelCase				:			Tuple    			=      num_buckets
          lowerCAmelCase				:			str    			=      relative_max_distance
          lowerCAmelCase				:			Optional[Any]    			=      disable_ngram_loss
          lowerCAmelCase				:			Optional[int]    			=      eps
  
          # 3 Types of Dropout
          lowerCAmelCase				:			Tuple    			=      attention_dropout
          lowerCAmelCase				:			int    			=      activation_dropout
          lowerCAmelCase				:			Any    			=      dropout
  
          lowerCAmelCase				:			Any    			=      use_cache
  
          super().__init__(
              pad_token_id=UpperCAmelCase_    ,				bos_token_id=UpperCAmelCase_    ,				eos_token_id=UpperCAmelCase_    ,				is_encoder_decoder=UpperCAmelCase_    ,				add_cross_attention=UpperCAmelCase_    ,				decoder_start_token_id=UpperCAmelCase_    ,				**UpperCAmelCase_    ,				)
  
  
  
  
  
  
      @property
      def 	lowercase__ (	self			:    Any    ):
          return self.num_encoder_layers + self.num_decoder_layers
  
  
  
  
  
  
      @num_hidden_layers.setter
      def 	lowercase__ (	self			:    Optional[int]    ,				UpperCAmelCase_			:    Union[str, Any]    ):
          raise NotImplementedError(
              'This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'
              ' `num_decoder_layers`.'    )
  
  
  
  
  
  
style_context: 
  
  import torch
  
  from diffusers import KDPMaAncestralDiscreteScheduler
  from diffusers.utils import torch_device
  
  from .test_schedulers import SchedulerCommonTest
  
  
  
  
  
  
  class    __A				(							lowerCAmelCase ):
      lowerCAmelCase_							:		List[str]						=							(KDPMaAncestralDiscreteScheduler,)
      lowerCAmelCase_							:		Dict						=							10
  
  
  
  
  
  
      def 	lowercase__ (	self			:    Any    ,				**UpperCAmelCase_			:    List[Any]    ):
          lowerCAmelCase				:			int    			=      {
              'num_train_timesteps': 1100,
              'beta_start': 0.00_01,
              'beta_end': 0.02,
              'beta_schedule': 'linear',
          }
  
          config.update(**UpperCAmelCase_    )
          return config
  
  
  
  
  
  
      def 	lowercase__ (	self			:    Optional[Any]    ):
          for timesteps in [10, 50, 100, 1000]:
              self.check_over_configs(num_train_timesteps=UpperCAmelCase_    )
  
  
  
  
  
  
      def 	lowercase__ (	self			:    List[str]    ):
          for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]    ,				[0.00_02, 0.0_02, 0.02]    ):
              self.check_over_configs(beta_start=UpperCAmelCase_    ,				beta_end=UpperCAmelCase_    )
  
  
  
  
  
  
      def 	lowercase__ (	self			:    Optional[int]    ):
          for schedule in ["linear", "scaled_linear"]:
              self.check_over_configs(beta_schedule=UpperCAmelCase_    )
  
  
  
  
  
  
      def 	lowercase__ (	self			:    int    ):
          if torch_device == "mps":
              return
          lowerCAmelCase				:			Any    			=      self.scheduler_classes[0]
          lowerCAmelCase				:			Optional[int]    			=      self.get_scheduler_config()
          lowerCAmelCase				:			List[str]    			=      scheduler_class(**UpperCAmelCase_    )
  
          scheduler.set_timesteps(self.num_inference_steps    )
  
          lowerCAmelCase				:			Any    			=      torch.manual_seed(0    )
  
          lowerCAmelCase				:			List[Any]    			=      self.dummy_model()
          lowerCAmelCase				:			List[Any]    			=      self.dummy_sample_deter * scheduler.init_noise_sigma
          lowerCAmelCase				:			Optional[int]    			=      sample.to(UpperCAmelCase_    )
  
          for i, t in enumerate(scheduler.timesteps    ):
              lowerCAmelCase				:			str    			=      scheduler.scale_model_input(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			Any    			=      model(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			Optional[Any]    			=      scheduler.step(UpperCAmelCase_    ,				UpperCAmelCase_    ,				UpperCAmelCase_    ,				generator=UpperCAmelCase_    )
              lowerCAmelCase				:			Union[str, Any]    			=      output.prev_sample
  
          lowerCAmelCase				:			List[Any]    			=      torch.sum(torch.abs(UpperCAmelCase_    )    )
          lowerCAmelCase				:			Any    			=      torch.mean(torch.abs(UpperCAmelCase_    )    )
  
          assert abs(result_sum.item() - 1_38_49.38_77    ) < 1E-2
          assert abs(result_mean.item() - 18.03_31    ) < 5E-3
  
  
  
  
  
  
      def 	lowercase__ (	self			:    Tuple    ):
          for prediction_type in ["epsilon", "v_prediction"]:
              self.check_over_configs(prediction_type=UpperCAmelCase_    )
  
  
  
  
  
  
      def 	lowercase__ (	self			:    List[str]    ):
          if torch_device == "mps":
              return
          lowerCAmelCase				:			Optional[Any]    			=      self.scheduler_classes[0]
          lowerCAmelCase				:			List[Any]    			=      self.get_scheduler_config(prediction_type='v_prediction'    )
          lowerCAmelCase				:			Any    			=      scheduler_class(**UpperCAmelCase_    )
  
          scheduler.set_timesteps(self.num_inference_steps    )
  
          lowerCAmelCase				:			Optional[int]    			=      self.dummy_model()
          lowerCAmelCase				:			Any    			=      self.dummy_sample_deter * scheduler.init_noise_sigma
          lowerCAmelCase				:			Optional[int]    			=      sample.to(UpperCAmelCase_    )
  
          lowerCAmelCase				:			Optional[int]    			=      torch.manual_seed(0    )
  
          for i, t in enumerate(scheduler.timesteps    ):
              lowerCAmelCase				:			Dict    			=      scheduler.scale_model_input(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			Optional[int]    			=      model(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			Optional[int]    			=      scheduler.step(UpperCAmelCase_    ,				UpperCAmelCase_    ,				UpperCAmelCase_    ,				generator=UpperCAmelCase_    )
              lowerCAmelCase				:			str    			=      output.prev_sample
  
          lowerCAmelCase				:			str    			=      torch.sum(torch.abs(UpperCAmelCase_    )    )
          lowerCAmelCase				:			Tuple    			=      torch.mean(torch.abs(UpperCAmelCase_    )    )
  
          assert abs(result_sum.item() - 3_28.99_70    ) < 1E-2
          assert abs(result_mean.item() - 0.42_84    ) < 1E-3
  
  
  
  
  
  
      def 	lowercase__ (	self			:    Tuple    ):
          if torch_device == "mps":
              return
          lowerCAmelCase				:			str    			=      self.scheduler_classes[0]
          lowerCAmelCase				:			Dict    			=      self.get_scheduler_config()
          lowerCAmelCase				:			List[str]    			=      scheduler_class(**UpperCAmelCase_    )
  
          scheduler.set_timesteps(self.num_inference_steps    ,				device=UpperCAmelCase_    )
          lowerCAmelCase				:			int    			=      torch.manual_seed(0    )
  
          lowerCAmelCase				:			Tuple    			=      self.dummy_model()
          lowerCAmelCase				:			Optional[Any]    			=      self.dummy_sample_deter.to(UpperCAmelCase_    ) * scheduler.init_noise_sigma
  
          for t in scheduler.timesteps:
              lowerCAmelCase				:			str    			=      scheduler.scale_model_input(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			List[Any]    			=      model(UpperCAmelCase_    ,				UpperCAmelCase_    )
  
              lowerCAmelCase				:			Dict    			=      scheduler.step(UpperCAmelCase_    ,				UpperCAmelCase_    ,				UpperCAmelCase_    ,				generator=UpperCAmelCase_    )
              lowerCAmelCase				:			Dict    			=      output.prev_sample
  
          lowerCAmelCase				:			Union[str, Any]    			=      torch.sum(torch.abs(UpperCAmelCase_    )    )
          lowerCAmelCase				:			str    			=      torch.mean(torch.abs(UpperCAmelCase_    )    )
  
          assert abs(result_sum.item() - 1_38_49.38_18    ) < 1E-1
          assert abs(result_mean.item() - 18.03_31    ) < 1E-3
  
  
  
  
  
  