



"""simple docstring"""
import argparse
import os
import re

import numpy as np
import PIL
import torch
from timm import create_model
from torch.optim.lr_scheduler import OneCycleLR
from torch.utils.data import DataLoader, Dataset
from torchvision.transforms import Compose, RandomResizedCrop, Resize, ToTensor

from accelerate import Accelerator



def        lowerCAmelCase_(   lowercase_     :							Optional[Any]							)	->       Optional[Any]:
				_lowerCamelCase        =				fname.split(os.path.sep							)[-1]
				return re.search(r'''^(.*)_\d+\.jpg$'''						,   lowercase_							).groups()[0]


class 							lowerCamelCase_(   A__    ):





					'''simple docstring'''



					def __init__(    self				,       lowerCamelCase__				,       lowerCamelCase__=None				,       lowerCamelCase__=None   ):
									_lowerCamelCase        =				file_names
									_lowerCamelCase        =				image_transform
									_lowerCamelCase        =				label_to_id

					def __len__(    self   ):
									return len(self.file_names   )





					def __getitem__(    self				,       lowerCamelCase__   ):
									_lowerCamelCase        =				self.file_names[idx]
									_lowerCamelCase        =				PIL.Image.open(lowerCamelCase__   )
									_lowerCamelCase        =				raw_image.convert('''RGB'''   )
									if self.image_transform is not None:
													_lowerCamelCase        =				self.image_transform(lowerCamelCase__   )
									_lowerCamelCase        =				extract_label(lowerCamelCase__   )
									if self.label_to_id is not None:
													_lowerCamelCase        =				self.label_to_id[label]
									return {"image": image, "label": label}



