




import math
import os
import unittest

from transformers import MegatronBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    MegatronBertForCausalLM,
					    MegatronBertForMaskedLM,
					    MegatronBertForMultipleChoice,
					    MegatronBertForNextSentencePrediction,
					    MegatronBertForPreTraining,
					    MegatronBertForQuestionAnswering,
					    MegatronBertForSequenceClassification,
					    MegatronBertForTokenClassification,
					    MegatronBertModel,
					)







class     __lowerCAmelCase :

			"""simple docstring"""







			def __init__(      self			,						lowerCamelCase__			,						lowerCamelCase__=13			,						lowerCamelCase__=7			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=True			,						lowerCamelCase__=99			,						lowerCamelCase__=64			,						lowerCamelCase__=32			,						lowerCamelCase__=5			,						lowerCamelCase__=4			,						lowerCamelCase__=37			,						lowerCamelCase__="gelu"			,						lowerCamelCase__=0.1			,						lowerCamelCase__=0.1			,						lowerCamelCase__=512			,						lowerCamelCase__=16			,						lowerCamelCase__=2			,						lowerCamelCase__=0.02			,						lowerCamelCase__=3			,						lowerCamelCase__=4			,						lowerCamelCase__=None			,						)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    parent
							__lowerCamelCase		       =    batch_size
							__lowerCamelCase		       =    seq_length
							__lowerCamelCase		       =    is_training
							__lowerCamelCase		       =    use_input_mask
							__lowerCamelCase		       =    use_token_type_ids
							__lowerCamelCase		       =    use_labels
							__lowerCamelCase		       =    vocab_size
							__lowerCamelCase		       =    hidden_size
							__lowerCamelCase		       =    embedding_size
							__lowerCamelCase		       =    num_hidden_layers
							__lowerCamelCase		       =    num_attention_heads
							__lowerCamelCase		       =    intermediate_size
							__lowerCamelCase		       =    hidden_act
							__lowerCamelCase		       =    hidden_dropout_prob
							__lowerCamelCase		       =    attention_probs_dropout_prob
							__lowerCamelCase		       =    max_position_embeddings
							__lowerCamelCase		       =    type_vocab_size
							__lowerCamelCase		       =    type_sequence_label_size
							__lowerCamelCase		       =    initializer_range
							__lowerCamelCase		       =    num_labels
							__lowerCamelCase		       =    num_choices
							__lowerCamelCase		       =    scope


			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size							)

							__lowerCamelCase		       =    None
							if self.use_input_mask:
											__lowerCamelCase		       =    random_attention_mask([self.batch_size, self.seq_length]							)

							__lowerCamelCase		       =    None
							if self.use_token_type_ids:
											__lowerCamelCase		       =    ids_tensor([self.batch_size, self.seq_length]			,						self.type_vocab_size							)

							__lowerCamelCase		       =    None
							__lowerCamelCase		       =    None
							__lowerCamelCase		       =    None
							if self.use_labels:
											__lowerCamelCase		       =    ids_tensor([self.batch_size]			,						self.type_sequence_label_size							)
											__lowerCamelCase		       =    ids_tensor([self.batch_size, self.seq_length]			,						self.num_labels							)
											__lowerCamelCase		       =    ids_tensor([self.batch_size]			,						self.num_choices							)

							__lowerCamelCase		       =    self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


			def       lowercase_    (      self							)    ->      Optional[int]:



							'''simple docstring'''
							return MegatronBertConfig(
							    vocab_size=self.vocab_size			,						hidden_size=self.hidden_size			,						num_hidden_layers=self.num_hidden_layers			,						num_attention_heads=self.num_attention_heads			,						intermediate_size=self.intermediate_size			,						embedding_size=self.embedding_size			,						hidden_act=self.hidden_act			,						hidden_dropout_prob=self.hidden_dropout_prob			,						attention_probs_dropout_prob=self.attention_probs_dropout_prob			,						max_position_embeddings=self.max_position_embeddings			,						type_vocab_size=self.type_vocab_size			,						is_decoder=lowerCamelCase__			,						initializer_range=self.initializer_range			,						)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      List[Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertModel(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__							)
							__lowerCamelCase		       =    model(lowerCamelCase__			,						token_type_ids=lowerCamelCase__							)
							__lowerCamelCase		       =    model(lowerCamelCase__							)

							self.parent.assertEqual(result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size)							)
							self.parent.assertEqual(result.pooler_output.shape			,						(self.batch_size, self.hidden_size)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertForMaskedLM(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Optional[Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertForCausalLM(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertForNextSentencePrediction(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(
							    lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__			,						)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, 2)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Optional[int]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertForPreTraining(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(
							    lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__			,						next_sentence_label=lowerCamelCase__			,						)
							self.parent.assertEqual(result.prediction_logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size)							)
							self.parent.assertEqual(result.seq_relationship_logits.shape			,						(self.batch_size, 2)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      Optional[int]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertForQuestionAnswering(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(
							    lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						start_positions=lowerCamelCase__			,						end_positions=lowerCamelCase__			,						)
							self.parent.assertEqual(result.start_logits.shape			,						(self.batch_size, self.seq_length)							)
							self.parent.assertEqual(result.end_logits.shape			,						(self.batch_size, self.seq_length)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    self.num_labels
							__lowerCamelCase		       =    MegatronBertForSequenceClassification(lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.num_labels)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    self.num_labels
							__lowerCamelCase		       =    MegatronBertForTokenClassification(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    model(lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__							)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.num_labels)							)


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)    ->      str:



							'''simple docstring'''
							__lowerCamelCase		       =    self.num_choices
							__lowerCamelCase		       =    MegatronBertForMultipleChoice(config=lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.eval()
							__lowerCamelCase		       =    input_ids.unsqueeze(1							).expand(-1			,						self.num_choices			,						-1							).contiguous()
							__lowerCamelCase		       =    token_type_ids.unsqueeze(1							).expand(-1			,						self.num_choices			,						-1							).contiguous()
							__lowerCamelCase		       =    input_mask.unsqueeze(1							).expand(-1			,						self.num_choices			,						-1							).contiguous()
							__lowerCamelCase		       =    model(
							    lowerCamelCase__			,						attention_mask=lowerCamelCase__			,						token_type_ids=lowerCamelCase__			,						labels=lowerCamelCase__			,						)
							self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.num_choices)							)






			def       lowercase_    (      self							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.prepare_config_and_inputs()
							(
							    (
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						(
							    __lowerCamelCase
							)       ,						
							)		       =    config_and_inputs
							__lowerCamelCase		       =    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_torch
class     __lowerCAmelCase (       __magic_name__			,				__magic_name__			,				unittest.TestCase ):

			"""simple docstring"""







			snake_case_   		=       (
			    (
			        MegatronBertModel,
			        MegatronBertForMaskedLM,
			        MegatronBertForCausalLM,
			        MegatronBertForMultipleChoice,
			        MegatronBertForNextSentencePrediction,
			        MegatronBertForPreTraining,
			        MegatronBertForQuestionAnswering,
			        MegatronBertForSequenceClassification,
			        MegatronBertForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			snake_case_   		=       (
			    {
			        '''feature-extraction''': MegatronBertModel,
			        '''fill-mask''': MegatronBertForMaskedLM,
			        '''question-answering''': MegatronBertForQuestionAnswering,
			        '''text-classification''': MegatronBertForSequenceClassification,
			        '''text-generation''': MegatronBertForCausalLM,
			        '''token-classification''': MegatronBertForTokenClassification,
			        '''zero-shot''': MegatronBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			snake_case_   		=       True
			# test_resize_embeddings = False
			snake_case_   		=       False


			def       lowercase_    (      self			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__=False							)    ->      Dict:



							'''simple docstring'''
							__lowerCamelCase		       =    super()._prepare_for_class(lowerCamelCase__			,						lowerCamelCase__			,						return_labels=lowerCamelCase__							)

							if return_labels:
											if model_class in get_values(lowerCamelCase__							):
															__lowerCamelCase		       =    torch.zeros(
															    (self.model_tester.batch_size, self.model_tester.seq_length)			,						dtype=torch.long			,						device=lowerCamelCase__							)
															__lowerCamelCase		       =    torch.zeros(
															    self.model_tester.batch_size			,						dtype=torch.long			,						device=lowerCamelCase__							)
							return inputs_dict


			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    MegatronBertModelTester(self							)
							__lowerCamelCase		       =    ConfigTester(self			,						config_class=lowerCamelCase__			,						hidden_size=37							)


			def       lowercase_    (      self							)    ->      Dict:



							'''simple docstring'''
							self.config_tester.run_common_tests()


			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_model(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      Tuple:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_masked_lm(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_multiple_choice(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      int:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_next_sequence_prediction(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      Union[str, Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_pretraining(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      List[Any]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_question_answering(*lowerCamelCase__							)


			def       lowercase_    (      self							)    ->      List[str]:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_sequence_classification(*lowerCamelCase__							)






			def       lowercase_    (      self							)    ->      Dict:



							'''simple docstring'''
							__lowerCamelCase		       =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_megatron_bert_for_token_classification(*lowerCamelCase__							)







def 			lowerCamelCase_		(       UpperCamelCase__				:      int      )     ->       List[str]:





				"""simple docstring"""


				return torch.tensor(
				    UpperCamelCase__ ,     dtype=torch.long ,     device=UpperCamelCase__ ,     )


__A        =    1e-4







@require_torch
@require_sentencepiece
@require_tokenizers
class     __lowerCAmelCase (       unittest.TestCase ):

			"""simple docstring"""







			@slow
			@unittest.skip('Model is not available.'							)
			def       lowercase_    (      self							)    ->      Any:



							'''simple docstring'''
							__lowerCamelCase		       =    'nvidia/megatron-bert-uncased-345m'
							if "MYDIR" in os.environ:
											__lowerCamelCase		       =    os.path.join(os.environ['MYDIR']			,						lowerCamelCase__							)
							__lowerCamelCase		       =    MegatronBertModel.from_pretrained(lowerCamelCase__							)
							model.to(lowerCamelCase__							)
							model.half()
							__lowerCamelCase		       =    _long_tensor([[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]							)
							with torch.no_grad():
											__lowerCamelCase		       =    model(lowerCamelCase__							)[0]
							__lowerCamelCase		       =    torch.Size((1, 9, 1_024)							)
							self.assertEqual(output.shape			,						lowerCamelCase__							)

							__lowerCamelCase		       =    [-0.60_40, -0.25_17, -0.10_25, 0.34_20, -0.67_58, -0.00_17, -0.10_89, -0.19_90, 0.57_28]
							for ii in range(3							):
											for jj in range(3							):
															__lowerCamelCase		       =    output[0, ii, jj]
															__lowerCamelCase		       =    expected[3 * ii + jj]
															__lowerCamelCase		       =    'ii={} jj={} a={} b={}'.format(lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__			,						lowerCamelCase__							)
															self.assertTrue(math.isclose(lowerCamelCase__			,						lowerCamelCase__			,						rel_tol=lowerCamelCase__			,						abs_tol=lowerCamelCase__							)			,						msg=lowerCamelCase__							)




# XXX: we want transformers master here - in the absense of conftest manipulating sys.path:
# hack it in for now:
import sys
from pathlib import Path


lowercase  :					Optional[int]													=       Path(__file__).resolve().parents[3] / 'src'
sys.path.insert(1, str(git_repo_path))

import dataclasses  # noqa
import io  # noqa
import itertools  # noqa
import json  # noqa
import os  # noqa
import unittest  # noqa
from copy import deepcopy  # noqa

from parameterized import parameterized  # noqa
from transformers import TrainingArguments, is_torch_available  # noqa
from transformers.deepspeed import is_deepspeed_available  # noqa
from transformers.file_utils import WEIGHTS_NAME  # noqa
from transformers.testing_utils import (  # noqa
    CaptureLogger,
    ExtendSysPath,
    TestCasePlus,
    execute_subprocess_async,
    get_gpu_count,
    mockenv_context,
    require_deepspeed,
    require_torch_gpu,
    require_torch_multi_gpu,
    slow,
)
from transformers.trainer_utils import set_seed  # noqa


set_seed(42)

lowercase  :					Optional[Any]													=       {'base': 'patrickvonplaten/wav2vec2_tiny_random', 'robust': 'patrickvonplaten/wav2vec2_tiny_random_robust'}

lowercase  :					str													=       'zero2'
lowercase  :					Optional[int]													=       'zero3'
lowercase  :					Optional[Any]													=       [ZEROa, ZEROa]




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			str						,  _lowerCamelCase :			Union[str, Any]						,  _lowerCamelCase :			List[str])					->    int:






							'''simple docstring'''





							__UpperCamelCase	:   Union[str, Any]			   =					parameterized.to_safe_name("_".join(str(_lowerCamelCase) for x in param.args))
							return F'{func.__name__}_{param_based_name}'


# Cartesian-product of zero stages with models to test
lowercase  :					List[str]													=       list(itertools.product(stages, models.keys()))




@slow
@require_deepspeed
@require_torch_gpu
class  lowerCamelCase__							(				__lowercase):




	'''simple docstring'''




	@parameterized.expand(a     ,   name_func=a						)
	def    _lowerCamelCase				(					self		:Dict     ,   a		:Optional[Any]     ,   a		:str						)		-> Optional[int]:
								self.run_and_check(
								    stage=a     ,   model=a     ,   distributed=a     ,   fpaa=a     ,   )







	@require_torch_multi_gpu
	@parameterized.expand(a     ,   name_func=a						)
	def    _lowerCamelCase				(					self		:List[str]     ,   a		:str     ,   a		:str						)		-> List[Any]:
								self.run_and_check(
								    stage=a     ,   model=a     ,   distributed=a     ,   fpaa=a     ,   )







	@parameterized.expand(a     ,   name_func=a						)
	def    _lowerCamelCase				(					self		:List[Any]     ,   a		:List[str]     ,   a		:int						)		-> Optional[int]:
								self.run_and_check(
								    stage=a     ,   model=a     ,   distributed=a     ,   fpaa=a     ,   )







	@require_torch_multi_gpu
	@parameterized.expand(a     ,   name_func=a						)
	def    _lowerCamelCase				(					self		:List[str]     ,   a		:List[Any]     ,   a		:Dict						)		-> int:
								self.run_and_check(
								    stage=a     ,   model=a     ,   distributed=a     ,   fpaa=a     ,   )







	def    _lowerCamelCase				(					self		:Any     ,   a		:List[str]						)		-> Optional[Any]:
								# XXX: run_asr is premature and doesn't save any results
								# so all we check for now is that the process didn't fail
								pass







	def    _lowerCamelCase				(					self		:Optional[Any]     ,   a		:str     ,   a		:str     ,   a		:int = 1_0     ,   a		:bool = True     ,   a		:bool = True     ,   a		:bool = True     ,   )		-> Any:
								__UpperCamelCase	:   Optional[Any]			   =					models[model]

								__UpperCamelCase	:   List[Any]			   =					self.run_trainer(
								    stage=a     ,   model_name=a     ,   eval_steps=a     ,   num_train_epochs=1     ,   distributed=a     ,   fpaa=a     ,   )

								self.do_checks(a						)

								return output_dir







	def    _lowerCamelCase				(					self		:List[str]     ,   a		:str     ,   a		:str     ,   a		:int = 1_0     ,   a		:int = 1     ,   a		:bool = True     ,   a		:bool = True     ,   )		-> Dict:
								__UpperCamelCase	:   int			   =					self.get_auto_remove_tmp_dir("./xxx"     ,   after=a						)
								__UpperCamelCase	:   int			   =					f'\n            --model_name_or_path {model_name}\n            --dataset_name hf-internal-testing/librispeech_asr_dummy\n            --dataset_config_name clean\n            --train_split_name validation\n            --validation_split_name validation\n            --output_dir {output_dir}\n            --num_train_epochs {str(a						)}\n            --per_device_train_batch_size 2\n            --per_device_eval_batch_size 2\n            --evaluation_strategy steps\n            --learning_rate 5e-4\n            --warmup_steps 8\n            --orthography timit\n            --preprocessing_num_workers 1\n            --group_by_length\n            --freeze_feature_extractor\n            --report_to none\n            --save_steps 0\n            --eval_steps {eval_steps}\n            --report_to none\n        '.split()

								if fpaa:
															args.extend(["--fp16"]						)

								# currently ds_config_wav2vec2_zero.json requires "zero_optimization.find_unused_parameters": true,
								# hence the separate config files
								__UpperCamelCase	:   Dict			   =					f'--deepspeed {self.test_file_dir_str}/ds_config_wav2vec2_{stage}.json'.split()
								__UpperCamelCase	:   int			   =					[f'{self.examples_dir_str}/research_projects/wav2vec2/run_asr.py']
								__UpperCamelCase	:   Optional[Any]			   =					self.get_launcher(a						)

								__UpperCamelCase	:   Optional[int]			   =					launcher + script + args + ds_args
								# keep for quick debug
								# print(" ".join([f"\nPYTHONPATH={self.src_dir_str}"] +cmd)); die
								execute_subprocess_async(a     ,   env=self.get_env()						)

								return output_dir







	def    _lowerCamelCase				(					self		:Any     ,   a		:List[Any]=False						)		-> List[Any]:
								# 1. explicitly set --num_nodes=1 just in case these tests end up run on a multi-node setup
								# - it won't be able to handle that
								# 2. for now testing with just 2 gpus max (since some quality tests may give different
								# results with mode gpus because we use very little data)
								__UpperCamelCase	:   List[Any]			   =					min(2     ,   get_gpu_count()						) if distributed else 1
								return f'deepspeed --num_nodes 1 --num_gpus {num_gpus}'.split()