



'''simple docstring'''



import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


lowerCamelCase	 =       logging.getLogger()





@unittest.skip("""Temporarily disable the doc tests."""		)
@require_torch
@require_tf
@slow
class _UpperCamelCase		(     unittest.TestCase		):





				'''simple docstring'''





				def 				__lowerCamelCase     (							self  :  Optional[int]  ,       _lowerCAmelCase  :  Path  ,       _lowerCAmelCase  :  Union[str, None] = None  ,       _lowerCAmelCase  :  Union[List[str], None] = None  ,       _lowerCAmelCase  :  Union[str, List[str], None] = None  ,       _lowerCAmelCase  :  bool = True  ,       ):







											'''simple docstring'''

											__lowercase       	=[file for file in os.listdir(_lowerCAmelCase) if os.path.isfile(os.path.join(_lowerCAmelCase  ,       _lowerCAmelCase))]

											if identifier is not None:
																		__lowercase       	=[file for file in files if identifier in file]

											if n_identifier is not None:
																		if isinstance(_lowerCAmelCase  ,       _lowerCAmelCase):
																									for n_ in n_identifier:
																																__lowercase       	=[file for file in files if n_ not in file]
																		else:
																									__lowercase       	=[file for file in files if n_identifier not in file]

											__lowercase       	=ignore_files or []
											ignore_files.append('__init__.py')
											__lowercase       	=[file for file in files if file not in ignore_files]

											for file in files:
																		# Open all files
																		print('Testing'  ,       _lowerCAmelCase)

																		if only_modules:
																									__lowercase       	=file.split('.')[0]
																									try:
																																__lowercase       	=getattr(_lowerCAmelCase  ,       _lowerCAmelCase)
																																__lowercase       	=doctest.DocTestSuite(_lowerCAmelCase)
																																__lowercase       	=unittest.TextTestRunner().run(_lowerCAmelCase)
																																self.assertIs(len(result.failures)  ,       0)
																									except AttributeError:
																																logger.info(f"""{module_identifier} is not a module.""")
																		else:
																									__lowercase       	=doctest.testfile(str('..' / directory / file)  ,       optionflags=doctest.ELLIPSIS)
																									self.assertIs(result.failed  ,       0)

				def 				__lowerCamelCase     (							self  :  List[Any]):







											'''simple docstring'''

											__lowercase       	=Path('src/transformers')
											__lowercase       	='modeling'
											__lowercase       	=[
											    'modeling_ctrl.py',
											    'modeling_tf_ctrl.py',
											]
											self.analyze_directory(_lowerCAmelCase  ,       identifier=_lowerCAmelCase  ,       ignore_files=_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  List[Any]):







											'''simple docstring'''

											__lowercase       	=Path('src/transformers')
											__lowercase       	='tokenization'
											self.analyze_directory(_lowerCAmelCase  ,       identifier=_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  List[str]):







											'''simple docstring'''

											__lowercase       	=Path('src/transformers')
											__lowercase       	='configuration'
											self.analyze_directory(_lowerCAmelCase  ,       identifier=_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  int):







											'''simple docstring'''

											__lowercase       	=Path('src/transformers')
											__lowercase       	=['configuration', 'modeling', 'tokenization']
											self.analyze_directory(_lowerCAmelCase  ,       n_identifier=_lowerCAmelCase)

				def 				__lowerCamelCase     (							self  :  List[Any]):







											'''simple docstring'''

											__lowercase       	=Path('docs/source')
											__lowercase       	=['favicon.ico']
											self.analyze_directory(_lowerCAmelCase  ,       ignore_files=_lowerCAmelCase  ,       only_modules=_lowerCAmelCase)








'''simple docstring'''



import gc
import unittest

from diffusers import FlaxStableDiffusionInpaintPipeline
from diffusers.utils import is_flax_available, load_image, 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 _UpperCamelCase		(     unittest.TestCase		):





				'''simple docstring'''





				def 				__lowerCamelCase     (							self  :  List[Any]):







											'''simple docstring'''

											super().tearDown()
											gc.collect()

				def 				__lowerCamelCase     (							self  :  List[str]):







											'''simple docstring'''

											__lowercase       	=load_image(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/sd2-inpaint/init_image.png')
											__lowercase       	=load_image(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png')

											__lowercase       	='xvjiarui/stable-diffusion-2-inpainting'
											__lowercase	,				__lowercase       	=FlaxStableDiffusionInpaintPipeline.from_pretrained(_lowerCAmelCase  ,       safety_checker=_lowerCAmelCase)

											__lowercase       	='Face of a yellow cat, high resolution, sitting on a park bench'

											__lowercase       	=jax.random.PRNGKey(0)
											__lowercase       	=5_0

											__lowercase       	=jax.device_count()
											__lowercase       	=num_samples * [prompt]
											__lowercase       	=num_samples * [init_image]
											__lowercase       	=num_samples * [mask_image]
											__lowercase	,				__lowercase	,				__lowercase       	=pipeline.prepare_inputs(_lowerCAmelCase  ,       _lowerCAmelCase  ,       _lowerCAmelCase)

											# shard inputs and rng
											__lowercase       	=replicate(_lowerCAmelCase)
											__lowercase       	=jax.random.split(_lowerCAmelCase  ,       jax.device_count())
											__lowercase       	=shard(_lowerCAmelCase)
											__lowercase       	=shard(_lowerCAmelCase)
											__lowercase       	=shard(_lowerCAmelCase)

											__lowercase       	=pipeline(
											    _lowerCAmelCase  ,       _lowerCAmelCase  ,       _lowerCAmelCase  ,       _lowerCAmelCase  ,       _lowerCAmelCase  ,       _lowerCAmelCase  ,       jit=_lowerCAmelCase)

											__lowercase       	=output.images.reshape(_lowerCAmelCase  ,       5_1_2  ,       5_1_2  ,       3)

											__lowercase       	=images[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

											__lowercase       	=jnp.asarray(jax.device_get(image_slice.flatten()))
											__lowercase       	=jnp.array(
											    [0.361_1307, 0.3764_9736, 0.375_7408, 0.3821_3953, 0.3929_5167, 0.384_1631, 0.4155_4978, 0.413_7475, 0.421_7084])
											print(f"""output_slice: {output_slice}""")
											assert jnp.abs(output_slice - expected_slice).max() < 1e-2