def        lowerCAmelCase_(   lowercase_     :							List[Any]						,   lowercase_     :							List[Any]							)	->       Union[str, Any]:
				# Initialize accelerator
				if args.with_tracking:
								_lowerCamelCase        =				Accelerator(
								    cpu=args.cpu						,   mixed_precision=args.mixed_precision						,   log_with='''all'''						,   project_dir=args.project_dir							)
				else:
								_lowerCamelCase        =				Accelerator(cpu=args.cpu						,   mixed_precision=args.mixed_precision							)

				# Sample hyper-parameters for learning rate, batch size, seed and a few other HPs
				_lowerCamelCase        =				config['''lr''']
				_lowerCamelCase        =				int(config['''num_epochs''']							)
				_lowerCamelCase        =				int(config['''seed''']							)
				_lowerCamelCase        =				int(config['''batch_size''']							)
				_lowerCamelCase        =				config['''image_size''']
				if not isinstance(lowercase_						,   (list, tuple)							):
								_lowerCamelCase        =				(image_size, image_size)

				# Parse out whether we are saving every epoch or after a certain number of batches
				if hasattr(args.checkpointing_steps						,   '''isdigit'''							):
								if args.checkpointing_steps == "epoch":
												_lowerCamelCase        =				args.checkpointing_steps
								elif args.checkpointing_steps.isdigit():
												_lowerCamelCase        =				int(args.checkpointing_steps							)
								else:
												raise ValueError(
												    F"""Argument `checkpointing_steps` must be either a number or `epoch`. `{args.checkpointing_steps}` passed."""							)
				else:
								_lowerCamelCase        =				None

				# We need to initialize the trackers we use, and also store our configuration
				if args.with_tracking:
								_lowerCamelCase        =				os.path.split(lowercase_							)[-1].split('''.'''							)[0]
								accelerator.init_trackers(lowercase_						,   lowercase_							)

				# Grab all the image filenames
				_lowerCamelCase        =				[os.path.join(args.data_dir						,   lowercase_							) for fname in os.listdir(args.data_dir							) if fname.endswith('''.jpg'''							)]

				# Build the label correspondences
				_lowerCamelCase        =				[extract_label(lowercase_							) for fname in file_names]
				_lowerCamelCase        =				list(set(lowercase_							)							)
				id_to_label.sort()
				_lowerCamelCase        =				{lbl: i for i, lbl in enumerate(lowercase_							)}

				# Set the seed before splitting the data.
				np.random.seed(lowercase_							)
				torch.manual_seed(lowercase_							)
				torch.cuda.manual_seed_all(lowercase_							)

				# Split our filenames between train and validation
				_lowerCamelCase        =				np.random.permutation(len(lowercase_							)							)
				_lowerCamelCase        =				int(0.8 * len(lowercase_							)							)
				_lowerCamelCase        =				random_perm[:cut]
				_lowerCamelCase        =				random_perm[cut:]

				# For training we use a simple RandomResizedCrop
				_lowerCamelCase        =				Compose([RandomResizedCrop(lowercase_						,   scale=(0.5, 1.0)							), ToTensor()]							)
				_lowerCamelCase        =				PetsDataset(
				    [file_names[i] for i in train_split]						,   image_transform=lowercase_						,   label_to_id=lowercase_							)

				# For evaluation, we use a deterministic Resize
				_lowerCamelCase        =				Compose([Resize(lowercase_							), ToTensor()]							)
				_lowerCamelCase        =				PetsDataset([file_names[i] for i in eval_split]						,   image_transform=lowercase_						,   label_to_id=lowercase_							)

				# Instantiate dataloaders.
				_lowerCamelCase        =				DataLoader(lowercase_						,   shuffle=lowercase_						,   batch_size=lowercase_						,   num_workers=4							)
				_lowerCamelCase        =				DataLoader(lowercase_						,   shuffle=lowercase_						,   batch_size=lowercase_						,   num_workers=4							)

				# Instantiate the model (we build the model here so that the seed also control new weights initialization)
				_lowerCamelCase        =				create_model('''resnet50d'''						,   pretrained=lowercase_						,   num_classes=len(lowercase_							)							)

				# We could avoid this line since the accelerator is set with `device_placement=True` (default value).
				# Note that if you are placing tensors on devices manually, this line absolutely needs to be before the optimizer
				# creation otherwise training will not work on TPU (`accelerate` will kindly throw an error to make us aware of that).
				_lowerCamelCase        =				model.to(accelerator.device							)

				# Freezing the base model
				for param in model.parameters():
								_lowerCamelCase        =				False
				for param in model.get_classifier().parameters():
								_lowerCamelCase        =				True

				# We normalize the batches of images to be a bit faster.
				_lowerCamelCase        =				torch.tensor(model.default_cfg['''mean''']							)[None, :, None, None].to(accelerator.device							)
				_lowerCamelCase        =				torch.tensor(model.default_cfg['''std''']							)[None, :, None, None].to(accelerator.device							)

				# Instantiate optimizer
				_lowerCamelCase        =				torch.optim.Adam(params=model.parameters()						,   lr=lr / 25							)

				# Instantiate learning rate scheduler
				_lowerCamelCase        =				OneCycleLR(optimizer=lowercase_						,   max_lr=lowercase_						,   epochs=lowercase_						,   steps_per_epoch=len(lowercase_							)							)

				# Prepare everything
				# There is no specific order to remember, we just need to unpack the objects in the same order we gave them to the
				# prepare method.
				_lowerCamelCase  ,     _lowerCamelCase  ,     _lowerCamelCase  ,     _lowerCamelCase  ,     _lowerCamelCase        =				accelerator.prepare(
				    lowercase_						,   lowercase_						,   lowercase_						,   lowercase_						,   lowercase_							)
				# We need to keep track of how many total steps we have iterated over
				_lowerCamelCase        =				0
				# We also need to keep track of the starting epoch so files are named properly
				_lowerCamelCase        =				0

				# Potentially load in the weights and states from a previous save
				if args.resume_from_checkpoint:
								if args.resume_from_checkpoint is not None or args.resume_from_checkpoint != "":
												accelerator.print(F"""Resumed from checkpoint: {args.resume_from_checkpoint}"""							)
												accelerator.load_state(args.resume_from_checkpoint							)
												_lowerCamelCase        =				os.path.basename(args.resume_from_checkpoint							)
								else:
												# Get the most recent checkpoint
												_lowerCamelCase        =				[f.name for f in os.scandir(os.getcwd()							) if f.is_dir()]
												dirs.sort(key=os.path.getctime							)
												_lowerCamelCase        =				dirs[-1]  # Sorts folders by date modified, most recent checkpoint is the last
								# Extract `epoch_{i}` or `step_{i}`
								_lowerCamelCase        =				os.path.splitext(lowercase_							)[0]

								if "epoch" in training_difference:
												_lowerCamelCase        =				int(training_difference.replace('''epoch_'''						,   ''''''							)							) + 1
												_lowerCamelCase        =				None
								else:
												_lowerCamelCase        =				int(training_difference.replace('''step_'''						,   ''''''							)							)
												_lowerCamelCase        =				resume_step // len(lowercase_							)
												resume_step -= starting_epoch * len(lowercase_							)

    # Now we train the model
				for epoch in range(lowercase_						,   lowercase_							):
								model.train()
								if args.with_tracking:
												_lowerCamelCase        =				0
								if args.resume_from_checkpoint and epoch == starting_epoch and resume_step is not None:
												# We need to skip steps until we reach the resumed step
												_lowerCamelCase        =				accelerator.skip_first_batches(lowercase_						,   lowercase_							)
												overall_step += resume_step
								else:
												# After the first iteration though, we need to go back to the original dataloader
												_lowerCamelCase        =				train_dataloader
								for batch in active_dataloader:
												# We could avoid this line since we set the accelerator with `device_placement=True`.
												_lowerCamelCase        =				{k: v.to(accelerator.device							) for k, v in batch.items()}
												_lowerCamelCase        =				(batch['''image'''] - mean) / std
												_lowerCamelCase        =				model(lowercase_							)
												_lowerCamelCase        =				torch.nn.functional.cross_entropy(lowercase_						,   batch['''label''']							)
												# We keep track of the loss at each epoch
												if args.with_tracking:
																total_loss += loss.detach().float()
												accelerator.backward(lowercase_							)
												optimizer.step()
												lr_scheduler.step()
												optimizer.zero_grad()
												overall_step += 1
												if isinstance(lowercase_						,   lowercase_							):
																_lowerCamelCase        =				F"""step_{overall_step}"""
																if overall_step % checkpointing_steps == 0:
																				if args.output_dir is not None:
																								_lowerCamelCase        =				os.path.join(args.output_dir						,   lowercase_							)
																				accelerator.save_state(lowercase_							)
								model.eval()
								_lowerCamelCase        =				0
								_lowerCamelCase        =				0
								for step, batch in enumerate(lowercase_							):
												# We could avoid this line since we set the accelerator with `device_placement=True`.
												_lowerCamelCase        =				{k: v.to(accelerator.device							) for k, v in batch.items()}
												_lowerCamelCase        =				(batch['''image'''] - mean) / std
												with torch.no_grad():
																_lowerCamelCase        =				model(lowercase_							)
												_lowerCamelCase        =				outputs.argmax(dim=-1							)
												_lowerCamelCase  ,     _lowerCamelCase        =				accelerator.gather_for_metrics((predictions, batch['''label'''])							)
												_lowerCamelCase        =				predictions == references
												num_elems += accurate_preds.shape[0]
												accurate += accurate_preds.long().sum()

								_lowerCamelCase        =				accurate.item() / num_elems
								# Use accelerator.print to print only on the main process.
								accelerator.print(F"""epoch {epoch}: {1_00 * eval_metric:.2f}"""							)
								if args.with_tracking:
												accelerator.log(
												    {
												        '''accuracy''': 1_00 * eval_metric,
												        '''train_loss''': total_loss.item() / len(lowercase_							),
												        '''epoch''': epoch,
												    }						,   step=lowercase_						,   )
								if checkpointing_steps == "epoch":
												_lowerCamelCase        =				F"""epoch_{epoch}"""
												if args.output_dir is not None:
																_lowerCamelCase        =				os.path.join(args.output_dir						,   lowercase_							)
												accelerator.save_state(lowercase_							)

				if args.with_tracking:
								accelerator.end_training()



