import inspect
import logging
import os
import random
import shutil
import tempfile
import unittest

import pytest
import torch
from torch import nn
from torch.utils.data import DataLoader, TensorDataset

from accelerate import Accelerator
from accelerate.test_utils import execute_subprocess_async, require_cuda
from accelerate.utils import ProjectConfiguration, set_seed


A__           =							logging.getLogger(__name__)





def  _lowerCamelCase					(   a_				: Tuple=2						,			a_				: Optional[int]=3						,			a_				: Tuple=16						,			a_				: int = 10						,			a_				: int = 2):

			def get_dataset(a_				: List[str]):
						lowerCamelCase						:int						  =     torch.randn(batch_size * n_batches						,			1)
						return TensorDataset(a_						,			a * x + b + 0.1 * torch.randn(batch_size * n_batches						,			1))

			lowerCamelCase						:List[Any]						  =     get_dataset(a_)
			lowerCamelCase						:Dict						  =     get_dataset(a_)
			lowerCamelCase						:Optional[Any]						  =     DataLoader(a_						,			shuffle=a_						,			batch_size=a_						,			num_workers=4)
			lowerCamelCase						:int						  =     DataLoader(a_						,			shuffle=a_						,			batch_size=a_						,			num_workers=4)
			return (train_dataloader, valid_dataloader)





def  _lowerCamelCase					(   a_				: Any						,			a_				: Dict						,			a_				: str						,			a_				: List[str]						,			a_				: Optional[int]						,			a_				: Union[str, Any]=None):
			lowerCamelCase						:int						  =     []
			for epoch in range(a_):
						# Train quickly
						model.train()
						for batch in dataloader:
									lowerCamelCase  ,    lowerCamelCase						:List[Any]						  =     batch
									lowerCamelCase						:List[Any]						  =     model(a_)
									lowerCamelCase						:Dict						  =     torch.nn.functional.mse_loss(a_						,			a_)
									accelerator.backward(a_)
									optimizer.step()
									optimizer.zero_grad()
						rands.append(random.random())  # Introduce some randomness
						if scheduler is not None:
									scheduler.step()
			return rands
class   _lowerCAmelCase		(     nn.Module				):







							def __init__(				self     :    Optional[int]		):
										super().__init__()
										lowerCamelCase						:Optional[int]						  =     nn.Parameter(torch.randn(1		)		)
										lowerCamelCase						:List[Any]						  =     nn.Parameter(torch.randn(1		)		)







							def 				snake_case  (				self     :    Optional[Any]	,					__snake_case     :    List[str]		):
										return x * self.a + self.b


