





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


__A							:			List[Any]         =			logging.get_logger(__name__)

__A							:			Union[str, Any]         =			{
    "facebook/nllb-moe-54B": "https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json",
}







class      lowerCamelCase(						__snake_case	):
     '''simple docstring'''


     __magic_name__   =			'nllb-moe'
     __magic_name__   =			['past_key_values']
     __magic_name__   =			{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}




     def __init__(    self				,     snake_case_=12_8112				,     snake_case_=1024				,     snake_case_=12				,     snake_case_=4096				,     snake_case_=16				,     snake_case_=12				,     snake_case_=4096				,     snake_case_=16				,     snake_case_=0.05				,     snake_case_=0.05				,     snake_case_=True				,     snake_case_=True				,     snake_case_="relu"				,     snake_case_=1024				,     snake_case_=0.1				,     snake_case_=0.1				,     snake_case_=0.0				,     snake_case_=0.02				,     snake_case_=2				,     snake_case_=True				,     snake_case_=False				,     snake_case_="float32"				,     snake_case_=False				,     snake_case_=128				,     snake_case_=64				,     snake_case_=4				,     snake_case_=4				,     snake_case_=0.001				,     snake_case_=0.001				,     snake_case_="all"				,     snake_case_=False				,     snake_case_=False				,     snake_case_=1.0				,     snake_case_=0.2				,     snake_case_=1				,     snake_case_=0				,     snake_case_=2				,     snake_case_=False				,     **snake_case_				,     ):
         _A     =							vocab_size
         _A     =							max_position_embeddings
         _A     =							d_model
         _A     =							encoder_ffn_dim
         _A     =							encoder_layers
         _A     =							encoder_attention_heads
         _A     =							decoder_ffn_dim
         _A     =							decoder_layers
         _A     =							decoder_attention_heads
         _A     =							dropout
         _A     =							attention_dropout
         _A     =							activation_dropout
         _A     =							activation_function
         _A     =							init_std
         _A     =							encoder_layerdrop
         _A     =							decoder_layerdrop
         _A     =							use_cache
         _A     =							encoder_layers
         _A     =							scale_embedding  # scale factor will be sqrt(d_model) if True
         _A     =							router_z_loss_coef
         _A     =							router_aux_loss_coef
         _A     =							decoder_sparse_step
         _A     =							encoder_sparse_step
         _A     =							num_experts
         _A     =							expert_capacity
         _A     =							router_bias
         if router_dtype not in ["float32", "float16", "bfloat16"]:
             raise ValueError(F"`router_dtype` must be one of 'float32', 'float16' or 'bfloat16', got {router_dtype}"							)
         _A     =							router_dtype

         _A     =							router_ignore_padding_tokens
         _A     =							batch_prioritized_routing
         _A     =							second_expert_policy
         _A     =							normalize_router_prob_before_dropping
         _A     =							moe_eval_capacity_token_fraction
         _A     =							moe_token_dropout
         _A     =							output_router_logits
         super().__init__(
             pad_token_id=snake_case_				,     bos_token_id=snake_case_				,     eos_token_id=snake_case_				,     is_encoder_decoder=snake_case_				,     decoder_start_token_id=snake_case_				,     **snake_case_				,     )












import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class      lowerCamelCase(						unittest.TestCase	):
     '''simple docstring'''


     @property
     def        lowerCAmelCase__		(    self							):
         torch.manual_seed(0							)
         _A     =							UNetaDModel(
             block_out_channels=(32, 64)				,     layers_per_block=2				,     sample_size=32				,     in_channels=3				,     out_channels=3				,     down_block_types=('DownBlock2D', 'AttnDownBlock2D')				,     up_block_types=('AttnUpBlock2D', 'UpBlock2D')				,     )
         return model




     def        lowerCAmelCase__		(    self							):
         _A     =							self.dummy_uncond_unet
         _A     =							KarrasVeScheduler()

         _A     =							KarrasVePipeline(unet=snake_case_				,     scheduler=snake_case_							)
         pipe.to(snake_case_							)
         pipe.set_progress_bar_config(disable=snake_case_							)

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=2				,     generator=snake_case_				,     output_type='numpy'							).images

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=2				,     generator=snake_case_				,     output_type='numpy'				,     return_dict=snake_case_							)[0]

         _A     =							image[0, -3:, -3:, -1]
         _A     =							image_from_tuple[0, -3:, -3:, -1]

         assert image.shape == (1, 32, 32, 3)
         _A     =							np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
         assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1E-2







@slow
@require_torch
class      lowerCamelCase(						unittest.TestCase	):
     '''simple docstring'''


     def        lowerCAmelCase__		(    self							):
         _A     =							'google/ncsnpp-celebahq-256'
         _A     =							UNetaDModel.from_pretrained(snake_case_							)
         _A     =							KarrasVeScheduler()

         _A     =							KarrasVePipeline(unet=snake_case_				,     scheduler=snake_case_							)
         pipe.to(snake_case_							)
         pipe.set_progress_bar_config(disable=snake_case_							)

         _A     =							torch.manual_seed(0							)
         _A     =							pipe(num_inference_steps=20				,     generator=snake_case_				,     output_type='numpy'							).images

         _A     =							image[0, -3:, -3:, -1]
         assert image.shape == (1, 256, 256, 3)
         _A     =							np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]							)

         assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2