def        lowerCAmelCase_(   )	->       str:
				_lowerCamelCase        =				argparse.ArgumentParser(description='''Simple example of training script.'''							)
				parser.add_argument('''--data_dir'''						,   required=lowercase_						,   help='''The data folder on disk.'''							)
				parser.add_argument('''--fp16'''						,   action='''store_true'''						,   help='''If passed, will use FP16 training.'''							)
				parser.add_argument(
				    '''--mixed_precision'''						,   type=lowercase_						,   default=lowercase_						,   choices=['''no''', '''fp16''', '''bf16''', '''fp8''']						,   help='''Whether to use mixed precision. Choose'''
				    '''between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >= 1.10.'''
				    '''and an Nvidia Ampere GPU.'''						,   )
				parser.add_argument('''--cpu'''						,   action='''store_true'''						,   help='''If passed, will train on the CPU.'''							)
				parser.add_argument(
				    '''--checkpointing_steps'''						,   type=lowercase_						,   default=lowercase_						,   help='''Whether the various states should be saved at the end of every n steps, or \'epoch\' for each epoch.'''						,   )
				parser.add_argument(
				    '''--output_dir'''						,   type=lowercase_						,   default='''.'''						,   help='''Optional save directory where all checkpoint folders will be stored. Default is the current working directory.'''						,   )
				parser.add_argument(
				    '''--resume_from_checkpoint'''						,   type=lowercase_						,   default=lowercase_						,   help='''If the training should continue from a checkpoint folder.'''						,   )
				parser.add_argument(
				    '''--with_tracking'''						,   action='''store_true'''						,   help='''Whether to load in all available experiment trackers from the environment and use them for logging.'''						,   )
				parser.add_argument(
				    '''--project_dir'''						,   type=lowercase_						,   default='''logs'''						,   help='''Location on where to store experiment tracking logs` and relevent project information'''						,   )
				_lowerCamelCase        =				parser.parse_args()
				_lowerCamelCase        =				{'''lr''': 3e-2, '''num_epochs''': 3, '''seed''': 42, '''batch_size''': 64, '''image_size''': 2_24}
				training_function(lowercase_						,   lowercase_							)


