


'''simple docstring'''






import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


__UpperCAmelCase       =							False




class 		a__    (							unittest.TestCase  ):





							'''simple docstring'''






							pass




@nightly
@require_torch_gpu
class 		a__    (							unittest.TestCase  ):





							'''simple docstring'''






							def   __SCREAMING_SNAKE_CASE							(		self       )	->							int:
														# clean up the VRAM after each test
														super().tearDown()
														gc.collect()
														torch.cuda.empty_cache()







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							str:
														lowerCAmelCase__	       =     VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''       )
														# remove text_unet
														pipe.remove_unused_weights()
														pipe.to(lowerCamelCase_       )
														pipe.set_progress_bar_config(disable=lowerCamelCase_       )

														lowerCAmelCase__	       =     '''A painting of a squirrel eating a burger '''
														lowerCAmelCase__	       =     torch.manual_seed(0       )
														lowerCAmelCase__	       =     pipe(
														    prompt=lowerCamelCase_ ,   generator=lowerCamelCase_ ,   guidance_scale=7.5 ,   num_inference_steps=2 ,   output_type='''numpy'''       ).images

														with tempfile.TemporaryDirectory() as tmpdirname:
																					pipe.save_pretrained(lowerCamelCase_       )
																					lowerCAmelCase__	       =     VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCamelCase_       )
														pipe.to(lowerCamelCase_       )
														pipe.set_progress_bar_config(disable=lowerCamelCase_       )

														lowerCAmelCase__	       =     generator.manual_seed(0       )
														lowerCAmelCase__	       =     pipe(
														    prompt=lowerCamelCase_ ,   generator=lowerCamelCase_ ,   guidance_scale=7.5 ,   num_inference_steps=2 ,   output_type='''numpy'''       ).images

														assert np.abs(image - new_image       ).sum() < 1e-5, "Models don't have the same forward pass"







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Any:
														lowerCAmelCase__	       =     VersatileDiffusionTextToImagePipeline.from_pretrained(
														    '''shi-labs/versatile-diffusion''' ,   torch_dtype=torch.floataa       )
														pipe.to(lowerCamelCase_       )
														pipe.set_progress_bar_config(disable=lowerCamelCase_       )

														lowerCAmelCase__	       =     '''A painting of a squirrel eating a burger '''
														lowerCAmelCase__	       =     torch.manual_seed(0       )
														lowerCAmelCase__	       =     pipe(
														    prompt=lowerCamelCase_ ,   generator=lowerCamelCase_ ,   guidance_scale=7.5 ,   num_inference_steps=50 ,   output_type='''numpy'''       ).images

														lowerCAmelCase__	       =     image[0, 2_53:2_56, 2_53:2_56, -1]

														assert image.shape == (1, 5_12, 5_12, 3)
														lowerCAmelCase__	       =     np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778]       )

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



'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCAmelCase       =							logging.get_logger(__name__)

__UpperCAmelCase       =							{
    '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/config.json''',
    '''distilbert-base-uncased-distilled-squad''': (
        '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json'''
    ),
    '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/config.json''',
    '''distilbert-base-cased-distilled-squad''': (
        '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json'''
    ),
    '''distilbert-base-german-cased''': '''https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json''',
    '''distilbert-base-multilingual-cased''': (
        '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json'''
    ),
    '''distilbert-base-uncased-finetuned-sst-2-english''': (
        '''https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json'''
    ),
}




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Optional[Any]     						=				"distilbert"
							lowercase__      :       Tuple     						=				{
							    "hidden_size": "dim",
							    "num_attention_heads": "n_heads",
							    "num_hidden_layers": "n_layers",
							}







							def __init__(		self ,   lowerCamelCase_=3_05_22 ,   lowerCamelCase_=5_12 ,   lowerCamelCase_=False ,   lowerCamelCase_=6 ,   lowerCamelCase_=12 ,   lowerCamelCase_=7_68 ,   lowerCamelCase_=4 * 7_68 ,   lowerCamelCase_=0.1 ,   lowerCamelCase_=0.1 ,   lowerCamelCase_="gelu" ,   lowerCamelCase_=0.02 ,   lowerCamelCase_=0.1 ,   lowerCamelCase_=0.2 ,   lowerCamelCase_=0 ,   **lowerCamelCase_ ,   )	->							Any:
														lowerCAmelCase__	       =     vocab_size
														lowerCAmelCase__	       =     max_position_embeddings
														lowerCAmelCase__	       =     sinusoidal_pos_embds
														lowerCAmelCase__	       =     n_layers
														lowerCAmelCase__	       =     n_heads
														lowerCAmelCase__	       =     dim
														lowerCAmelCase__	       =     hidden_dim
														lowerCAmelCase__	       =     dropout
														lowerCAmelCase__	       =     attention_dropout
														lowerCAmelCase__	       =     activation
														lowerCAmelCase__	       =     initializer_range
														lowerCAmelCase__	       =     qa_dropout
														lowerCAmelCase__	       =     seq_classif_dropout
														super().__init__(**lowerCamelCase_ ,   pad_token_id=lowerCamelCase_       )




class 		a__    (							a__  ):





							'''simple docstring'''






							@property
							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Mapping[str, Mapping[int, str]]:
														if self.task == "multiple-choice":
																					lowerCAmelCase__	       =     {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
														else:
																					lowerCAmelCase__	       =     {0: '''batch''', 1: '''sequence'''}
														return OrderedDict(
														    [
														        ('''input_ids''', dynamic_axis),
														        ('''attention_mask''', dynamic_axis),
														    ]       )