import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    EulerAncestralDiscreteScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPanoramaPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()






@skip_mps
class 						A   (   lowercase__       ,	lowercase__       ,	unittest.TestCase   ):
							a_        =      StableDiffusionPanoramaPipeline
							a_        =      TEXT_TO_IMAGE_PARAMS
							a_        =      TEXT_TO_IMAGE_BATCH_PARAMS
							a_        =      TEXT_TO_IMAGE_IMAGE_PARAMS
							a_        =      TEXT_TO_IMAGE_IMAGE_PARAMS





							def       snake_case__						(      self				:							Tuple	)							->	str:
								torch.manual_seed(0	)
								__UpperCAmelCase							=			UNetaDConditionModel(
								    block_out_channels=(3_2, 6_4)     ,		layers_per_block=1     ,		sample_size=3_2     ,		in_channels=4     ,		out_channels=4     ,		down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')     ,		up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')     ,		cross_attention_dim=3_2     ,		)
								__UpperCAmelCase							=			DDIMScheduler()
								torch.manual_seed(0	)
								__UpperCAmelCase							=			AutoencoderKL(
								    block_out_channels=[3_2, 6_4]     ,		in_channels=3     ,		out_channels=3     ,		down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']     ,		up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']     ,		latent_channels=4     ,		)
								torch.manual_seed(0	)
								__UpperCAmelCase							=			CLIPTextConfig(
								    bos_token_id=0     ,		eos_token_id=2     ,		hidden_size=3_2     ,		intermediate_size=3_7     ,		layer_norm_eps=1e-05     ,		num_attention_heads=4     ,		num_hidden_layers=5     ,		pad_token_id=1     ,		vocab_size=1_0_0_0     ,		)
								__UpperCAmelCase							=			CLIPTextModel(UpperCAmelCase__	)
								__UpperCAmelCase							=			CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''	)

								__UpperCAmelCase							=			{
								    '''unet''': unet,
								    '''scheduler''': scheduler,
								    '''vae''': vae,
								    '''text_encoder''': text_encoder,
								    '''tokenizer''': tokenizer,
								    '''safety_checker''': None,
								    '''feature_extractor''': None,
								}
								return components





							def       snake_case__						(      self				:							Tuple     ,		__a				:							Any     ,		__a				:							Any=0	)							->	List[Any]:
								__UpperCAmelCase							=			torch.manual_seed(UpperCAmelCase__	)
								__UpperCAmelCase							=			{
								    '''prompt''': '''a photo of the dolomites''',
								    '''generator''': generator,
								    # Setting height and width to None to prevent OOMs on CPU.
								    '''height''': None,
								    '''width''': None,
								    '''num_inference_steps''': 1,
								    '''guidance_scale''': 6.0,
								    '''output_type''': '''numpy''',
								}
								return inputs





							def       snake_case__						(      self				:							Optional[Any]	)							->	Any:
								__UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								__UpperCAmelCase							=			self.get_dummy_components()
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline(**UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe.to(UpperCAmelCase__	)
								sd_pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

								__UpperCAmelCase							=			self.get_dummy_inputs(UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe(**UpperCAmelCase__	).images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1]
								assert image.shape == (1, 6_4, 6_4, 3)

								__UpperCAmelCase							=			np.array([0.6_1_8_6, 0.5_3_7_4, 0.4_9_1_5, 0.4_1_3_5, 0.4_1_1_4, 0.4_5_6_3, 0.5_1_2_8, 0.4_9_7_7, 0.4_7_5_7]	)

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





							def       snake_case__						(      self				:							Dict	)							->	Union[str, Any]:
								super().test_inference_batch_consistent(batch_sizes=[1, 2]	)





							def       snake_case__						(      self				:							Tuple	)							->	Optional[Any]:
								super().test_inference_batch_single_identical(batch_size=2     ,		expected_max_diff=3.25e-3	)





							def       snake_case__						(      self				:							Tuple	)							->	Optional[Any]:
								__UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								__UpperCAmelCase							=			self.get_dummy_components()
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline(**UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe.to(UpperCAmelCase__	)
								sd_pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

								__UpperCAmelCase							=			self.get_dummy_inputs(UpperCAmelCase__	)
								__UpperCAmelCase							=			'''french fries'''
								__UpperCAmelCase							=			sd_pipe(**UpperCAmelCase__     ,		negative_prompt=UpperCAmelCase__	)
								__UpperCAmelCase							=			output.images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1]

								assert image.shape == (1, 6_4, 6_4, 3)

								__UpperCAmelCase							=			np.array([0.6_1_8_7, 0.5_3_7_5, 0.4_9_1_5, 0.4_1_3_6, 0.4_1_1_4, 0.4_5_6_3, 0.5_1_2_8, 0.4_9_7_6, 0.4_7_5_7]	)

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





							def       snake_case__						(      self				:							Dict	)							->	Optional[int]:
								__UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								__UpperCAmelCase							=			self.get_dummy_components()
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline(**UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe.to(UpperCAmelCase__	)
								sd_pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

								__UpperCAmelCase							=			self.get_dummy_inputs(UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe(**UpperCAmelCase__     ,		view_batch_size=2	)
								__UpperCAmelCase							=			output.images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1]

								assert image.shape == (1, 6_4, 6_4, 3)

								__UpperCAmelCase							=			np.array([0.6_1_8_7, 0.5_3_7_5, 0.4_9_1_5, 0.4_1_3_6, 0.4_1_1_4, 0.4_5_6_3, 0.5_1_2_8, 0.4_9_7_6, 0.4_7_5_7]	)

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





							def       snake_case__						(      self				:							str	)							->	str:
								__UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								__UpperCAmelCase							=			self.get_dummy_components()
								__UpperCAmelCase							=			EulerAncestralDiscreteScheduler(
								    beta_start=0.0_0_0_8_5     ,		beta_end=0.0_1_2     ,		beta_schedule='''scaled_linear'''	)
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline(**UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe.to(UpperCAmelCase__	)
								sd_pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

								__UpperCAmelCase							=			self.get_dummy_inputs(UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe(**UpperCAmelCase__	).images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1]

								assert image.shape == (1, 6_4, 6_4, 3)

								__UpperCAmelCase							=			np.array([0.4_0_2_4, 0.6_5_1_0, 0.4_9_0_1, 0.5_3_7_8, 0.5_8_1_3, 0.5_6_2_2, 0.4_7_9_5, 0.4_4_6_7, 0.4_9_5_2]	)

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






							def       snake_case__						(      self				:							Tuple	)							->	str:
								__UpperCAmelCase							=			'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								__UpperCAmelCase							=			self.get_dummy_components()
								__UpperCAmelCase							=			PNDMScheduler(
								    beta_start=0.0_0_0_8_5     ,		beta_end=0.0_1_2     ,		beta_schedule='''scaled_linear'''     ,		skip_prk_steps=UpperCAmelCase__	)
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline(**UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe.to(UpperCAmelCase__	)
								sd_pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

								__UpperCAmelCase							=			self.get_dummy_inputs(UpperCAmelCase__	)
								__UpperCAmelCase							=			sd_pipe(**UpperCAmelCase__	).images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1]

								assert image.shape == (1, 6_4, 6_4, 3)

								__UpperCAmelCase							=			np.array([0.6_3_9_1, 0.6_2_9_1, 0.4_8_6_1, 0.5_1_3_4, 0.5_5_5_2, 0.4_5_7_8, 0.5_0_3_2, 0.5_0_2_3, 0.4_5_3_9]	)

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






@slow
@require_torch_gpu
class 						A   (   unittest.TestCase   ):





							def       snake_case__						(      self				:							int	)							->	int:
								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()





							def       snake_case__						(      self				:							int     ,		__a				:							int=0	)							->	List[Any]:
								__UpperCAmelCase							=			torch.manual_seed(UpperCAmelCase__	)
								__UpperCAmelCase							=			{
								    '''prompt''': '''a photo of the dolomites''',
								    '''generator''': generator,
								    '''num_inference_steps''': 3,
								    '''guidance_scale''': 7.5,
								    '''output_type''': '''numpy''',
								}
								return inputs





							def       snake_case__						(      self				:							Any	)							->	Dict:
								__UpperCAmelCase							=			'''stabilityai/stable-diffusion-2-base'''
								__UpperCAmelCase							=			DDIMScheduler.from_pretrained(UpperCAmelCase__     ,		subfolder='''scheduler'''	)
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline.from_pretrained(UpperCAmelCase__     ,		scheduler=UpperCAmelCase__     ,		safety_checker=UpperCAmelCase__	)
								pipe.to(UpperCAmelCase__	)
								pipe.set_progress_bar_config(disable=UpperCAmelCase__	)
								pipe.enable_attention_slicing()

								__UpperCAmelCase							=			self.get_inputs()
								__UpperCAmelCase							=			pipe(**UpperCAmelCase__	).images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1].flatten()

								assert image.shape == (1, 5_1_2, 2_0_4_8, 3)

								__UpperCAmelCase							=			np.array(
								    [
								        0.3_6_9_6_8_3_9_2,
								        0.2_7_0_2_5_3_7_2,
								        0.3_2_4_4_6_7_6_6,
								        0.2_8_3_7_9_3_8_7,
								        0.3_6_3_6_3_2_7_4,
								        0.3_0_7_3_3_3_4_7,
								        0.2_7_1_0_0_0_2_7,
								        0.2_7_0_5_4_1_2_5,
								        0.2_5_5_3_6_0_9_6,
								    ]	)

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





							def       snake_case__						(      self				:							Any	)							->	List[str]:
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline.from_pretrained(
								    '''stabilityai/stable-diffusion-2-base'''     ,		safety_checker=UpperCAmelCase__	)
								__UpperCAmelCase							=			LMSDiscreteScheduler.from_config(pipe.scheduler.config	)
								pipe.to(UpperCAmelCase__	)
								pipe.set_progress_bar_config(disable=UpperCAmelCase__	)
								pipe.enable_attention_slicing()

								__UpperCAmelCase							=			self.get_inputs()
								__UpperCAmelCase							=			pipe(**UpperCAmelCase__	).images
								__UpperCAmelCase							=			image[0, -3:, -3:, -1].flatten()

								assert image.shape == (1, 5_1_2, 2_0_4_8, 3)

								__UpperCAmelCase							=			np.array(
								    [
								        [
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								            0.0,
								        ]
								    ]	)

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





							def       snake_case__						(      self				:							Optional[int]	)							->	int:
								__UpperCAmelCase							=			0

								def callback_fn(__a				:							int     ,		__a				:							int     ,		__a				:							torch.FloatTensor	) -> None:
									__UpperCAmelCase							=			True
									nonlocal number_of_steps
									number_of_steps += 1
									if step == 1:
										__UpperCAmelCase							=			latents.detach().cpu().numpy()
										assert latents.shape == (1, 4, 6_4, 2_5_6)
										__UpperCAmelCase							=			latents[0, -3:, -3:, -1]

										__UpperCAmelCase							=			np.array(
										    [
										        0.1_8_6_8_1_8_6_9,
										        0.3_3_9_0_7_8_1_6,
										        0.5_3_6_1_2_7_6,
										        0.1_4_4_3_2_8_6_5,
										        -0.0_2_8_5_6_6_1_1,
										        -0.7_3_9_4_1_1_2_3,
										        0.2_3_3_9_7_9_8_7,
										        0.4_7_3_2_2_6_8_2,
										        -0.3_7_8_2_3_1_6_4,
										    ]	)
										assert np.abs(latents_slice.flatten() - expected_slice	).max() < 5e-2
									elif step == 2:
										__UpperCAmelCase							=			latents.detach().cpu().numpy()
										assert latents.shape == (1, 4, 6_4, 2_5_6)
										__UpperCAmelCase							=			latents[0, -3:, -3:, -1]

										__UpperCAmelCase							=			np.array(
										    [
										        0.1_8_5_3_9_6_4_5,
										        0.3_3_9_8_7_2_4_8,
										        0.5_3_7_8_5_5_9,
										        0.1_4_4_3_7_1_4_2,
										        -0.0_2_4_5_5_2_6_1,
										        -0.7_3_3_8_3_1_7,
										        0.2_3_9_9_0_7_5_5,
										        0.4_7_3_5_6_2_7_2,
										        -0.3_7_8_6_5_0_5,
										    ]	)

										assert np.abs(latents_slice.flatten() - expected_slice	).max() < 5e-2

								__UpperCAmelCase							=			False

								__UpperCAmelCase							=			'''stabilityai/stable-diffusion-2-base'''
								__UpperCAmelCase							=			DDIMScheduler.from_pretrained(UpperCAmelCase__     ,		subfolder='''scheduler'''	)
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline.from_pretrained(UpperCAmelCase__     ,		scheduler=UpperCAmelCase__     ,		safety_checker=UpperCAmelCase__	)
								__UpperCAmelCase							=			pipe.to(UpperCAmelCase__	)
								pipe.set_progress_bar_config(disable=UpperCAmelCase__	)
								pipe.enable_attention_slicing()

								__UpperCAmelCase							=			self.get_inputs()
								pipe(**UpperCAmelCase__     ,		callback=UpperCAmelCase__     ,		callback_steps=1	)
								assert callback_fn.has_been_called
								assert number_of_steps == 3






							def       snake_case__						(      self				:							int	)							->	Any:
								torch.cuda.empty_cache()
								torch.cuda.reset_max_memory_allocated()
								torch.cuda.reset_peak_memory_stats()

								__UpperCAmelCase							=			'''stabilityai/stable-diffusion-2-base'''
								__UpperCAmelCase							=			DDIMScheduler.from_pretrained(UpperCAmelCase__     ,		subfolder='''scheduler'''	)
								__UpperCAmelCase							=			StableDiffusionPanoramaPipeline.from_pretrained(UpperCAmelCase__     ,		scheduler=UpperCAmelCase__     ,		safety_checker=UpperCAmelCase__	)
								__UpperCAmelCase							=			pipe.to(UpperCAmelCase__	)
								pipe.set_progress_bar_config(disable=UpperCAmelCase__	)
								pipe.enable_attention_slicing(1	)
								pipe.enable_sequential_cpu_offload()

								__UpperCAmelCase							=			self.get_inputs()
								__UpperCAmelCase							=			pipe(**UpperCAmelCase__	)

								__UpperCAmelCase							=			torch.cuda.max_memory_allocated()
								# make sure that less than 5.2 GB is allocated
								assert mem_bytes < 5.5 * 1_0**9

'''simple docstring'''


import ast
import os
import re
import shutil
import tempfile
import unittest
from unittest import mock

import torch

from accelerate.test_utils.examples import compare_against_test
from accelerate.test_utils.testing import TempDirTestCase, require_trackers, run_command, slow
from accelerate.utils import write_basic_config


# DataLoaders built from `test_samples/MRPC` for quick testing
# Should mock `{script_name}.get_dataloaders` via:
# @mock.patch("{script_name}.get_dataloaders", mocked_dataloaders)

__lowerCAmelCase	:       Optional[int]						       =	[
    "cross_validation.py",
    "gradient_accumulation.py",
    "local_sgd.py",
    "multi_process_metrics.py",
    "memory.py",
    "automatic_gradient_accumulation.py",
    "fsdp_with_peak_mem_tracking.py",
    "deepspeed_with_config_support.py",
    "megatron_lm_gpt_pretraining.py",
]






class 						A   (   unittest.TestCase   ):





							def       snake_case__						(      self				:							Any     ,		__a				:							str     ,		__a				:							bool     ,		__a				:							str = None     ,		__a				:							list = None	)							->	Tuple:
								__UpperCAmelCase							=			None
								__UpperCAmelCase							=			os.path.abspath(os.path.join('''examples'''     ,		'''by_feature'''	)	)
								__UpperCAmelCase							=			os.path.abspath('''examples'''	)
								for item in os.listdir(__a	):
									if item not in EXCLUDE_EXAMPLES:
										__UpperCAmelCase							=			os.path.join(__a     ,		__a	)
										if os.path.isfile(__a	) and ".py" in item_path:
											with self.subTest(
											    tested_script=__a     ,		feature_script=__a     ,		tested_section='''main()''' if parser_only else '''training_function()'''     ,		):
												__UpperCAmelCase							=			compare_against_test(
												    os.path.join(__a     ,		__a	)     ,		__a     ,		__a     ,		__a	)
												__UpperCAmelCase							=			'''\n'''.join(__a	)
												if special_strings is not None:
													for string in special_strings:
														__UpperCAmelCase							=			diff.replace(__a     ,		''''''	)
												self.assertEqual(__a     ,		''''''	)





							def       snake_case__						(      self				:							Optional[Any]	)							->	str:
								self.one_complete_example('''complete_nlp_example.py'''     ,		__a	)
								self.one_complete_example('''complete_nlp_example.py'''     ,		__a	)






							def       snake_case__						(      self				:							List[str]	)							->	Tuple:
								__UpperCAmelCase							=			os.path.abspath(os.path.join('''examples'''     ,		'''cv_example.py'''	)	)
								__UpperCAmelCase							=			[
								    ''' ''' * 1_6 + '''{\n\n''',
								    ''' ''' * 2_0 + '''"accuracy": eval_metric["accuracy"],\n\n''',
								    ''' ''' * 2_0 + '''"f1": eval_metric["f1"],\n\n''',
								    ''' ''' * 2_0 + '''"train_loss": total_loss.item() / len(train_dataloader),\n\n''',
								    ''' ''' * 2_0 + '''"epoch": epoch,\n\n''',
								    ''' ''' * 1_6 + '''},\n\n''',
								    ''' ''' * 1_6 + '''step=epoch,\n''',
								    ''' ''' * 1_2,
								    ''' ''' * 8 + '''for step, batch in enumerate(active_dataloader):\n''',
								]
								self.one_complete_example('''complete_cv_example.py'''     ,		__a     ,		__a     ,		__a	)
								self.one_complete_example('''complete_cv_example.py'''     ,		__a     ,		__a     ,		__a	)






@mock.patch.dict(os.environ       ,	{'''TESTING_MOCKED_DATALOADERS''': '''1'''}   )
class 						A   (   UpperCAmelCase   ):
							a_        =      False





							@classmethod
							def       snake_case__						(      cls				:							Tuple	)							->	str:
								super().setUpClass()
								__UpperCAmelCase							=			tempfile.mkdtemp()
								__UpperCAmelCase							=			os.path.join(cls._tmpdir     ,		'''default_config.yml'''	)

								write_basic_config(save_location=cls.configPath	)
								__UpperCAmelCase							=			['''accelerate''', '''launch''', '''--config_file''', cls.configPath]





							@classmethod
							def       snake_case__						(      cls				:							Dict	)							->	int:
								super().tearDownClass()
								shutil.rmtree(cls._tmpdir	)





							def       snake_case__						(      self				:							Tuple	)							->	Dict:
								__UpperCAmelCase							=			f"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps epoch
        --output_dir {self.tmpdir}
        """.split()
								run_command(self._launch_args + testargs	)
								self.assertTrue(os.path.exists(os.path.join(self.tmpdir     ,		'''epoch_0'''	)	)	)





							def       snake_case__						(      self				:							str	)							->	int:
								__UpperCAmelCase							=			f"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps 1
        --output_dir {self.tmpdir}
        """.split()
								__UpperCAmelCase							=			run_command(self._launch_args + testargs	)
								self.assertTrue(os.path.exists(os.path.join(self.tmpdir     ,		'''step_2'''	)	)	)





							def       snake_case__						(      self				:							Any	)							->	Any:
								__UpperCAmelCase							=			f"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir     ,		'epoch_0'	)}
        """.split()
								__UpperCAmelCase							=			run_command(self._launch_args + testargs     ,		return_stdout=__a	)
								self.assertNotIn('''epoch 0:'''     ,		__a	)
								self.assertIn('''epoch 1:'''     ,		__a	)





							def       snake_case__						(      self				:							Tuple	)							->	Optional[int]:
								__UpperCAmelCase							=			f"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir     ,		'step_2'	)}
        """.split()
								__UpperCAmelCase							=			run_command(self._launch_args + testargs     ,		return_stdout=__a	)
								if torch.cuda.is_available():
									__UpperCAmelCase							=			torch.cuda.device_count()
								else:
									__UpperCAmelCase							=			1
								if num_processes > 1:
									self.assertNotIn('''epoch 0:'''     ,		__a	)
									self.assertIn('''epoch 1:'''     ,		__a	)
								else:
									self.assertIn('''epoch 0:'''     ,		__a	)
									self.assertIn('''epoch 1:'''     ,		__a	)





							@slow
							def       snake_case__						(      self				:							Any	)							->	Optional[Any]:
								__UpperCAmelCase							=			'''
        examples/by_feature/cross_validation.py
        --num_folds 2
        '''.split()
								with mock.patch.dict(os.environ     ,		{'''TESTING_MOCKED_DATALOADERS''': '''0'''}	):
									__UpperCAmelCase							=			run_command(self._launch_args + testargs     ,		return_stdout=__a	)
									__UpperCAmelCase							=			re.findall('''({.+})'''     ,		__a	)
									__UpperCAmelCase							=			[r for r in results if '''accuracy''' in r][-1]
									__UpperCAmelCase							=			ast.literal_eval(__a	)
									self.assertGreaterEqual(results['''accuracy''']     ,		0.7_5	)





							def       snake_case__						(      self				:							Dict	)							->	int:
								__UpperCAmelCase							=			['''examples/by_feature/multi_process_metrics.py''']
								run_command(self._launch_args + testargs	)





							@require_trackers
							@mock.patch.dict(os.environ     ,		{'''WANDB_MODE''': '''offline'''}	)
							def       snake_case__						(      self				:							Optional[Any]	)							->	Optional[int]:
								with tempfile.TemporaryDirectory() as tmpdir:
									__UpperCAmelCase							=			f"""
            examples/by_feature/tracking.py
            --with_tracking
            --project_dir {tmpdir}
            """.split()
									run_command(self._launch_args + testargs	)
									self.assertTrue(os.path.exists(os.path.join(__a     ,		'''tracking'''	)	)	)





							def       snake_case__						(      self				:							Optional[int]	)							->	List[Any]:
								__UpperCAmelCase							=			['''examples/by_feature/gradient_accumulation.py''']
								run_command(self._launch_args + testargs	)






							def       snake_case__						(      self				:							Tuple	)							->	Optional[Any]:
								__UpperCAmelCase							=			['''examples/by_feature/local_sgd.py''']
								run_command(self._launch_args + testargs	)