if __name__ == "__main__":
			main()





"""simple docstring"""
import itertools
import os
import random
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers import is_speech_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
			from transformers import WhisperFeatureExtractor

if is_torch_available():
			import torch

__SCREAMING_SNAKE_CASE  :						Dict    							=      random.Random()



def        lowerCAmelCase_(   lowercase_     :							Dict						,   lowercase_     :							int=1.0						,   lowercase_     :							str=None						,   lowercase_     :							Optional[int]=None							)	->       Any:
				if rng is None:
								_lowerCamelCase        =				global_rng

				_lowerCamelCase        =				[]
				for batch_idx in range(shape[0]							):
								values.append([]							)
								for _ in range(shape[1]							):
												values[-1].append(rng.random() * scale							)

				return values


@require_torch
@require_torchaudio
class 							lowerCamelCase_(   unittest.TestCase    ):





					'''simple docstring'''



					def __init__(    self				,       lowerCamelCase__				,       lowerCamelCase__=7				,       lowerCamelCase__=4_0_0				,       lowerCamelCase__=2_0_0_0				,       lowerCamelCase__=1_0				,       lowerCamelCase__=1_6_0				,       lowerCamelCase__=8				,       lowerCamelCase__=0.0				,       lowerCamelCase__=4_0_0_0				,       lowerCamelCase__=False				,       lowerCamelCase__=True				,       ):
									_lowerCamelCase        =				parent
									_lowerCamelCase        =				batch_size
									_lowerCamelCase        =				min_seq_length
									_lowerCamelCase        =				max_seq_length
									_lowerCamelCase        =				(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
									_lowerCamelCase        =				padding_value
									_lowerCamelCase        =				sampling_rate
									_lowerCamelCase        =				return_attention_mask
									_lowerCamelCase        =				do_normalize
									_lowerCamelCase        =				feature_size
									_lowerCamelCase        =				chunk_length
									_lowerCamelCase        =				hop_length

					def 			snake_case__      (    self   ):
									return {
									    "feature_size": self.feature_size,
									    "hop_length": self.hop_length,
									    "chunk_length": self.chunk_length,
									    "padding_value": self.padding_value,
									    "sampling_rate": self.sampling_rate,
									    "return_attention_mask": self.return_attention_mask,
									    "do_normalize": self.do_normalize,
									}





					def 			snake_case__      (    self				,       lowerCamelCase__=False				,       lowerCamelCase__=False   ):
									def _flatten(lowerCamelCase__   ):
													return list(itertools.chain(*lowerCamelCase__   )   )

									if equal_length:
													_lowerCamelCase        =				[floats_list((self.max_seq_length, self.feature_size)   ) for _ in range(self.batch_size   )]
									else:
													# make sure that inputs increase in size
													_lowerCamelCase        =				[
													    floats_list((x, self.feature_size)   )
													    for x in range(self.min_seq_length				,       self.max_seq_length				,       self.seq_length_diff   )
													]
									if numpify:
													_lowerCamelCase        =				[np.asarray(lowerCamelCase__   ) for x in speech_inputs]
									return speech_inputs


@require_torch
@require_torchaudio
class 							lowerCamelCase_(   A__,				unittest.TestCase    ):





					'''simple docstring'''



					lowercase__   :       Optional[int]										= WhisperFeatureExtractor if is_speech_available() else None

					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				WhisperFeatureExtractionTester(self   )

					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				self.feature_extraction_class(**self.feat_extract_dict   )

									with tempfile.TemporaryDirectory() as tmpdirname:
													_lowerCamelCase        =				feat_extract_first.save_pretrained(lowerCamelCase__   )[0]
													check_json_file_has_correct_format(lowerCamelCase__   )
													_lowerCamelCase        =				self.feature_extraction_class.from_pretrained(lowerCamelCase__   )

									_lowerCamelCase        =				feat_extract_first.to_dict()
									_lowerCamelCase        =				feat_extract_second.to_dict()
									_lowerCamelCase        =				feat_extract_first.mel_filters
									_lowerCamelCase        =				feat_extract_second.mel_filters
									self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__   )   )
									self.assertEqual(lowerCamelCase__				,       lowerCamelCase__   )

					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				self.feature_extraction_class(**self.feat_extract_dict   )

									with tempfile.TemporaryDirectory() as tmpdirname:
													_lowerCamelCase        =				os.path.join(lowerCamelCase__				,       '''feat_extract.json'''   )
													feat_extract_first.to_json_file(lowerCamelCase__   )
													_lowerCamelCase        =				self.feature_extraction_class.from_json_file(lowerCamelCase__   )

									_lowerCamelCase        =				feat_extract_first.to_dict()
									_lowerCamelCase        =				feat_extract_second.to_dict()
									_lowerCamelCase        =				feat_extract_first.mel_filters
									_lowerCamelCase        =				feat_extract_second.mel_filters
									self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__   )   )
									self.assertEqual(lowerCamelCase__				,       lowerCamelCase__   )

					def 			snake_case__      (    self   ):
									# Tests that all call wrap to encode_plus and batch_encode_plus
									_lowerCamelCase        =				self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
									# create three inputs of length 800, 1000, and 1200
									_lowerCamelCase        =				[floats_list((1, x)   )[0] for x in range(8_0_0				,       1_4_0_0				,       2_0_0   )]
									_lowerCamelCase        =				[np.asarray(lowerCamelCase__   ) for speech_input in speech_inputs]

									# Test feature size
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       padding='''max_length'''				,       return_tensors='''np'''   ).input_features
									self.assertTrue(input_features.ndim == 3   )
									self.assertTrue(input_features.shape[-1] == feature_extractor.nb_max_frames   )
									self.assertTrue(input_features.shape[-2] == feature_extractor.feature_size   )

									# Test not batched input
									_lowerCamelCase        =				feature_extractor(speech_inputs[0]				,       return_tensors='''np'''   ).input_features
									_lowerCamelCase        =				feature_extractor(np_speech_inputs[0]				,       return_tensors='''np'''   ).input_features
									self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__				,       atol=1e-3   )   )

									# Test batched
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									for enc_seq_a, enc_seq_a in zip(lowerCamelCase__				,       lowerCamelCase__   ):
													self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__				,       atol=1e-3   )   )

									# Test 2-D numpy arrays are batched.
									_lowerCamelCase        =				[floats_list((1, x)   )[0] for x in (8_0_0, 8_0_0, 8_0_0)]
									_lowerCamelCase        =				np.asarray(lowerCamelCase__   )
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									for enc_seq_a, enc_seq_a in zip(lowerCamelCase__				,       lowerCamelCase__   ):
													self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__				,       atol=1e-3   )   )

									# Test truncation required
									_lowerCamelCase        =				[floats_list((1, x)   )[0] for x in range(2_0_0				,       (feature_extractor.n_samples + 5_0_0)				,       2_0_0   )]
									_lowerCamelCase        =				[np.asarray(lowerCamelCase__   ) for speech_input in speech_inputs]

									_lowerCamelCase        =				[x[: feature_extractor.n_samples] for x in speech_inputs]
									_lowerCamelCase        =				[np.asarray(lowerCamelCase__   ) for speech_input in speech_inputs_truncated]

									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''np'''   ).input_features
									for enc_seq_a, enc_seq_a in zip(lowerCamelCase__				,       lowerCamelCase__   ):
													self.assertTrue(np.allclose(lowerCamelCase__				,       lowerCamelCase__				,       atol=1e-3   )   )

					def 			snake_case__      (    self   ):
									import torch

									_lowerCamelCase        =				self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
									_lowerCamelCase        =				np.random.rand(1_0_0				,       3_2   ).astype(np.floataa   )
									_lowerCamelCase        =				np_speech_inputs.tolist()

									for inputs in [py_speech_inputs, np_speech_inputs]:
													_lowerCamelCase        =				feature_extractor.pad([{'''input_features''': inputs}]				,       return_tensors='''np'''   )
													self.assertTrue(np_processed.input_features.dtype == np.floataa   )
													_lowerCamelCase        =				feature_extractor.pad([{'''input_features''': inputs}]				,       return_tensors='''pt'''   )
													self.assertTrue(pt_processed.input_features.dtype == torch.floataa   )

					def 			snake_case__      (    self				,       lowerCamelCase__   ):
									_lowerCamelCase        =				load_dataset('''hf-internal-testing/librispeech_asr_dummy'''				,       '''clean'''				,       split='''validation'''   )
									# automatic decoding with librispeech
									_lowerCamelCase        =				ds.sort('''id'''   ).select(range(lowerCamelCase__   )   )[:num_samples]['''audio''']

									return [x["array"] for x in speech_samples]

					def 			snake_case__      (    self   ):
									# fmt: off
									_lowerCamelCase        =				torch.tensor(
									    [
									        0.1_1_9_3, -0.0_9_4_6, -0.1_0_9_8, -0.0_1_9_6, 0.0_2_2_5, -0.0_6_9_0, -0.1_7_3_6, 0.0_9_5_1,
									        0.0_9_7_1, -0.0_8_1_7, -0.0_7_0_2, 0.0_1_6_2, 0.0_2_6_0, 0.0_0_1_7, -0.0_1_9_2, -0.1_6_7_8,
									        0.0_7_0_9, -0.1_8_6_7, -0.0_6_5_5, -0.0_2_7_4, -0.0_2_3_4, -0.1_8_8_4, -0.0_5_1_6, -0.0_5_5_4,
									        -0.0_2_7_4, -0.1_4_2_5, -0.1_4_2_3, 0.0_8_3_7, 0.0_3_7_7, -0.0_8_5_4
									    ]   )
									# fmt: on

									_lowerCamelCase        =				self._load_datasamples(1   )
									_lowerCamelCase        =				WhisperFeatureExtractor()
									_lowerCamelCase        =				feature_extractor(lowerCamelCase__				,       return_tensors='''pt'''   ).input_features
									self.assertEqual(input_features.shape				,       (1, 8_0, 3_0_0_0)   )
									self.assertTrue(torch.allclose(input_features[0, 0, :3_0]				,       lowerCamelCase__				,       atol=1e-4   )   )





					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()   )
									_lowerCamelCase        =				self._load_datasamples(1   )[0]
									_lowerCamelCase        =				((audio - audio.min()) / (audio.max() - audio.min())) * 6_5_5_3_5  # Rescale to [0, 65535] to show issue
									_lowerCamelCase        =				feat_extract.zero_mean_unit_var_norm([audio]				,       attention_mask=lowerCamelCase__   )[0]

									self.assertTrue(np.all(np.mean(lowerCamelCase__   ) < 1e-3   )   )
									self.assertTrue(np.all(np.abs(np.var(lowerCamelCase__   ) - 1   ) < 1e-3   )   )
