



"""simple docstring"""







import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    @property
    def      __snake_case							( self    :   Optional[int]):
      torch.manual_seed(0)
      a						:		List[Any]											=      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      __snake_case							( self    :   Optional[Any]):
      a						:		Any											=      self.dummy_uncond_unet
      a						:		List[str]											=      PNDMScheduler()

      a						:		Dict											=      PNDMPipeline(unet=__UpperCAmelCase    ,			scheduler=__UpperCAmelCase)
      pndm.to(__UpperCAmelCase)
      pndm.set_progress_bar_config(disable=__UpperCAmelCase)

      a						:		int											=      torch.manual_seed(0)
      a						:		Dict											=      pndm(generator=__UpperCAmelCase    ,			num_inference_steps=20    ,			output_type="numpy").images

      a						:		int											=      torch.manual_seed(0)
      a						:		List[str]											=      pndm(generator=__UpperCAmelCase    ,			num_inference_steps=20    ,			output_type="numpy"    ,			return_dict=__UpperCAmelCase)[0]

      a						:		List[str]											=      image[0, -3:, -3:, -1]
      a						:		Optional[int]											=      image_from_tuple[0, -3:, -3:, -1]

      assert image.shape == (1, 32, 32, 3)
      a						:		str											=      np.array([1.0, 1.0, 0.0, 1.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 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def      __snake_case							( self    :   Tuple):
      a						:		Union[str, Any]											=      "google/ddpm-cifar10-32"

      a						:		Tuple											=      UNetaDModel.from_pretrained(__UpperCAmelCase)
      a						:		List[str]											=      PNDMScheduler()

      a						:		int											=      PNDMPipeline(unet=__UpperCAmelCase    ,			scheduler=__UpperCAmelCase)
      pndm.to(__UpperCAmelCase)
      pndm.set_progress_bar_config(disable=__UpperCAmelCase)
      a						:		Optional[int]											=      torch.manual_seed(0)
      a						:		Optional[int]											=      pndm(generator=__UpperCAmelCase    ,			output_type="numpy").images

      a						:		int											=      image[0, -3:, -3:, -1]

      assert image.shape == (1, 32, 32, 3)
      a						:		Optional[Any]											=      np.array([0.1_564, 0.14_645, 0.1_406, 0.14_715, 0.12_425, 0.14_045, 0.13_115, 0.12_175, 0.125])

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










"""simple docstring"""







import datasets


__lowercase    =				"""\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

__lowercase    =				"""\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

__lowercase    =				"""
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""


def 					lowercase      (    A_  ,       A_	)->				List[str]:
  '''simple docstring'''







  return (preds == labels).mean()







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION   ,_KWARGS_DESCRIPTION  )
class 						_A  (  datasets.Metric  ):







    """simple docstring"""




    def      __snake_case							( self    :   List[str]):
      return datasets.MetricInfo(
          description=_DESCRIPTION    ,			citation=_CITATION    ,			inputs_description=_KWARGS_DESCRIPTION    ,			features=datasets.Features(
              {
                  "predictions": datasets.Value("int64" if self.config_name != "sts-b" else "float32"),
                  "references": datasets.Value("int64" if self.config_name != "sts-b" else "float32"),
              })    ,			codebase_urls=[]    ,			reference_urls=[]    ,			format="numpy"    ,			)






    def      __snake_case							( self    :   str    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Tuple):
      return {"accuracy": simple_accuracy(__UpperCAmelCase    ,			__UpperCAmelCase)}






