


'''simple docstring'''

import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
     import jax
     import jax.numpy as jnp
     from flax.jax_utils import replicate
     from flax.training.common_utils import shard





@slow
@require_flax
class   snake_case					(					unittest.TestCase    ):





  """simple docstring"""




  def 						snake_case	(					self  ):







   """simple docstring"""
   # clean up the VRAM after each test
   super().tearDown()
   gc.collect()






  def 						snake_case	(					self  ):







   """simple docstring"""
   lowerCamelCase_				,lowerCamelCase_  				=						FlaxStableDiffusionPipeline.from_pretrained(
       "stabilityai/stable-diffusion-2"    ,						revision="bf16"    ,						dtype=jnp.bfloataa    ,						)

   lowerCamelCase_  				=						"A painting of a squirrel eating a burger"
   lowerCamelCase_  				=						jax.device_count()
   lowerCamelCase_  				=						num_samples * [prompt]
   lowerCamelCase_  				=						sd_pipe.prepare_inputs(UpperCamelCase  )

   lowerCamelCase_  				=						replicate(UpperCamelCase  )
   lowerCamelCase_  				=						shard(UpperCamelCase  )

   lowerCamelCase_  				=						jax.random.PRNGKey(0  )
   lowerCamelCase_  				=						jax.random.split(UpperCamelCase    ,						jax.device_count()  )

   lowerCamelCase_  				=						sd_pipe(UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						num_inference_steps=25    ,						jit=UpperCamelCase  )[0]
   assert images.shape == (jax.device_count(), 1, 768, 768, 3)

   lowerCamelCase_  				=						images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]  )
   lowerCamelCase_  				=						images[0, 253:256, 253:256, -1]

   lowerCamelCase_  				=						jnp.asarray(jax.device_get(image_slice.flatten()  )  )
   lowerCamelCase_  				=						jnp.array([0.4_238, 0.4_414, 0.4_395, 0.4_453, 0.4_629, 0.4_590, 0.4_531, 0.45_508, 0.4_512]  )
   print(f'''output_slice: {output_slice}'''  )
   assert jnp.abs(output_slice - expected_slice  ).max() < 1e-2







  def 						snake_case	(					self  ):







   """simple docstring"""
   lowerCamelCase_  				=						"stabilityai/stable-diffusion-2"
   lowerCamelCase_				,lowerCamelCase_  				=						FlaxDPMSolverMultistepScheduler.from_pretrained(UpperCamelCase    ,						subfolder="scheduler"  )
   lowerCamelCase_				,lowerCamelCase_  				=						FlaxStableDiffusionPipeline.from_pretrained(
       UpperCamelCase    ,						scheduler=UpperCamelCase    ,						revision="bf16"    ,						dtype=jnp.bfloataa    ,						)
   lowerCamelCase_  				=						scheduler_params

   lowerCamelCase_  				=						"A painting of a squirrel eating a burger"
   lowerCamelCase_  				=						jax.device_count()
   lowerCamelCase_  				=						num_samples * [prompt]
   lowerCamelCase_  				=						sd_pipe.prepare_inputs(UpperCamelCase  )

   lowerCamelCase_  				=						replicate(UpperCamelCase  )
   lowerCamelCase_  				=						shard(UpperCamelCase  )

   lowerCamelCase_  				=						jax.random.PRNGKey(0  )
   lowerCamelCase_  				=						jax.random.split(UpperCamelCase    ,						jax.device_count()  )

   lowerCamelCase_  				=						sd_pipe(UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						num_inference_steps=25    ,						jit=UpperCamelCase  )[0]
   assert images.shape == (jax.device_count(), 1, 768, 768, 3)

   lowerCamelCase_  				=						images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]  )
   lowerCamelCase_  				=						images[0, 253:256, 253:256, -1]

   lowerCamelCase_  				=						jnp.asarray(jax.device_get(image_slice.flatten()  )  )
   lowerCamelCase_  				=						jnp.array([0.4_336, 0.42_969, 0.4_453, 0.4_199, 0.4_297, 0.4_531, 0.4_434, 0.4_434, 0.4_297]  )
   print(f'''output_slice: {output_slice}'''  )
   assert jnp.abs(output_slice - expected_slice  ).max() < 1e-2







'''simple docstring'''

import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
from sklearn.metrics import ConfusionMatrixDisplay
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier





def __snake_case      (   UpperCAmelCase_		:		dict	):
 return (data["data"], data["target"])





def __snake_case      (   UpperCAmelCase_		:		np.ndarray      ,       UpperCAmelCase_		:		np.ndarray	):
 lowerCamelCase_  				=						XGBClassifier()
 classifier.fit(UpperCAmelCase_      ,       UpperCAmelCase_	)
 return classifier





def __snake_case      (   ):
 lowerCamelCase_  				=						load_iris()
 lowerCamelCase_				,lowerCamelCase_  				=						data_handling(UpperCAmelCase_	)
 lowerCamelCase_				,lowerCamelCase_				,lowerCamelCase_				,lowerCamelCase_  				=						train_test_split(
     UpperCAmelCase_      ,       UpperCAmelCase_      ,       test_size=0.25	)

 lowerCamelCase_  				=						iris["target_names"]

 # Create an XGBoost Classifier from the training data
 lowerCamelCase_  				=						xgboost(UpperCAmelCase_      ,       UpperCAmelCase_	)

 # Display the confusion matrix of the classifier with both training and test sets
 ConfusionMatrixDisplay.from_estimator(
     UpperCAmelCase_      ,       UpperCAmelCase_      ,       UpperCAmelCase_      ,       display_labels=UpperCAmelCase_      ,       cmap="Blues"      ,       normalize="true"      ,       )
 plt.title("Normalized Confusion Matrix - IRIS Dataset"	)
 plt.show()


if __name__ == "__main__":
     import doctest

     doctest.testmod(verbose=True)
     main()



