
"""simple docstring"""



import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     FlaubertForMultipleChoice,
     FlaubertForQuestionAnswering,
     FlaubertForQuestionAnsweringSimple,
     FlaubertForSequenceClassification,
     FlaubertForTokenClassification,
     FlaubertModel,
     FlaubertWithLMHeadModel,
 )
 from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class 		a_						( _UpperCAmelCase	):







    def __init__(			self			:       int     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       Any=13     ,					__UpperCamelCase			:       Tuple=7     ,					__UpperCamelCase			:       str=True     ,					__UpperCamelCase			:       Optional[int]=True     ,					__UpperCamelCase			:       Dict=True     ,					__UpperCamelCase			:       List[str]=True     ,					__UpperCamelCase			:       Tuple=True     ,					__UpperCamelCase			:       Dict=False     ,					__UpperCamelCase			:       List[str]=False     ,					__UpperCamelCase			:       Optional[Any]=False     ,					__UpperCamelCase			:       List[Any]=2     ,					__UpperCamelCase			:       List[Any]=99     ,					__UpperCamelCase			:       List[str]=0     ,					__UpperCamelCase			:       List[str]=32     ,					__UpperCamelCase			:       List[Any]=5     ,					__UpperCamelCase			:       Dict=4     ,					__UpperCamelCase			:       List[Any]=0.1     ,					__UpperCamelCase			:       Tuple=0.1     ,					__UpperCamelCase			:       Optional[Any]=5_12     ,					__UpperCamelCase			:       Optional[int]=12     ,					__UpperCamelCase			:       List[Any]=2     ,					__UpperCamelCase			:       str=0.0_2     ,					__UpperCamelCase			:       Any=3     ,					__UpperCamelCase			:       Dict=4     ,					__UpperCamelCase			:       Tuple="last"     ,					__UpperCamelCase			:       Optional[int]=None     ,					__UpperCamelCase			:       Dict=None     ,					)		->Dict:






        '''simple docstring'''






        _UpperCAmelCase          =   parent
        _UpperCAmelCase          =   batch_size
        _UpperCAmelCase          =   seq_length
        _UpperCAmelCase          =   is_training
        _UpperCAmelCase          =   use_input_lengths
        _UpperCAmelCase          =   use_token_type_ids
        _UpperCAmelCase          =   use_labels
        _UpperCAmelCase          =   gelu_activation
        _UpperCAmelCase          =   sinusoidal_embeddings
        _UpperCAmelCase          =   causal
        _UpperCAmelCase          =   asm
        _UpperCAmelCase          =   n_langs
        _UpperCAmelCase          =   vocab_size
        _UpperCAmelCase          =   n_special
        _UpperCAmelCase          =   hidden_size
        _UpperCAmelCase          =   num_hidden_layers
        _UpperCAmelCase          =   num_attention_heads
        _UpperCAmelCase          =   hidden_dropout_prob
        _UpperCAmelCase          =   attention_probs_dropout_prob
        _UpperCAmelCase          =   max_position_embeddings
        _UpperCAmelCase          =   type_vocab_size
        _UpperCAmelCase          =   type_sequence_label_size
        _UpperCAmelCase          =   initializer_range
        _UpperCAmelCase          =   num_labels
        _UpperCAmelCase          =   num_choices
        _UpperCAmelCase          =   summary_type
        _UpperCAmelCase          =   use_proj
        _UpperCAmelCase          =   scope







    def      _snake_case					(			self			:       Any     )		->str:






        '''simple docstring'''






        _UpperCAmelCase          =   ids_tensor([self.batch_size, self.seq_length]     ,					self.vocab_size     )
        _UpperCAmelCase          =   random_attention_mask([self.batch_size, self.seq_length]     )

        _UpperCAmelCase          =   None
        if self.use_input_lengths:
            _UpperCAmelCase          =   (
                ids_tensor([self.batch_size]     ,					vocab_size=2     ) + self.seq_length - 2
            )  # small variation of seq_length

        _UpperCAmelCase          =   None
        if self.use_token_type_ids:
            _UpperCAmelCase          =   ids_tensor([self.batch_size, self.seq_length]     ,					self.n_langs     )

        _UpperCAmelCase          =   None
        _UpperCAmelCase          =   None
        _UpperCAmelCase          =   None
        if self.use_labels:
            _UpperCAmelCase          =   ids_tensor([self.batch_size]     ,					self.type_sequence_label_size     )
            _UpperCAmelCase          =   ids_tensor([self.batch_size, self.seq_length]     ,					self.num_labels     )
            _UpperCAmelCase          =   ids_tensor([self.batch_size]     ,					2     ).float()
            _UpperCAmelCase          =   ids_tensor([self.batch_size]     ,					self.num_choices     )

        _UpperCAmelCase          =   self.get_config()

        return (
            config,
            input_ids,
            token_type_ids,
            input_lengths,
            sequence_labels,
            token_labels,
            is_impossible_labels,
            choice_labels,
            input_mask,
        )







    def      _snake_case					(			self			:       Union[str, Any]     )		->Union[str, Any]:






        '''simple docstring'''






        return FlaubertConfig(
            vocab_size=self.vocab_size     ,					n_special=self.n_special     ,					emb_dim=self.hidden_size     ,					n_layers=self.num_hidden_layers     ,					n_heads=self.num_attention_heads     ,					dropout=self.hidden_dropout_prob     ,					attention_dropout=self.attention_probs_dropout_prob     ,					gelu_activation=self.gelu_activation     ,					sinusoidal_embeddings=self.sinusoidal_embeddings     ,					asm=self.asm     ,					causal=self.causal     ,					n_langs=self.n_langs     ,					max_position_embeddings=self.max_position_embeddings     ,					initializer_range=self.initializer_range     ,					summary_type=self.summary_type     ,					use_proj=self.use_proj     ,					)







    def      _snake_case					(			self			:       int     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Optional[int]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       Optional[int]     ,					__UpperCamelCase			:       Any     ,					__UpperCamelCase			:       int     ,					)		->Tuple:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertModel(config=__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()
        _UpperCAmelCase          =   model(__UpperCamelCase     ,					lengths=__UpperCamelCase     ,					langs=__UpperCamelCase     )
        _UpperCAmelCase          =   model(__UpperCamelCase     ,					langs=__UpperCamelCase     )
        _UpperCAmelCase          =   model(__UpperCamelCase     )
        self.parent.assertEqual(result.last_hidden_state.shape     ,					(self.batch_size, self.seq_length, self.hidden_size)     )







    def      _snake_case					(			self			:       int     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       Tuple     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       str     ,					)		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertWithLMHeadModel(__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()

        _UpperCAmelCase          =   model(__UpperCamelCase     ,					token_type_ids=__UpperCamelCase     ,					labels=__UpperCamelCase     )
        self.parent.assertEqual(result.loss.shape     ,					()     )
        self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.seq_length, self.vocab_size)     )







    def      _snake_case					(			self			:       Dict     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       Any     ,					__UpperCamelCase			:       Union[str, Any]     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Any     ,					__UpperCamelCase			:       Optional[int]     ,					)		->Any:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertForQuestionAnsweringSimple(__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()

        _UpperCAmelCase          =   model(__UpperCamelCase     )

        _UpperCAmelCase          =   model(__UpperCamelCase     ,					start_positions=__UpperCamelCase     ,					end_positions=__UpperCamelCase     )
        self.parent.assertEqual(result.start_logits.shape     ,					(self.batch_size, self.seq_length)     )
        self.parent.assertEqual(result.end_logits.shape     ,					(self.batch_size, self.seq_length)     )







    def      _snake_case					(			self			:       Dict     ,					__UpperCamelCase			:       Optional[int]     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Optional[int]     ,					__UpperCamelCase			:       Tuple     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       Optional[Any]     ,					)		->Any:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertForQuestionAnswering(__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()

        _UpperCAmelCase          =   model(__UpperCamelCase     )

        _UpperCAmelCase          =   model(
            __UpperCamelCase     ,					start_positions=__UpperCamelCase     ,					end_positions=__UpperCamelCase     ,					cls_index=__UpperCamelCase     ,					is_impossible=__UpperCamelCase     ,					p_mask=__UpperCamelCase     ,					)

        _UpperCAmelCase          =   model(
            __UpperCamelCase     ,					start_positions=__UpperCamelCase     ,					end_positions=__UpperCamelCase     ,					cls_index=__UpperCamelCase     ,					is_impossible=__UpperCamelCase     ,					)

        ((_UpperCAmelCase)    ,)          =   result_with_labels.to_tuple()

        _UpperCAmelCase          =   model(__UpperCamelCase     ,					start_positions=__UpperCamelCase     ,					end_positions=__UpperCamelCase     )

        ((_UpperCAmelCase)    ,)          =   result_with_labels.to_tuple()

        self.parent.assertEqual(result_with_labels.loss.shape     ,					()     )
        self.parent.assertEqual(result.start_top_log_probs.shape     ,					(self.batch_size, model.config.start_n_top)     )
        self.parent.assertEqual(result.start_top_index.shape     ,					(self.batch_size, model.config.start_n_top)     )
        self.parent.assertEqual(
            result.end_top_log_probs.shape     ,					(self.batch_size, model.config.start_n_top * model.config.end_n_top)     )
        self.parent.assertEqual(
            result.end_top_index.shape     ,					(self.batch_size, model.config.start_n_top * model.config.end_n_top)     )
        self.parent.assertEqual(result.cls_logits.shape     ,					(self.batch_size,)     )







    def      _snake_case					(			self			:       Optional[int]     ,					__UpperCamelCase			:       Optional[int]     ,					__UpperCamelCase			:       Any     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Tuple     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       str     ,					)		->Dict:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertForSequenceClassification(__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()

        _UpperCAmelCase          =   model(__UpperCamelCase     )
        _UpperCAmelCase          =   model(__UpperCamelCase     ,					labels=__UpperCamelCase     )

        self.parent.assertEqual(result.loss.shape     ,					()     )
        self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.type_sequence_label_size)     )







    def      _snake_case					(			self			:       Optional[int]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       Any     ,					__UpperCamelCase			:       int     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       str     ,					__UpperCamelCase			:       Optional[int]     ,					)		->Any:






        '''simple docstring'''






        _UpperCAmelCase          =   self.num_labels
        _UpperCAmelCase          =   FlaubertForTokenClassification(__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()

        _UpperCAmelCase          =   model(__UpperCamelCase     ,					attention_mask=__UpperCamelCase     ,					labels=__UpperCamelCase     )
        self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.seq_length, self.num_labels)     )







    def      _snake_case					(			self			:       Optional[int]     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       Union[str, Any]     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Dict     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       List[Any]     ,					__UpperCamelCase			:       Optional[int]     ,					)		->Dict:






        '''simple docstring'''






        _UpperCAmelCase          =   self.num_choices
        _UpperCAmelCase          =   FlaubertForMultipleChoice(config=__UpperCamelCase     )
        model.to(__UpperCamelCase     )
        model.eval()
        _UpperCAmelCase          =   input_ids.unsqueeze(1     ).expand(-1     ,					self.num_choices     ,					-1     ).contiguous()
        _UpperCAmelCase          =   token_type_ids.unsqueeze(1     ).expand(-1     ,					self.num_choices     ,					-1     ).contiguous()
        _UpperCAmelCase          =   input_mask.unsqueeze(1     ).expand(-1     ,					self.num_choices     ,					-1     ).contiguous()
        _UpperCAmelCase          =   model(
            __UpperCamelCase     ,					attention_mask=__UpperCamelCase     ,					token_type_ids=__UpperCamelCase     ,					labels=__UpperCamelCase     ,					)
        self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.num_choices)     )







    def      _snake_case					(			self			:       Dict     )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase          =   self.prepare_config_and_inputs()
        (
            (
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,(
            _UpperCAmelCase
        )    ,
        )          =   config_and_inputs
        _UpperCAmelCase          =   {
            """input_ids""": input_ids,
            """token_type_ids""": token_type_ids,
            """lengths""": input_lengths,
            """attention_mask""": input_mask,
        }
        return config, inputs_dict







@require_torch
class 		a_						( _UpperCAmelCase     ,						_UpperCAmelCase     ,						unittest.TestCase	):
    a      :				Dict     =				(
        (
            FlaubertModel,
            FlaubertWithLMHeadModel,
            FlaubertForQuestionAnswering,
            FlaubertForQuestionAnsweringSimple,
            FlaubertForSequenceClassification,
            FlaubertForTokenClassification,
            FlaubertForMultipleChoice,
        )
        if is_torch_available()
        else ()
    )
    a      :				Tuple     =				(
        {
            'feature-extraction': FlaubertModel,
            'fill-mask': FlaubertWithLMHeadModel,
            'question-answering': FlaubertForQuestionAnsweringSimple,
            'text-classification': FlaubertForSequenceClassification,
            'token-classification': FlaubertForTokenClassification,
            'zero-shot': FlaubertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )







    def      _snake_case					(			self			:       List[str]     ,					__UpperCamelCase			:       Union[str, Any]     ,					__UpperCamelCase			:       Union[str, Any]     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Union[str, Any]     ,					__UpperCamelCase			:       str     )		->Union[str, Any]:






        '''simple docstring'''






        if (
            pipeline_test_casse_name == "QAPipelineTests"
            and tokenizer_name is not None
            and not tokenizer_name.endswith("""Fast"""     )
        ):
            # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
            # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
            # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
            return True

        return False







    def      _snake_case					(			self			:       Dict     ,					__UpperCamelCase			:       List[str]     ,					__UpperCamelCase			:       Optional[Any]     ,					__UpperCamelCase			:       Tuple=False     )		->List[str]:






        '''simple docstring'''






        _UpperCAmelCase          =   super()._prepare_for_class(__UpperCamelCase     ,					__UpperCamelCase     ,					return_labels=__UpperCamelCase     )

        if return_labels:
            if model_class.__name__ == "FlaubertForQuestionAnswering":
                _UpperCAmelCase          =   torch.zeros(
                    self.model_tester.batch_size     ,					dtype=torch.long     ,					device=__UpperCamelCase     )
                _UpperCAmelCase          =   torch.zeros(
                    self.model_tester.batch_size     ,					dtype=torch.long     ,					device=__UpperCamelCase     )

        return inputs_dict







    def      _snake_case					(			self			:       Optional[Any]     )		->List[Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertModelTester(self     )
        _UpperCAmelCase          =   ConfigTester(self     ,					config_class=__UpperCamelCase     ,					emb_dim=37     )







    def      _snake_case					(			self			:       Union[str, Any]     )		->List[Any]:






        '''simple docstring'''






        self.config_tester.run_common_tests()







    def      _snake_case					(			self			:       Any     )		->Dict:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_model(*__UpperCamelCase     )







    def      _snake_case					(			self			:       Union[str, Any]     )		->List[Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_lm_head(*__UpperCamelCase     )







    def      _snake_case					(			self			:       Optional[Any]     )		->str:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_simple_qa(*__UpperCamelCase     )







    def      _snake_case					(			self			:       Optional[Any]     )		->Tuple:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_qa(*__UpperCamelCase     )







    def      _snake_case					(			self			:       Dict     )		->str:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_sequence_classif(*__UpperCamelCase     )







    def      _snake_case					(			self			:       List[Any]     )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_token_classif(*__UpperCamelCase     )







    def      _snake_case					(			self			:       Optional[Any]     )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_flaubert_multiple_choice(*__UpperCamelCase     )







    @slow
    def      _snake_case					(			self			:       Any     )		->List[Any]:






        '''simple docstring'''






        for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            _UpperCAmelCase          =   FlaubertModel.from_pretrained(__UpperCamelCase     )
            self.assertIsNotNone(__UpperCamelCase     )







    @slow
    @require_torch_gpu
    def      _snake_case					(			self			:       Tuple     )		->int:






        '''simple docstring'''






        _UpperCAmelCase    ,_UpperCAmelCase          =   self.model_tester.prepare_config_and_inputs_for_common()
        for model_class in self.all_model_classes:
            # FlauBertForMultipleChoice behaves incorrectly in JIT environments.
            if model_class == FlaubertForMultipleChoice:
                return

            _UpperCAmelCase          =   True
            _UpperCAmelCase          =   model_class(config=__UpperCamelCase     )

            _UpperCAmelCase          =   self._prepare_for_class(__UpperCamelCase     ,					__UpperCamelCase     )
            _UpperCAmelCase          =   torch.jit.trace(
                __UpperCamelCase     ,					(inputs_dict["""input_ids"""].to("""cpu"""     ), inputs_dict["""attention_mask"""].to("""cpu"""     ))     )

            with tempfile.TemporaryDirectory() as tmp:
                torch.jit.save(__UpperCamelCase     ,					os.path.join(__UpperCamelCase     ,					"""traced_model.pt"""     )     )
                _UpperCAmelCase          =   torch.jit.load(os.path.join(__UpperCamelCase     ,					"""traced_model.pt"""     )     ,					map_location=__UpperCamelCase     )
                loaded(inputs_dict["""input_ids"""].to(__UpperCamelCase     )     ,					inputs_dict["""attention_mask"""].to(__UpperCamelCase     )     )







@require_torch
class 		a_						( unittest.TestCase	):







    @slow
    def      _snake_case					(			self			:       Tuple     )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   FlaubertModel.from_pretrained("""flaubert/flaubert_base_cased"""     )
        _UpperCAmelCase          =   torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]     )
        with torch.no_grad():
            _UpperCAmelCase          =   model(__UpperCamelCase     )[0]
        _UpperCAmelCase          =   torch.Size((1, 11, 7_68)     )
        self.assertEqual(output.shape     ,					__UpperCamelCase     )
        _UpperCAmelCase          =   torch.tensor(
            [[[-2.6_2_5_1, -1.4_2_9_8, -0.0_2_2_7], [-2.8_5_1_0, -1.6_3_8_7, 0.2_2_5_8], [-2.8_1_1_4, -1.1_8_3_2, -0.3_0_6_6]]]     )

        self.assertTrue(torch.allclose(output[:, :3, :3]     ,					__UpperCamelCase     ,					atol=1e-4     )     )

"""simple docstring"""



import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel

from diffusers import DDIMScheduler, LDMPipeline, UNetaDModel, VQModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()




class 		a_						( unittest.TestCase	):







    @property
    def      _snake_case					(			self			:       Dict     )		->int:






        '''simple docstring'''






        torch.manual_seed(0     )
        _UpperCAmelCase          =   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







    @property
    def      _snake_case					(			self			:       Optional[Any]     )		->str:






        '''simple docstring'''






        torch.manual_seed(0     )
        _UpperCAmelCase          =   VQModel(
            block_out_channels=[32, 64]     ,					in_channels=3     ,					out_channels=3     ,					down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]     ,					up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]     ,					latent_channels=3     ,					)
        return model







    @property
    def      _snake_case					(			self			:       List[Any]     )		->Optional[int]:






        '''simple docstring'''






        torch.manual_seed(0     )
        _UpperCAmelCase          =   CLIPTextConfig(
            bos_token_id=0     ,					eos_token_id=2     ,					hidden_size=32     ,					intermediate_size=37     ,					layer_norm_eps=1e-05     ,					num_attention_heads=4     ,					num_hidden_layers=5     ,					pad_token_id=1     ,					vocab_size=10_00     ,					)
        return CLIPTextModel(__UpperCamelCase     )







    def      _snake_case					(			self			:       List[str]     )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   self.dummy_uncond_unet
        _UpperCAmelCase          =   DDIMScheduler()
        _UpperCAmelCase          =   self.dummy_vq_model

        _UpperCAmelCase          =   LDMPipeline(unet=__UpperCamelCase     ,					vqvae=__UpperCamelCase     ,					scheduler=__UpperCamelCase     )
        ldm.to(__UpperCamelCase     )
        ldm.set_progress_bar_config(disable=__UpperCamelCase     )

        _UpperCAmelCase          =   torch.manual_seed(0     )
        _UpperCAmelCase          =   ldm(generator=__UpperCamelCase     ,					num_inference_steps=2     ,					output_type="""numpy"""     ).images

        _UpperCAmelCase          =   torch.manual_seed(0     )
        _UpperCAmelCase          =   ldm(generator=__UpperCamelCase     ,					num_inference_steps=2     ,					output_type="""numpy"""     ,					return_dict=__UpperCamelCase     )[0]

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

        assert image.shape == (1, 64, 64, 3)
        _UpperCAmelCase          =   np.array([0.8_5_1_2, 0.8_1_8, 0.6_4_1_1, 0.6_8_0_8, 0.4_4_6_5, 0.5_6_1_8, 0.4_6, 0.6_2_3_1, 0.5_1_7_2]     )
        _UpperCAmelCase          =   1e-2 if torch_device != """mps""" else 3e-2

        assert np.abs(image_slice.flatten() - expected_slice     ).max() < tolerance
        assert np.abs(image_from_tuple_slice.flatten() - expected_slice     ).max() < tolerance







@slow
@require_torch
class 		a_						( unittest.TestCase	):







    def      _snake_case					(			self			:       List[Any]     )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase          =   LDMPipeline.from_pretrained("""CompVis/ldm-celebahq-256"""     )
        ldm.to(__UpperCamelCase     )
        ldm.set_progress_bar_config(disable=__UpperCamelCase     )

        _UpperCAmelCase          =   torch.manual_seed(0     )
        _UpperCAmelCase          =   ldm(generator=__UpperCamelCase     ,					num_inference_steps=5     ,					output_type="""numpy"""     ).images

        _UpperCAmelCase          =   image[0, -3:, -3:, -1]

        assert image.shape == (1, 2_56, 2_56, 3)
        _UpperCAmelCase          =   np.array([0.4_3_9_9, 0.4_4_9_7_5, 0.4_6_8_2_5, 0.4_7_4, 0.4_3_5_9, 0.4_5_8_1, 0.4_5_0_9_5, 0.4_3_4_1, 0.4_4_4_7]     )
        _UpperCAmelCase          =   1e-2 if torch_device != """mps""" else 3e-2

        assert np.abs(image_slice.flatten() - expected_slice     ).max() < tolerance