class   _lowerCAmelCase		(     unittest.TestCase				):







							def 				snake_case  (				self     :    Union[str, Any]		):
										with tempfile.TemporaryDirectory() as tmpdir:
													set_seed(42		)
													lowerCamelCase						:Optional[Any]						  =     DummyModel()
													lowerCamelCase						:Optional[Any]						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase  ,    lowerCamelCase						:str						  =     dummy_dataloaders()
													lowerCamelCase						:List[Any]						  =     ProjectConfiguration(total_limit=1	,					project_dir=__snake_case	,					automatic_checkpoint_naming=__snake_case		)
													# Train baseline
													lowerCamelCase						:List[str]						  =     Accelerator(project_config=__snake_case		)
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:Dict						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save initial
													accelerator.save_state()

													# Save second state
													accelerator.save_state()
													self.assertEqual(len(os.listdir(accelerator.project_dir		)		)	,					1		)







							def 				snake_case  (				self     :    Optional[Any]		):
										with tempfile.TemporaryDirectory() as tmpdir:
													set_seed(42		)
													lowerCamelCase						:int						  =     DummyModel()
													lowerCamelCase						:str						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase  ,    lowerCamelCase						:int						  =     dummy_dataloaders()
													# Train baseline
													lowerCamelCase						:Optional[Any]						  =     Accelerator()
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:str						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save initial
													lowerCamelCase						:Optional[int]						  =     os.path.join(__snake_case	,					'''initial'''		)
													accelerator.save_state(__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:Union[str, Any]						  =     model.a.item(), model.b.item()
													lowerCamelCase						:List[str]						  =     optimizer.state_dict()
													lowerCamelCase						:Union[str, Any]						  =     train(3	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:Tuple						  =     model.a.item(), model.b.item()
													lowerCamelCase						:str						  =     optimizer.state_dict()

													# Train partially
													set_seed(42		)
													lowerCamelCase						:Union[str, Any]						  =     DummyModel()
													lowerCamelCase						:int						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase  ,    lowerCamelCase						:Optional[Any]						  =     dummy_dataloaders()
													lowerCamelCase						:Optional[Any]						  =     Accelerator()
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:Dict						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													accelerator.load_state(__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:Union[str, Any]						  =     model.a.item(), model.b.item()
													lowerCamelCase						:List[Any]						  =     optimizer.state_dict()
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)

													lowerCamelCase						:List[Any]						  =     train(2	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save everything
													lowerCamelCase						:int						  =     os.path.join(__snake_case	,					'''checkpoint'''		)
													accelerator.save_state(__snake_case		)

													# Load everything back in and make sure all states work
													accelerator.load_state(__snake_case		)
													test_rands += train(1	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:Union[str, Any]						  =     model.a.item(), model.b.item()
													lowerCamelCase						:str						  =     optimizer.state_dict()
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)







							def 				snake_case  (				self     :    str		):
										with tempfile.TemporaryDirectory() as tmpdir:
													set_seed(42		)
													lowerCamelCase						:str						  =     DummyModel()
													lowerCamelCase						:List[str]						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase  ,    lowerCamelCase						:Union[str, Any]						  =     dummy_dataloaders()
													lowerCamelCase						:Any						  =     ProjectConfiguration(automatic_checkpoint_naming=__snake_case		)

													# Train baseline
													lowerCamelCase						:int						  =     Accelerator(project_dir=__snake_case	,					project_config=__snake_case		)
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:str						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save initial
													accelerator.save_state()
													((lowerCamelCase)  ,    (lowerCamelCase))						:List[Any]						  =     model.a.item(), model.b.item()
													lowerCamelCase						:Any						  =     optimizer.state_dict()
													lowerCamelCase						:List[Any]						  =     train(3	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:List[Any]						  =     model.a.item(), model.b.item()
													lowerCamelCase						:Dict						  =     optimizer.state_dict()

													# Train partially
													set_seed(42		)
													lowerCamelCase						:Dict						  =     DummyModel()
													lowerCamelCase						:Union[str, Any]						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase  ,    lowerCamelCase						:Optional[Any]						  =     dummy_dataloaders()
													lowerCamelCase						:Tuple						  =     ProjectConfiguration(iteration=1	,					automatic_checkpoint_naming=__snake_case		)
													lowerCamelCase						:List[str]						  =     Accelerator(project_dir=__snake_case	,					project_config=__snake_case		)
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:Tuple						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													accelerator.load_state(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_0'''		)		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:int						  =     model.a.item(), model.b.item()
													lowerCamelCase						:Any						  =     optimizer.state_dict()
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)

													lowerCamelCase						:List[str]						  =     train(2	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save everything
													accelerator.save_state()

													# Load everything back in and make sure all states work
													accelerator.load_state(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_1'''		)		)
													test_rands += train(1	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													((lowerCamelCase)  ,    (lowerCamelCase))						:Any						  =     model.a.item(), model.b.item()
													lowerCamelCase						:int						  =     optimizer.state_dict()
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)
													self.assertEqual(__snake_case	,					__snake_case		)







							def 				snake_case  (				self     :    Dict		):
										lowerCamelCase						:str						  =     torch.tensor([1, 2, 3]		)
										lowerCamelCase						:int						  =     torch.tensor([2, 3, 4]		)
										lowerCamelCase						:Union[str, Any]						  =     DummyModel()
										lowerCamelCase						:Any						  =     torch.optim.Adam(net.parameters()		)
										lowerCamelCase						:Union[str, Any]						  =     Accelerator()
										with self.assertRaises(__snake_case		) as ve:
													accelerator.register_for_checkpointing(__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
										lowerCamelCase						:Union[str, Any]						  =     str(ve.exception		)
										self.assertTrue('''Item at index 0''' in message		)
										self.assertTrue('''Item at index 1''' in message		)
										self.assertFalse('''Item at index 2''' in message		)
										self.assertFalse('''Item at index 3''' in message		)







							def 				snake_case  (				self     :    Any		):
										with tempfile.TemporaryDirectory() as tmpdir:
													set_seed(42		)
													lowerCamelCase						:List[str]						  =     DummyModel()
													lowerCamelCase						:Optional[Any]						  =     torch.optim.Adam(params=model.parameters()	,					lr=1e-3		)
													lowerCamelCase						:Optional[int]						  =     torch.optim.lr_scheduler.StepLR(__snake_case	,					step_size=1	,					gamma=0.9_9		)
													lowerCamelCase  ,    lowerCamelCase						:List[Any]						  =     dummy_dataloaders()
													lowerCamelCase						:Tuple						  =     ProjectConfiguration(automatic_checkpoint_naming=__snake_case		)
													# Train baseline
													lowerCamelCase						:List[Any]						  =     Accelerator(project_dir=__snake_case	,					project_config=__snake_case		)
													lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase  ,    lowerCamelCase						:str						  =     accelerator.prepare(
													    __snake_case	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													# Save initial
													accelerator.save_state()
													lowerCamelCase						:Optional[Any]						  =     scheduler.state_dict()
													train(3	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case	,					__snake_case		)
													self.assertNotEqual(__snake_case	,					scheduler.state_dict()		)

													# Load everything back in and make sure all states work
													accelerator.load_state(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_0'''		)		)
													self.assertEqual(__snake_case	,					scheduler.state_dict()		)







							def 				snake_case  (				self     :    Any		):
										with tempfile.TemporaryDirectory() as tmpdir:
													set_seed(42		)
													lowerCamelCase						:int						  =     DummyModel()
													lowerCamelCase						:Optional[Any]						  =     ProjectConfiguration(automatic_checkpoint_naming=__snake_case	,					total_limit=2		)
													# Train baseline
													lowerCamelCase						:Dict						  =     Accelerator(project_dir=__snake_case	,					project_config=__snake_case		)
													lowerCamelCase						:Tuple						  =     accelerator.prepare(__snake_case		)
													# Save 3 states:
													for _ in range(11		):
																accelerator.save_state()
													self.assertTrue(not os.path.exists(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_0'''		)		)		)
													self.assertTrue(os.path.exists(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_9'''		)		)		)
													self.assertTrue(os.path.exists(os.path.join(__snake_case	,					'''checkpoints'''	,					'''checkpoint_10'''		)		)		)







							@require_cuda
							def 				snake_case  (				self     :    str		):
										lowerCamelCase						:List[str]						  =     ['''torchrun''', F"--nproc_per_node={torch.cuda.device_count()}", inspect.getfile(self.__class__		)]
										execute_subprocess_async(__snake_case	,					env=os.environ.copy()		)


if __name__ == "__main__":
			A__           =							"""/tmp/accelerate/state_checkpointing"""
			A__           =							DummyModel()
			A__           =							torch.optim.Adam(params=model.parameters(), lr=1E-3)
			A__           =							torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.99)
			A__      ,					A__           =							dummy_dataloaders()
			A__           =							ProjectConfiguration(automatic_checkpoint_naming=True)
			# Train baseline
			A__           =							Accelerator(project_dir=savedir, project_config=project_config, mixed_precision="""no""")
			if accelerator.process_index == 0:
						if os.path.exists(savedir):
									shutil.rmtree(savedir)
						os.makedirs(savedir)
			A__      ,					A__      ,					A__      ,					A__      ,					A__           =							accelerator.prepare(
			    model, optimizer, train_dataloader, valid_dataloader, scheduler
			)
			A__      ,					A__           =							accelerator.prepare(model, optimizer)
			train(3, model, train_dataloader, optimizer, accelerator, scheduler)
			# Check that the intial optimizer is loaded on the GPU
			for group in optimizer.param_groups:
						A__           =							group["""params"""][0].device
						break
			assert param_device.type == accelerator.device.type
			A__           =							model.cpu()
			accelerator.wait_for_everyone()
			accelerator.save_state()
			accelerator.wait_for_everyone()

			# Check CPU state
			accelerator.load_state(os.path.join(savedir, """checkpoints""", """checkpoint_0"""), map_location="""cpu""")
			for group in optimizer.param_groups:
						A__           =							group["""params"""][0].device
						break
			assert (
			    param_device.type == torch.device("""cpu""").type
			), F"Loaded optimizer states did not match, expected to be loaded on the CPU but got {param_device}"

			# Check device state
			model.to(accelerator.device)
			accelerator.load_state(os.path.join(savedir, """checkpoints""", """checkpoint_0"""), map_location="""on_device""")
			for group in optimizer.param_groups:
						A__           =							group["""params"""][0].device
						break
			assert (
			    param_device.type == accelerator.device.type
			), F"Loaded optimizer states did not match, expected to be loaded on {accelerator.device} but got {param_device}"

			# Check error
			with pytest.raises(TypeError, match="""Unsupported optimizer map location passed"""):
						accelerator.load_state(os.path.join(savedir, """checkpoints""", """checkpoint_0"""), map_location="""invalid""")
			accelerator.wait_for_everyone()
			if accelerator.process_index == 0:
						shutil.rmtree(savedir)
			accelerator.wait_for_everyone()




import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:
			class   _lowerCAmelCase		:







										@staticmethod
										def 				snake_case  (				*__snake_case     :    str	,					**__snake_case     :    str		):
													pass
@is_pipeline_test
@require_vision
class   _lowerCAmelCase		(     unittest.TestCase				):







							@require_torch
							def 				snake_case  (				self     :    Union[str, Any]		):
										lowerCamelCase						:Optional[int]						  =     pipeline(
										    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''	,					)
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Dict						  =     image_classifier(__snake_case	,					candidate_labels=['''a''', '''b''', '''c''']		)

										# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
										# python and torch versions.
										self.assertIn(
										    nested_simplify(__snake_case		)	,					[
										        [{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}],
										        [{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}],
										    ]	,					)

										lowerCamelCase						:Tuple						  =     image_classifier([image] * 5	,					candidate_labels=['''A''', '''B''', '''C''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										    ]	,					)







							@require_tf
							def 				snake_case  (				self     :    Tuple		):
										lowerCamelCase						:Tuple						  =     pipeline(
										    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''	,					framework='''tf'''		)
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Optional[Any]						  =     image_classifier(__snake_case	,					candidate_labels=['''a''', '''b''', '''c''']		)

										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[{'''score''': 0.3_3_3, '''label''': '''a'''}, {'''score''': 0.3_3_3, '''label''': '''b'''}, {'''score''': 0.3_3_3, '''label''': '''c'''}]	,					)

										lowerCamelCase						:int						  =     image_classifier([image] * 5	,					candidate_labels=['''A''', '''B''', '''C''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										        [
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										            {'''score''': 0.3_3_3, '''label''': ANY(__snake_case		)},
										        ],
										    ]	,					)







							@slow
							@require_torch
							def 				snake_case  (				self     :    Any		):
										lowerCamelCase						:str						  =     pipeline(
										    task='''zero-shot-image-classification'''	,					model='''openai/clip-vit-base-patch32'''	,					)
										# This is an image of 2 cats with remotes and no planes
										lowerCamelCase						:List[str]						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Optional[Any]						  =     image_classifier(__snake_case	,					candidate_labels=['''cat''', '''plane''', '''remote''']		)

										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        {'''score''': 0.5_1_1, '''label''': '''remote'''},
										        {'''score''': 0.4_8_5, '''label''': '''cat'''},
										        {'''score''': 0.0_0_4, '''label''': '''plane'''},
										    ]	,					)

										lowerCamelCase						:Any						  =     image_classifier([image] * 5	,					candidate_labels=['''cat''', '''plane''', '''remote''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.5_1_1, '''label''': '''remote'''},
										            {'''score''': 0.4_8_5, '''label''': '''cat'''},
										            {'''score''': 0.0_0_4, '''label''': '''plane'''},
										        ],
										    ]
										    * 5	,					)







							@slow
							@require_tf
							def 				snake_case  (				self     :    Optional[Any]		):
										lowerCamelCase						:Union[str, Any]						  =     pipeline(
										    task='''zero-shot-image-classification'''	,					model='''openai/clip-vit-base-patch32'''	,					framework='''tf'''		)
										# This is an image of 2 cats with remotes and no planes
										lowerCamelCase						:Dict						  =     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
										lowerCamelCase						:Dict						  =     image_classifier(__snake_case	,					candidate_labels=['''cat''', '''plane''', '''remote''']		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        {'''score''': 0.5_1_1, '''label''': '''remote'''},
										        {'''score''': 0.4_8_5, '''label''': '''cat'''},
										        {'''score''': 0.0_0_4, '''label''': '''plane'''},
										    ]	,					)

										lowerCamelCase						:Any						  =     image_classifier([image] * 5	,					candidate_labels=['''cat''', '''plane''', '''remote''']	,					batch_size=2		)
										self.assertEqual(
										    nested_simplify(__snake_case		)	,					[
										        [
										            {'''score''': 0.5_1_1, '''label''': '''remote'''},
										            {'''score''': 0.4_8_5, '''label''': '''cat'''},
										            {'''score''': 0.0_0_4, '''label''': '''plane'''},
										        ],
										    ]
										    * 5	,					)



