




from collections import OrderedDict
from typing import Mapping

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


lowerCamelCase__				:     Optional[Any]			       =							logging.get_logger(__name__)

lowerCamelCase__				:     Dict			       =							{
    'flaubert/flaubert_small_cased': 'https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json',
    'flaubert/flaubert_base_uncased': 'https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json',
    'flaubert/flaubert_base_cased': 'https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json',
    'flaubert/flaubert_large_cased': 'https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json',
}





class  lowerCamelCase_							(   lowerCAmelCase__      ):


 '''simple docstring'''







 lowercase_       					=					"""flaubert"""
 lowercase_       					=					{
     """hidden_size""": """emb_dim""",
     """num_attention_heads""": """n_heads""",
     """num_hidden_layers""": """n_layers""",
     """n_words""": """vocab_size""",  # For backward compatibility
 }



 def __init__(							self						:	List[str]       ,       _lowerCAmelCase						:	Tuple=False       ,       _lowerCAmelCase						:	Dict=0.0       ,       _lowerCAmelCase						:	List[Any]=30_145       ,       _lowerCAmelCase						:	Optional[int]=2_048       ,       _lowerCAmelCase						:	int=12       ,       _lowerCAmelCase						:	Dict=16       ,       _lowerCAmelCase						:	Optional[Any]=0.1       ,       _lowerCAmelCase						:	str=0.1       ,       _lowerCAmelCase						:	int=True       ,       _lowerCAmelCase						:	str=False       ,       _lowerCAmelCase						:	List[Any]=False       ,       _lowerCAmelCase						:	str=False       ,       _lowerCAmelCase						:	Union[str, Any]=1       ,       _lowerCAmelCase						:	Union[str, Any]=True       ,       _lowerCAmelCase						:	Optional[int]=512       ,       _lowerCAmelCase						:	Tuple=2_048**-0.5       ,       _lowerCAmelCase						:	List[Any]=1E-12       ,       _lowerCAmelCase						:	List[str]=0.02       ,       _lowerCAmelCase						:	Optional[int]=0       ,       _lowerCAmelCase						:	int=1       ,       _lowerCAmelCase						:	Any=2       ,       _lowerCAmelCase						:	Union[str, Any]=3       ,       _lowerCAmelCase						:	Union[str, Any]=5       ,       _lowerCAmelCase						:	Dict=True       ,       _lowerCAmelCase						:	List[Any]="first"       ,       _lowerCAmelCase						:	List[Any]=True       ,       _lowerCAmelCase						:	Union[str, Any]=None       ,       _lowerCAmelCase						:	List[str]=True       ,       _lowerCAmelCase						:	int=0.1       ,       _lowerCAmelCase						:	str=5       ,       _lowerCAmelCase						:	List[str]=5       ,       _lowerCAmelCase						:	Any=0       ,       _lowerCAmelCase						:	int=0       ,       _lowerCAmelCase						:	Optional[int]=2       ,       _lowerCAmelCase						:	Tuple=0       ,       **_lowerCAmelCase						:	int       ,       ):
       SCREAMING_SNAKE_CASE_					=    pre_norm
       SCREAMING_SNAKE_CASE_					=    layerdrop
       SCREAMING_SNAKE_CASE_					=    vocab_size
       SCREAMING_SNAKE_CASE_					=    emb_dim
       SCREAMING_SNAKE_CASE_					=    n_layers
       SCREAMING_SNAKE_CASE_					=    n_heads
       SCREAMING_SNAKE_CASE_					=    dropout
       SCREAMING_SNAKE_CASE_					=    attention_dropout
       SCREAMING_SNAKE_CASE_					=    gelu_activation
       SCREAMING_SNAKE_CASE_					=    sinusoidal_embeddings
       SCREAMING_SNAKE_CASE_					=    causal
       SCREAMING_SNAKE_CASE_					=    asm
       SCREAMING_SNAKE_CASE_					=    n_langs
       SCREAMING_SNAKE_CASE_					=    use_lang_emb
       SCREAMING_SNAKE_CASE_					=    layer_norm_eps
       SCREAMING_SNAKE_CASE_					=    bos_index
       SCREAMING_SNAKE_CASE_					=    eos_index
       SCREAMING_SNAKE_CASE_					=    pad_index
       SCREAMING_SNAKE_CASE_					=    unk_index
       SCREAMING_SNAKE_CASE_					=    mask_index
       SCREAMING_SNAKE_CASE_					=    is_encoder
       SCREAMING_SNAKE_CASE_					=    max_position_embeddings
       SCREAMING_SNAKE_CASE_					=    embed_init_std
       SCREAMING_SNAKE_CASE_					=    init_std
       SCREAMING_SNAKE_CASE_					=    summary_type
       SCREAMING_SNAKE_CASE_					=    summary_use_proj
       SCREAMING_SNAKE_CASE_					=    summary_activation
       SCREAMING_SNAKE_CASE_					=    summary_proj_to_labels
       SCREAMING_SNAKE_CASE_					=    summary_first_dropout
       SCREAMING_SNAKE_CASE_					=    start_n_top
       SCREAMING_SNAKE_CASE_					=    end_n_top
       SCREAMING_SNAKE_CASE_					=    mask_token_id
       SCREAMING_SNAKE_CASE_					=    lang_id

       if "n_words" in kwargs:
             SCREAMING_SNAKE_CASE_					=    kwargs['n_words']

       super().__init__(pad_token_id=lowerCAmelCase_       ,       bos_token_id=lowerCAmelCase_       ,       **lowerCAmelCase_		)





