'''simple docstring'''





import torch

from diffusers import KDPMaAncestralDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest



class   UpperCamelCase					(       a_       ):







    """simple docstring"""





    A     :    Any				=			(KDPMaAncestralDiscreteScheduler,)
    A     :    List[Any]				=			10





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[Any]							,							**UpperCAmelCase_     :						List[Any]):


         """simple docstring"""







         a					:							Optional[int]							= {
             'num_train_timesteps': 1_1_0_0,
             'beta_start': 0.00_01,
             'beta_end': 0.02,
             'beta_schedule': 'linear',
         }

         config.update(**UpperCAmelCase_)
         return config





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[int]):


         """simple docstring"""







         for timesteps in [1_0, 5_0, 1_0_0, 1_0_0_0]:
              self.check_over_configs(num_train_timesteps=UpperCAmelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         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    SCREAMING_SNAKE_CASE_     (					self     :						Any):


         """simple docstring"""







         for schedule in ["linear", "scaled_linear"]:
              self.check_over_configs(beta_schedule=UpperCAmelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Union[str, Any]):


         """simple docstring"""







         if torch_device == "mps":
              return
         a					:							Tuple							= self.scheduler_classes[0]
         a					:							Union[str, Any]							= self.get_scheduler_config()
         a					:							int							= scheduler_class(**UpperCAmelCase_)

         scheduler.set_timesteps(self.num_inference_steps)

         a					:							Optional[int]							= torch.manual_seed(0)

         a					:							Optional[Any]							= self.dummy_model()
         a					:							Optional[int]							= self.dummy_sample_deter * scheduler.init_noise_sigma
         a					:							Any							= sample.to(UpperCAmelCase_)

         for i, t in enumerate(scheduler.timesteps):
              a					:							Union[str, Any]							= scheduler.scale_model_input(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							str							= model(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							Dict							= scheduler.step(UpperCAmelCase_							,							UpperCAmelCase_							,							UpperCAmelCase_							,							generator=UpperCAmelCase_)
              a					:							Tuple							= output.prev_sample

         a					:							Union[str, Any]							= torch.sum(torch.abs(UpperCAmelCase_))
         a					:							int							= 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    SCREAMING_SNAKE_CASE_     (					self     :						str):


         """simple docstring"""







         for prediction_type in ["epsilon", "v_prediction"]:
              self.check_over_configs(prediction_type=UpperCAmelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         if torch_device == "mps":
              return
         a					:							Tuple							= self.scheduler_classes[0]
         a					:							Union[str, Any]							= self.get_scheduler_config(prediction_type='v_prediction')
         a					:							Tuple							= scheduler_class(**UpperCAmelCase_)

         scheduler.set_timesteps(self.num_inference_steps)

         a					:							Dict							= self.dummy_model()
         a					:							Tuple							= self.dummy_sample_deter * scheduler.init_noise_sigma
         a					:							str							= sample.to(UpperCAmelCase_)

         a					:							Optional[int]							= torch.manual_seed(0)

         for i, t in enumerate(scheduler.timesteps):
              a					:							Tuple							= scheduler.scale_model_input(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							Optional[Any]							= model(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							Tuple							= scheduler.step(UpperCAmelCase_							,							UpperCAmelCase_							,							UpperCAmelCase_							,							generator=UpperCAmelCase_)
              a					:							int							= output.prev_sample

         a					:							int							= torch.sum(torch.abs(UpperCAmelCase_))
         a					:							Optional[int]							= 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    SCREAMING_SNAKE_CASE_     (					self     :						Tuple):


         """simple docstring"""







         if torch_device == "mps":
              return
         a					:							str							= self.scheduler_classes[0]
         a					:							List[Any]							= self.get_scheduler_config()
         a					:							Dict							= scheduler_class(**UpperCAmelCase_)

         scheduler.set_timesteps(self.num_inference_steps							,							device=UpperCAmelCase_)
         a					:							Any							= torch.manual_seed(0)

         a					:							str							= self.dummy_model()
         a					:							Dict							= self.dummy_sample_deter.to(UpperCAmelCase_) * scheduler.init_noise_sigma

         for t in scheduler.timesteps:
              a					:							Union[str, Any]							= scheduler.scale_model_input(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							Dict							= model(UpperCAmelCase_							,							UpperCAmelCase_)

              a					:							Tuple							= scheduler.step(UpperCAmelCase_							,							UpperCAmelCase_							,							UpperCAmelCase_							,							generator=UpperCAmelCase_)
              a					:							Optional[Any]							= output.prev_sample

         a					:							Any							= torch.sum(torch.abs(UpperCAmelCase_))
         a					:							Optional[Any]							= 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


'''simple docstring'''





from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase       :     Any			=    logging.get_logger(__name__)

UpperCamelCase       :     Optional[int]			=    {
    """openbmb/cpm-ant-10b""": """https://huggingface.co/openbmb/cpm-ant-10b/blob/main/config.json"""
    # See all CPMAnt models at https://huggingface.co/models?filter=cpmant
}



class   UpperCamelCase					(       a_       ):







    """simple docstring"""





    A     :    List[str]				=			"cpmant"





    def __init__(					self     :						Tuple							,							UpperCAmelCase_     :						int = 3_0_7_2_0							,							UpperCAmelCase_     :						int = 4_0_9_6							,							UpperCAmelCase_     :						int = 3_2							,							UpperCAmelCase_     :						int = 1_2_8							,							UpperCAmelCase_     :						int = 1_0_2_4_0							,							UpperCAmelCase_     :						int = 4_8							,							UpperCAmelCase_     :						int = 0.0							,							UpperCAmelCase_     :						int = 5_1_2							,							UpperCAmelCase_     :						int = 2_0_4_8							,							UpperCAmelCase_     :						int = 1e-6							,							UpperCAmelCase_     :						float = 1.0							,							UpperCAmelCase_     :						int = 3_2							,							UpperCAmelCase_     :						int = 3_2							,							UpperCAmelCase_     :						int = 3_2							,							UpperCAmelCase_     :						bool = True							,							**UpperCAmelCase_     :						Tuple							,							):


         """simple docstring"""







         super().__init__(**UpperCAmelCase_)
         a					:							Union[str, Any]							= prompt_types
         a					:							List[str]							= prompt_length
         a					:							List[Any]							= segment_types
         a					:							Any							= hidden_size
         a					:							Optional[int]							= num_attention_heads
         a					:							Union[str, Any]							= dim_head
         a					:							int							= dim_ff
         a					:							Union[str, Any]							= num_hidden_layers
         a					:							List[Any]							= position_bias_num_buckets
         a					:							Optional[int]							= position_bias_max_distance
         a					:							str							= dropout_p
         a					:							List[str]							= eps
         a					:							Dict							= use_cache
         a					:							Tuple							= vocab_size
         a					:							Optional[Any]							= init_std

