




import collections
import types

import numpy as np

from ..utils import (
    add_end_docstrings,
    is_tensorflow_probability_available,
    is_tf_available,
    is_torch_available,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline, PipelineException


if is_torch_available():
    import torch

    from ..models.auto.modeling_auto import (
        MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
        MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
    )

if is_tf_available() and is_tensorflow_probability_available():
    import tensorflow as tf
    import tensorflow_probability as tfp

    from ..models.auto.modeling_tf_auto import (
        TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
        TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
    )
class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     def __call__(     self      :			List[str]    ,_UpperCamelCase      :			Any=None    ,_UpperCamelCase      :			Tuple=None    ,**_UpperCamelCase      :			Tuple						)		->       Optional[Any]:


         '''simple docstring'''





         requires_backends(self    ,"""pandas"""						)
         import pandas as pd

         if table is None:
             raise ValueError("""Keyword argument `table` cannot be None."""						)
         elif query is None:
             if isinstance(_UpperCamelCase    ,_UpperCamelCase						) and table.get("""query"""						) is not None and table.get("""table"""						) is not None:
                 SCREAMING_SNAKE_CASE__       =[table]
             elif isinstance(_UpperCamelCase    ,_UpperCamelCase						) and len(_UpperCamelCase						) > 0:
                 if not all(isinstance(_UpperCamelCase    ,_UpperCamelCase						) for d in table						):
                     raise ValueError(
                         f"""Keyword argument `table` should be a list of dict, but is {(type(_UpperCamelCase						) for d in table)}"""						)

                 if table[0].get("""query"""						) is not None and table[0].get("""table"""						) is not None:
                     SCREAMING_SNAKE_CASE__       =table
                 else:
                     raise ValueError(
                         """If keyword argument `table` is a list of dictionaries, each dictionary should have a `table`"""
                         f""" and `query` key, but only dictionary has keys {table[0].keys()} `table` and `query` keys."""						)
             elif Dataset is not None and isinstance(_UpperCamelCase    ,_UpperCamelCase						) or isinstance(_UpperCamelCase    ,types.GeneratorType						):
                 return table
             else:
                 raise ValueError(
                     """Invalid input. Keyword argument `table` should be either of type `dict` or `list`, but """
                     f"""is {type(_UpperCamelCase						)})"""						)
         else:
             SCREAMING_SNAKE_CASE__       =[{"""table""": table, """query""": query}]

         for tqa_pipeline_input in tqa_pipeline_inputs:
             if not isinstance(tqa_pipeline_input["""table"""]    ,pd.DataFrame						):
                 if tqa_pipeline_input["table"] is None:
                     raise ValueError("""Table cannot be None."""						)

                 SCREAMING_SNAKE_CASE__       =pd.DataFrame(tqa_pipeline_input["""table"""]						)

         return tqa_pipeline_inputs






@add_end_docstrings(__lowerCamelCase					)
class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   Any     =  "table,query"




     def __init__(     self      :			List[Any]    ,_UpperCamelCase      :			Optional[int]=TableQuestionAnsweringArgumentHandler()    ,*_UpperCamelCase      :			str    ,**_UpperCamelCase      :			Optional[int]						)		->       Dict:


         '''simple docstring'''





         super().__init__(*_UpperCamelCase    ,**_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =args_parser

         self.check_model_type(
             dict(
                 TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items()
                 + TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()						)
             if self.framework == """tf"""
             else dict(
                 MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items() + MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()						)						)

         SCREAMING_SNAKE_CASE__       =bool(getattr(self.model.config    ,"""aggregation_labels"""    ,_UpperCamelCase						)						) and bool(
             getattr(self.model.config    ,"""num_aggregation_labels"""    ,_UpperCamelCase						)						)
         SCREAMING_SNAKE_CASE__       ="""tapas""" if hasattr(self.model.config    ,"""aggregation_labels"""						) else None




     def   __A    (     self      :			List[str]    ,**_UpperCamelCase      :			int						)		->       List[Any]:


         '''simple docstring'''





         return self.model(**_UpperCamelCase						)




     def   __A    (     self      :			Tuple    ,**_UpperCamelCase      :			int						)		->       Dict:


         '''simple docstring'''





         if self.framework == "pt":
             SCREAMING_SNAKE_CASE__       =[]
             SCREAMING_SNAKE_CASE__       =[]
             SCREAMING_SNAKE_CASE__       =None
             SCREAMING_SNAKE_CASE__       =inputs["""input_ids"""].shape[0]

             SCREAMING_SNAKE_CASE__       =inputs["""input_ids"""].to(self.device						)
             SCREAMING_SNAKE_CASE__       =inputs["""attention_mask"""].to(self.device						)
             SCREAMING_SNAKE_CASE__       =inputs["""token_type_ids"""].to(self.device						)
             SCREAMING_SNAKE_CASE__       =None

             for index in range(_UpperCamelCase						):
                 # If sequences have already been processed, the token type IDs will be created according to the previous
                 # answer.
                 if prev_answers is not None:
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 3]  # shape (seq_len,)
                     SCREAMING_SNAKE_CASE__       =np.zeros_like(prev_labels_example.cpu().numpy()						)  # shape (seq_len,)

                     SCREAMING_SNAKE_CASE__       =token_type_ids[index]  # shape (seq_len, 7)
                     for i in range(model_labels.shape[0]						):
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 0].tolist()[i]
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 1].tolist()[i] - 1
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 2].tolist()[i] - 1

                         if row_id >= 0 and col_id >= 0 and segment_id == 1:
                             SCREAMING_SNAKE_CASE__       =int(prev_answers[(col_id, row_id)]						)

                     SCREAMING_SNAKE_CASE__       =torch.from_numpy(_UpperCamelCase						).type(torch.long						).to(self.device						)

                 SCREAMING_SNAKE_CASE__       =input_ids[index]
                 SCREAMING_SNAKE_CASE__       =attention_mask[index]  # shape (seq_len,)
                 SCREAMING_SNAKE_CASE__       =token_type_ids[index]  # shape (seq_len, 7)
                 SCREAMING_SNAKE_CASE__       =self.model(
                     input_ids=input_ids_example.unsqueeze(0						)    ,attention_mask=attention_mask_example.unsqueeze(0						)    ,token_type_ids=token_type_ids_example.unsqueeze(0						)    ,)
                 SCREAMING_SNAKE_CASE__       =outputs.logits

                 if self.aggregate:
                     all_aggregations.append(outputs.logits_aggregation						)

                 all_logits.append(_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__       =torch.distributions.Bernoulli(logits=_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__       =dist_per_token.probs * attention_mask_example.type(torch.floataa						).to(
                     dist_per_token.probs.device						)

                 SCREAMING_SNAKE_CASE__       =collections.defaultdict(_UpperCamelCase						)
                 for i, p in enumerate(probabilities.squeeze().tolist()						):
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 0].tolist()[i]
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 1].tolist()[i] - 1
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 2].tolist()[i] - 1
                     if col >= 0 and row >= 0 and segment_id == 1:
                         coords_to_probs[(col, row)].append(_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__       ={key: np.array(coords_to_probs[key]						).mean() > 0.5 for key in coords_to_probs}

             SCREAMING_SNAKE_CASE__       =torch.cat(tuple(_UpperCamelCase						)    ,0						)

             return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(_UpperCamelCase						)    ,0						))
         else:
             SCREAMING_SNAKE_CASE__       =[]
             SCREAMING_SNAKE_CASE__       =[]
             SCREAMING_SNAKE_CASE__       =None
             SCREAMING_SNAKE_CASE__       =inputs["""input_ids"""].shape[0]

             SCREAMING_SNAKE_CASE__       =inputs["""input_ids"""]
             SCREAMING_SNAKE_CASE__       =inputs["""attention_mask"""]
             SCREAMING_SNAKE_CASE__       =inputs["""token_type_ids"""].numpy()
             SCREAMING_SNAKE_CASE__       =None

             for index in range(_UpperCamelCase						):
                 # If sequences have already been processed, the token type IDs will be created according to the previous
                 # answer.
                 if prev_answers is not None:
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 3]  # shape (seq_len,)
                     SCREAMING_SNAKE_CASE__       =np.zeros_like(_UpperCamelCase    ,dtype=np.intaa						)  # shape (seq_len,)

                     SCREAMING_SNAKE_CASE__       =token_type_ids[index]  # shape (seq_len, 7)
                     for i in range(model_labels.shape[0]						):
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 0].tolist()[i]
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 1].tolist()[i] - 1
                         SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 2].tolist()[i] - 1

                         if row_id >= 0 and col_id >= 0 and segment_id == 1:
                             SCREAMING_SNAKE_CASE__       =int(prev_answers[(col_id, row_id)]						)

                     SCREAMING_SNAKE_CASE__       =model_labels

                 SCREAMING_SNAKE_CASE__       =input_ids[index]
                 SCREAMING_SNAKE_CASE__       =attention_mask[index]  # shape (seq_len,)
                 SCREAMING_SNAKE_CASE__       =token_type_ids[index]  # shape (seq_len, 7)
                 SCREAMING_SNAKE_CASE__       =self.model(
                     input_ids=np.expand_dims(_UpperCamelCase    ,axis=0						)    ,attention_mask=np.expand_dims(_UpperCamelCase    ,axis=0						)    ,token_type_ids=np.expand_dims(_UpperCamelCase    ,axis=0						)    ,)
                 SCREAMING_SNAKE_CASE__       =outputs.logits

                 if self.aggregate:
                     all_aggregations.append(outputs.logits_aggregation						)

                 all_logits.append(_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__       =tfp.distributions.Bernoulli(logits=_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__       =dist_per_token.probs_parameter() * tf.cast(_UpperCamelCase    ,tf.floataa						)

                 SCREAMING_SNAKE_CASE__       =collections.defaultdict(_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__       =token_type_ids_example
                 for i, p in enumerate(tf.squeeze(_UpperCamelCase						).numpy().tolist()						):
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 0].tolist()[i]
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 1].tolist()[i] - 1
                     SCREAMING_SNAKE_CASE__       =token_type_ids_example[:, 2].tolist()[i] - 1
                     if col >= 0 and row >= 0 and segment_id == 1:
                         coords_to_probs[(col, row)].append(_UpperCamelCase						)

                 SCREAMING_SNAKE_CASE__       ={key: np.array(coords_to_probs[key]						).mean() > 0.5 for key in coords_to_probs}

             SCREAMING_SNAKE_CASE__       =tf.concat(tuple(_UpperCamelCase						)    ,0						)

             return (logits_batch,) if not self.aggregate else (logits_batch, tf.concat(tuple(_UpperCamelCase						)    ,0						))




     def __call__(     self      :			Dict    ,*_UpperCamelCase      :			Optional[int]    ,**_UpperCamelCase      :			Union[str, Any]						)		->       Dict:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =self._args_parser(*_UpperCamelCase    ,**_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__       =super().__call__(_UpperCamelCase    ,**_UpperCamelCase						)
         if len(_UpperCamelCase						) == 1:
             return results[0]
         return results




     def   __A    (     self      :			Any    ,_UpperCamelCase      :			Optional[int]=None    ,_UpperCamelCase      :			Dict=None    ,_UpperCamelCase      :			Optional[int]=None    ,**_UpperCamelCase      :			str						)		->       Optional[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       ={}
         if padding is not None:
             SCREAMING_SNAKE_CASE__       =padding
         if truncation is not None:
             SCREAMING_SNAKE_CASE__       =truncation

         SCREAMING_SNAKE_CASE__       ={}
         if sequential is not None:
             SCREAMING_SNAKE_CASE__       =sequential
         return preprocess_params, forward_params, {}




     def   __A    (     self      :			str    ,_UpperCamelCase      :			Union[str, Any]    ,_UpperCamelCase      :			str=None    ,_UpperCamelCase      :			List[str]=True    ,_UpperCamelCase      :			Dict=None						)		->       Any:


         '''simple docstring'''





         if truncation is None:
             if self.type == "tapas":
                 SCREAMING_SNAKE_CASE__       ="""drop_rows_to_fit"""
             else:
                 SCREAMING_SNAKE_CASE__       ="""do_not_truncate"""

         SCREAMING_SNAKE_CASE__      ,		SCREAMING_SNAKE_CASE__       =pipeline_input["""table"""], pipeline_input["""query"""]
         if table.empty:
             raise ValueError("""table is empty"""						)
         if query is None or query == "":
             raise ValueError("""query is empty"""						)
         SCREAMING_SNAKE_CASE__       =self.tokenizer(_UpperCamelCase    ,_UpperCamelCase    ,return_tensors=self.framework    ,truncation=_UpperCamelCase    ,padding=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =table
         return inputs




     def   __A    (     self      :			Union[str, Any]    ,_UpperCamelCase      :			Optional[Any]    ,_UpperCamelCase      :			Tuple=False						)		->       List[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =model_inputs.pop("""table"""						)

         if self.type == "tapas":
             if sequential:
                 SCREAMING_SNAKE_CASE__       =self.sequential_inference(**_UpperCamelCase						)
             else:
                 SCREAMING_SNAKE_CASE__       =self.batch_inference(**_UpperCamelCase						)
         else:
             SCREAMING_SNAKE_CASE__       =self.model.generate(**_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       ={"""model_inputs""": model_inputs, """table""": table, """outputs""": outputs}
         return model_outputs




     def   __A    (     self      :			Tuple    ,_UpperCamelCase      :			Optional[int]						)		->       Any:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =model_outputs["""model_inputs"""]
         SCREAMING_SNAKE_CASE__       =model_outputs["""table"""]
         SCREAMING_SNAKE_CASE__       =model_outputs["""outputs"""]
         if self.type == "tapas":
             if self.aggregate:
                 SCREAMING_SNAKE_CASE__      ,		SCREAMING_SNAKE_CASE__       =outputs[:2]
                 SCREAMING_SNAKE_CASE__       =self.tokenizer.convert_logits_to_predictions(_UpperCamelCase    ,_UpperCamelCase    ,_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__      ,		SCREAMING_SNAKE_CASE__       =predictions
                 SCREAMING_SNAKE_CASE__       ={i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(_UpperCamelCase						)}

                 SCREAMING_SNAKE_CASE__       =self.model.config.no_aggregation_label_index
                 SCREAMING_SNAKE_CASE__       ={
                     i: aggregators[i] + """ > """ for i, pred in enumerate(_UpperCamelCase						) if pred != no_agg_label_index
                 }
             else:
                 SCREAMING_SNAKE_CASE__       =outputs[0]
                 SCREAMING_SNAKE_CASE__       =self.tokenizer.convert_logits_to_predictions(_UpperCamelCase    ,_UpperCamelCase						)
                 SCREAMING_SNAKE_CASE__       =predictions[0]
                 SCREAMING_SNAKE_CASE__       ={}
                 SCREAMING_SNAKE_CASE__       ={}
             SCREAMING_SNAKE_CASE__       =[]
             for index, coordinates in enumerate(_UpperCamelCase						):
                 SCREAMING_SNAKE_CASE__       =[table.iat[coordinate] for coordinate in coordinates]
                 SCREAMING_SNAKE_CASE__       =aggregators.get(_UpperCamelCase    ,""""""						)
                 SCREAMING_SNAKE_CASE__       =aggregators_prefix.get(_UpperCamelCase    ,""""""						)
                 SCREAMING_SNAKE_CASE__       ={
                     """answer""": aggregator_prefix + """, """.join(_UpperCamelCase						),
                     """coordinates""": coordinates,
                     """cells""": [table.iat[coordinate] for coordinate in coordinates],
                 }
                 if aggregator:
                     SCREAMING_SNAKE_CASE__       =aggregator

                 answers.append(_UpperCamelCase						)
             if len(_UpperCamelCase						) == 0:
                 raise PipelineException("""Empty answer"""						)
         else:
             SCREAMING_SNAKE_CASE__       =[{"""answer""": answer} for answer in self.tokenizer.batch_decode(_UpperCamelCase    ,skip_special_tokens=_UpperCamelCase						)]

         return answers if len(_UpperCamelCase						) > 1 else answers[0]












import tempfile
import unittest

from diffusers import (
    DDIMScheduler,
    DDPMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    PNDMScheduler,
    logging,
)
from diffusers.configuration_utils import ConfigMixin, register_to_config
from diffusers.utils.testing_utils import CaptureLogger
class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			int    ,_UpperCamelCase      :			int=2    ,_UpperCamelCase      :			Optional[Any]=5    ,_UpperCamelCase      :			List[str]=(2, 5)    ,_UpperCamelCase      :			List[Any]="for diffusion"    ,_UpperCamelCase      :			Optional[int]=[1, 3]    ,)		->       Any:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[str]     =  "config.json"




     @register_to_config
     def __init__(     self      :			List[Any]    ,_UpperCamelCase      :			str=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			Optional[Any]=(2, 5)    ,_UpperCamelCase      :			Union[str, Any]="for diffusion"    ,_UpperCamelCase      :			Tuple=[1, 3]    ,)		->       List[str]:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   Optional[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			str    ,_UpperCamelCase      :			Optional[int]=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			List[Any]=(2, 5)    ,_UpperCamelCase      :			Dict="for diffusion"    ,_UpperCamelCase      :			Union[str, Any]=[1, 3]    ,_UpperCamelCase      :			Dict=[1, 3]    ,)		->       Any:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			Union[str, Any]    ,_UpperCamelCase      :			str=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			List[Any]=(2, 5)    ,_UpperCamelCase      :			int="for diffusion"    ,_UpperCamelCase      :			Any=[1, 5]    ,_UpperCamelCase      :			Optional[Any]=[5, 4]    ,)		->       List[Any]:


         '''simple docstring'''





         pass






class 				__a (			unittest.TestCase					):


     """simple docstring"""


     def   __A    (     self      :			Dict						)		->       Optional[Any]:


         '''simple docstring'''





         with self.assertRaises(_UpperCamelCase						):
             ConfigMixin.load_config("""dummy_path"""						)




     def   __A    (     self      :			int						)		->       List[str]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # init ignore private arguments
         SCREAMING_SNAKE_CASE__       =SampleObject(_name_or_path="""lalala"""						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # can override default
         SCREAMING_SNAKE_CASE__       =SampleObject(c=6						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == 6
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # can use positional arguments.
         SCREAMING_SNAKE_CASE__       =SampleObject(1    ,c=6						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 1
         assert config["b"] == 5
         assert config["c"] == 6
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]




     def   __A    (     self      :			List[Any]						)		->       Tuple:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()
         SCREAMING_SNAKE_CASE__       =obj.config

         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         with tempfile.TemporaryDirectory() as tmpdirname:
             obj.save_config(_UpperCamelCase						)
             SCREAMING_SNAKE_CASE__       =SampleObject.from_config(SampleObject.load_config(_UpperCamelCase						)						)
             SCREAMING_SNAKE_CASE__       =new_obj.config

         # unfreeze configs
         SCREAMING_SNAKE_CASE__       =dict(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =dict(_UpperCamelCase						)

         assert config.pop("""c"""						) == (2, 5)  # instantiated as tuple
         assert new_config.pop("""c"""						) == [2, 5]  # saved & loaded as list because of json
         config.pop("""_use_default_values"""						)
         assert config == new_config




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


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DDIMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert ddim.__class__ == DDIMScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			Dict						)		->       Optional[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =EulerDiscreteScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert euler.__class__ == EulerDiscreteScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       int:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =EulerAncestralDiscreteScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert euler.__class__ == EulerAncestralDiscreteScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =PNDMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert pndm.__class__ == PNDMScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			Optional[int]						)		->       List[str]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DDPMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""    ,prediction_type="""sample"""    ,beta_end=8    ,)

         with CaptureLogger(_UpperCamelCase						) as cap_logger_a:
             SCREAMING_SNAKE_CASE__       =DDPMScheduler.from_pretrained("""google/ddpm-celebahq-256"""    ,beta_start=8_8						)

         assert ddpm.__class__ == DDPMScheduler
         assert ddpm.config.prediction_type == "sample"
         assert ddpm.config.beta_end == 8
         assert ddpm_a.config.beta_start == 8_8

         # no warning should be thrown
         assert cap_logger.out == ""
         assert cap_logger_a.out == ""




     def   __A    (     self      :			Any						)		->       Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DPMSolverMultistepScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert dpm.__class__ == DPMSolverMultistepScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       str:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()

         SCREAMING_SNAKE_CASE__       ={k: v for k, v in config.config.items() if not k.startswith("""_"""						)}

         # make sure that default config has all keys in `_use_default_values`
         assert set(config_dict.keys()						) == set(config.config._use_default_values						)

         with tempfile.TemporaryDirectory() as tmpdirname:
             config.save_config(_UpperCamelCase						)

             # now loading it with SampleObject2 should put f into `_use_default_values`
             SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(_UpperCamelCase						)

             assert "f" in config._use_default_values
             assert config.f == [1, 3]

         # now loading the config, should **NOT** use [1, 3] for `f`, but the default [1, 4] value
         # **BECAUSE** it is part of `config._use_default_values`
         SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(config.config						)
         assert new_config.f == [5, 4]

         config.config._use_default_values.pop()
         SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(config.config						)
         assert new_config_a.f == [1, 3]

         # Nevertheless "e" should still be correctly loaded to [1, 3] from SampleObject2 instead of defaulting to [1, 5]
         assert new_config_a.e == [1, 3]