class  lowerCamelCase_							(   lowerCAmelCase__      ):


 '''simple docstring'''







 @property
 def    lowerCAmelCase_						(							self						:	Union[str, Any]		):






       if self.task == "multiple-choice":
             SCREAMING_SNAKE_CASE_					=    {0: 'batch', 1: 'choice', 2: 'sequence'}
       else:
             SCREAMING_SNAKE_CASE_					=    {0: 'batch', 1: 'sequence'}
       return OrderedDict(
           [
               ('input_ids', dynamic_axis),
               ('attention_mask', dynamic_axis),
           ]		)








import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


lowerCamelCase__				:     int			       =							False





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


 '''simple docstring'''







 def    lowerCAmelCase_						(							self						:	Optional[Any]		):
       # clean up the VRAM after each test
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()



 def    lowerCAmelCase_						(							self						:	Optional[int]		):
       SCREAMING_SNAKE_CASE_					=    VersatileDiffusionDualGuidedPipeline.from_pretrained('shi-labs/versatile-diffusion'		)
       # remove text_unet
       pipe.remove_unused_weights()
       pipe.to(_lowerCAmelCase		)
       pipe.set_progress_bar_config(disable=_lowerCAmelCase		)

       SCREAMING_SNAKE_CASE_					=    load_image(
           'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'		)

       SCREAMING_SNAKE_CASE_					=    torch.manual_seed(0		)
       SCREAMING_SNAKE_CASE_					=    pipe(
           prompt='first prompt'       ,       image=_lowerCAmelCase       ,       text_to_image_strength=0.75       ,       generator=_lowerCAmelCase       ,       guidance_scale=7.5       ,       num_inference_steps=2       ,       output_type='numpy'       ,       ).images

       with tempfile.TemporaryDirectory() as tmpdirname:
             pipe.save_pretrained(_lowerCAmelCase		)
             SCREAMING_SNAKE_CASE_					=    VersatileDiffusionDualGuidedPipeline.from_pretrained(_lowerCAmelCase		)

       pipe.to(_lowerCAmelCase		)
       pipe.set_progress_bar_config(disable=_lowerCAmelCase		)

       SCREAMING_SNAKE_CASE_					=    generator.manual_seed(0		)
       SCREAMING_SNAKE_CASE_					=    pipe(
           prompt='first prompt'       ,       image=_lowerCAmelCase       ,       text_to_image_strength=0.75       ,       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    lowerCAmelCase_						(							self						:	Any		):
       SCREAMING_SNAKE_CASE_					=    VersatileDiffusionDualGuidedPipeline.from_pretrained('shi-labs/versatile-diffusion'		)
       pipe.remove_unused_weights()
       pipe.to(_lowerCAmelCase		)
       pipe.set_progress_bar_config(disable=_lowerCAmelCase		)

       SCREAMING_SNAKE_CASE_					=    'cyberpunk 2077'
       SCREAMING_SNAKE_CASE_					=    load_image(
           'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'		)
       SCREAMING_SNAKE_CASE_					=    torch.manual_seed(0		)
       SCREAMING_SNAKE_CASE_					=    pipe(
           prompt=_lowerCAmelCase       ,       image=_lowerCAmelCase       ,       text_to_image_strength=0.75       ,       generator=_lowerCAmelCase       ,       guidance_scale=7.5       ,       num_inference_steps=50       ,       output_type='numpy'       ,       ).images

       SCREAMING_SNAKE_CASE_					=    image[0, 253:256, 253:256, -1]

       assert image.shape == (1, 512, 512, 3)
       SCREAMING_SNAKE_CASE_					=    np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]		)

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