




'''simple docstring'''
from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers import (
							    TF_MODEL_FOR_PRETRAINING_MAPPING,
							    TFMobileBertForMaskedLM,
							    TFMobileBertForMultipleChoice,
							    TFMobileBertForNextSentencePrediction,
							    TFMobileBertForPreTraining,
							    TFMobileBertForQuestionAnswering,
							    TFMobileBertForSequenceClassification,
							    TFMobileBertForTokenClassification,
							    TFMobileBertModel,
							)
@require_tf
class   __UpperCAmelCase				(     lowerCAmelCase			,lowerCAmelCase			,unittest.TestCase				):



					'''simple docstring'''





					_UpperCamelCase							=		(
					    (
					        TFMobileBertModel,
					        TFMobileBertForMaskedLM,
					        TFMobileBertForNextSentencePrediction,
					        TFMobileBertForPreTraining,
					        TFMobileBertForQuestionAnswering,
					        TFMobileBertForSequenceClassification,
					        TFMobileBertForTokenClassification,
					        TFMobileBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					_UpperCamelCase							=		(
					    {
					        """feature-extraction""": TFMobileBertModel,
					        """fill-mask""": TFMobileBertForMaskedLM,
					        """question-answering""": TFMobileBertForQuestionAnswering,
					        """text-classification""": TFMobileBertForSequenceClassification,
					        """token-classification""": TFMobileBertForTokenClassification,
					        """zero-shot""": TFMobileBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_UpperCamelCase							=		False
					_UpperCamelCase							=		False



					def     __snake_case						(	self     :						str      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						List[str]      ,       _lowercase     :						int=False)    ->							List[str]:
								A_									= super()._prepare_for_class(_lowercase      ,       _lowercase      ,       return_labels=_lowercase)

								if return_labels:
											if model_class in get_values(_lowercase):
														A_									= tf.zeros(self.model_tester.batch_size      ,       dtype=tf.intaa)

								return inputs_dict
					class   __UpperCAmelCase				(     lowerCAmelCase				):



										'''simple docstring'''





										def __init__(	self     :						str      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						Any=13      ,       _lowercase     :						Union[str, Any]=7      ,       _lowercase     :						List[Any]=True      ,       _lowercase     :						Optional[int]=True      ,       _lowercase     :						Union[str, Any]=True      ,       _lowercase     :						int=True      ,       _lowercase     :						Optional[int]=99      ,       _lowercase     :						Optional[Any]=32      ,       _lowercase     :						int=32      ,       _lowercase     :						Optional[Any]=2      ,       _lowercase     :						Optional[Any]=4      ,       _lowercase     :						List[Any]=37      ,       _lowercase     :						List[str]="gelu"      ,       _lowercase     :						List[Any]=0.1      ,       _lowercase     :						Dict=0.1      ,       _lowercase     :						int=512      ,       _lowercase     :						Dict=16      ,       _lowercase     :						Dict=2      ,       _lowercase     :						Optional[Any]=0.02      ,       _lowercase     :						Dict=3      ,       _lowercase     :						Dict=4      ,       _lowercase     :						str=None      ,       )    ->							int:
													A_									= parent
													A_									= batch_size
													A_									= seq_length
													A_									= is_training
													A_									= use_input_mask
													A_									= use_token_type_ids
													A_									= use_labels
													A_									= vocab_size
													A_									= hidden_size
													A_									= num_hidden_layers
													A_									= num_attention_heads
													A_									= intermediate_size
													A_									= hidden_act
													A_									= hidden_dropout_prob
													A_									= attention_probs_dropout_prob
													A_									= max_position_embeddings
													A_									= type_vocab_size
													A_									= type_sequence_label_size
													A_									= initializer_range
													A_									= num_labels
													A_									= num_choices
													A_									= scope
													A_									= embedding_size



										def     __snake_case						(	self     :						Optional[Any])    ->							str:
													A_									= ids_tensor([self.batch_size, self.seq_length]      ,       self.vocab_size)

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

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

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

													A_									= MobileBertConfig(
													    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      ,       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      ,       initializer_range=self.initializer_range      ,       embedding_size=self.embedding_size      ,       )

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



										def     __snake_case						(	self     :						Union[str, Any]      ,       _lowercase     :						Optional[Any]      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						Tuple      ,       _lowercase     :						int      ,       _lowercase     :						Tuple      ,       _lowercase     :						Optional[Any]      ,       _lowercase     :						Optional[Any])    ->							Union[str, Any]:
													A_									= TFMobileBertModel(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)

													A_									= [input_ids, input_mask]
													A_									= model(_lowercase)

													A_									= model(_lowercase)

													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     __snake_case						(	self     :						Optional[Any]      ,       _lowercase     :						Any      ,       _lowercase     :						Any      ,       _lowercase     :						Any      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Tuple      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						Optional[int])    ->							Optional[Any]:
													A_									= TFMobileBertForMaskedLM(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.vocab_size))



										def     __snake_case						(	self     :						int      ,       _lowercase     :						str      ,       _lowercase     :						Dict      ,       _lowercase     :						Tuple      ,       _lowercase     :						List[str]      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						List[Any])    ->							List[Any]:
													A_									= TFMobileBertForNextSentencePrediction(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, 2))



										def     __snake_case						(	self     :						Tuple      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						Dict      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						Any      ,       _lowercase     :						int      ,       _lowercase     :						Optional[Any]      ,       _lowercase     :						Union[str, Any])    ->							Dict:
													A_									= TFMobileBertForPreTraining(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													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     __snake_case						(	self     :						Optional[int]      ,       _lowercase     :						Optional[Any]      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Optional[Any]      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						Dict      ,       _lowercase     :						str      ,       _lowercase     :						Union[str, Any])    ->							Tuple:
													A_									= self.num_labels
													A_									= TFMobileBertForSequenceClassification(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_labels))



										def     __snake_case						(	self     :						List[str]      ,       _lowercase     :						Tuple      ,       _lowercase     :						Tuple      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Tuple      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						str)    ->							Dict:
													A_									= self.num_choices
													A_									= TFMobileBertForMultipleChoice(config=_lowercase)
													A_									= tf.tile(tf.expand_dims(_lowercase      ,       1)      ,       (1, self.num_choices, 1))
													A_									= tf.tile(tf.expand_dims(_lowercase      ,       1)      ,       (1, self.num_choices, 1))
													A_									= tf.tile(tf.expand_dims(_lowercase      ,       1)      ,       (1, self.num_choices, 1))
													A_									= {
													    'input_ids': multiple_choice_inputs_ids,
													    'attention_mask': multiple_choice_input_mask,
													    'token_type_ids': multiple_choice_token_type_ids,
													}
													A_									= model(_lowercase)
													self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_choices))



										def     __snake_case						(	self     :						Tuple      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						Any      ,       _lowercase     :						List[Any]      ,       _lowercase     :						int      ,       _lowercase     :						int      ,       _lowercase     :						List[Any]      ,       _lowercase     :						int)    ->							Tuple:
													A_									= self.num_labels
													A_									= TFMobileBertForTokenClassification(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.num_labels))



										def     __snake_case						(	self     :						Optional[Any]      ,       _lowercase     :						int      ,       _lowercase     :						str      ,       _lowercase     :						Tuple      ,       _lowercase     :						str      ,       _lowercase     :						Dict      ,       _lowercase     :						Dict      ,       _lowercase     :						Optional[Any])    ->							Union[str, Any]:
													A_									= TFMobileBertForQuestionAnswering(config=_lowercase)
													A_									= {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
													A_									= model(_lowercase)
													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     __snake_case						(	self     :						int)    ->							List[str]:
													A_									= self.prepare_config_and_inputs()
													(
													    (
													    A_
													)		, (
													    A_
													)		, (
													    A_
													)		, (
													    A_
													)		, (
													    A_
													)		, (
													    A_
													)		, (
													    A_
													)		, 
													)									= config_and_inputs
													A_									= {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
													return config, inputs_dict





					def     __snake_case						(	self     :						List[Any])    ->							Dict:
								A_									= TFMobileBertModelTest.TFMobileBertModelTester(self)
								A_									= ConfigTester(self      ,       config_class=_lowercase      ,       hidden_size=37)



					def     __snake_case						(	self     :						Tuple)    ->							Optional[int]:
								self.config_tester.run_common_tests()



					def     __snake_case						(	self     :						Any)    ->							Optional[int]:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_model(*_lowercase)



					def     __snake_case						(	self     :						str)    ->							Optional[Any]:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_masked_lm(*_lowercase)



					def     __snake_case						(	self     :						Union[str, Any])    ->							Any:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_lowercase)



					def     __snake_case						(	self     :						Dict)    ->							Dict:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_lowercase)



					def     __snake_case						(	self     :						Optional[int])    ->							Tuple:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_pretraining(*_lowercase)



					def     __snake_case						(	self     :						List[Any])    ->							int:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_question_answering(*_lowercase)



					def     __snake_case						(	self     :						List[str])    ->							int:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_lowercase)



					def     __snake_case						(	self     :						Optional[int])    ->							Dict:
								A_									= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_mobilebert_for_token_classification(*_lowercase)



					@slow
					def     __snake_case						(	self     :						int)    ->							List[Any]:
								# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								for model_name in ["google/mobilebert-uncased"]:
											A_									= TFMobileBertModel.from_pretrained(_lowercase)
											self.assertIsNotNone(_lowercase)





@require_tf
class   __UpperCAmelCase				(     unittest.TestCase				):



					'''simple docstring'''





					@slow
					def     __snake_case						(	self     :						str)    ->							Tuple:
								A_									= TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased')
								A_									= tf.constant([[0, 1, 2, 3, 4, 5]])
								A_									= model(_lowercase)[0]

								A_									= [1, 6, 30_522]
								self.assertEqual(output.shape      ,       _lowercase)

								A_									= tf.constant(
								    [
								        [
								            [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
								            [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
								            [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
								        ]
								    ])
								tf.debugging.assert_near(output[:, :3, :3]      ,       _lowercase      ,       atol=1E-4)










'''simple docstring'''
import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length





def 			lowerCamelCase(							SCREAMING_SNAKE_CASE_     )		->		str:
			A_									= int(SCREAMING_SNAKE_CASE_     )
			A_		, A_		, A_									= t // 3600, (t // 60) % 60, t % 60
			return F'{h}:{m:02d}:{s:02d}' if h != 0 else F'{m:02d}:{s:02d}'





def 			lowerCamelCase(							SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_=300     )		->		Dict:
			# docstyle-ignore
			return F'\n    <div>\n      {prefix}\n      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>\n      {label}\n    </div>\n    '





def 			lowerCamelCase(							SCREAMING_SNAKE_CASE_     )		->		List[str]:
			A_									= '<table border="1" class="dataframe">\n'
			html_code += """  <thead>\n <tr style="text-align: left;">\n"""
			for i in items[0]:
						html_code += F'      <th>{i}</th>\n'
			html_code += "    </tr>\n  </thead>\n  <tbody>\n"
			for line in items[1:]:
						html_code += "    <tr>\n"
						for elt in line:
									A_									= F'{elt:.6f}' if isinstance(SCREAMING_SNAKE_CASE_       ,SCREAMING_SNAKE_CASE_     ) else str(SCREAMING_SNAKE_CASE_     )
									html_code += F'      <td>{elt}</td>\n'
						html_code += "    </tr>\n"
			html_code += "  </tbody>\n</table><p>"
			return html_code
class   __UpperCAmelCase				:



					'''simple docstring'''





					_UpperCamelCase							=		5
					_UpperCamelCase							=		0.2



					def __init__(	self     :						Tuple      ,       _lowercase     :						int      ,       _lowercase     :						Optional[str] = None      ,       _lowercase     :						bool = True      ,       _lowercase     :						Optional["NotebookTrainingTracker"] = None      ,       _lowercase     :						int = 300      ,       )    ->							Dict:
								A_									= total
								A_									= '' if prefix is None else prefix
								A_									= leave
								A_									= parent
								A_									= width
								A_									= None
								A_									= None
								A_									= None



					def     __snake_case						(	self     :						Optional[int]      ,       _lowercase     :						int      ,       _lowercase     :						bool = False      ,       _lowercase     :						str = None)    ->							Dict:
								A_									= value
								if comment is not None:
											A_									= comment
								if self.last_value is None:
											A_									= A_									= time.time()
											A_									= A_									= value
											A_									= A_									= None
											A_									= self.warmup
											A_									= 1
											self.update_bar(_lowercase)
								elif value <= self.last_value and not force_update:
											return
								elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for      ,       self.total):
											if self.first_calls > 0:
														self.first_calls -= 1
											A_									= time.time()
											A_									= current_time - self.start_time
											# We could have value = self.start_value if the update is called twixe with the same start value.
											if value > self.start_value:
														A_									= self.elapsed_time / (value - self.start_value)
											else:
														A_									= None
											if value >= self.total:
														A_									= self.total
														A_									= None
														if not self.leave:
																	self.close()
											elif self.average_time_per_item is not None:
														A_									= self.average_time_per_item * (self.total - value)
											self.update_bar(_lowercase)
											A_									= value
											A_									= current_time
											if self.average_time_per_item is None:
														A_									= 1
											else:
														A_									= max(int(self.update_every / self.average_time_per_item)      ,       1)



					def     __snake_case						(	self     :						str      ,       _lowercase     :						List[Any]      ,       _lowercase     :						Optional[int]=None)    ->							str:
								A_									= ' ' * (len(str(self.total)) - len(str(_lowercase))) + str(_lowercase)
								if self.elapsed_time is None:
											A_									= F'[{spaced_value}/{self.total} : < :'
								elif self.predicted_remaining is None:
											A_									= F'[{spaced_value}/{self.total} {format_time(self.elapsed_time)}'
								else:
											A_									= (
											    F'[{spaced_value}/{self.total} {format_time(self.elapsed_time)} <'
											    F' {format_time(self.predicted_remaining)}'
											)
											self.label += F', {1/self.average_time_per_item:.2f} it/s'
								self.label += "]" if self.comment is None or len(self.comment) == 0 else F', {self.comment}]'
								self.display()



					def     __snake_case						(	self     :						Optional[int])    ->							Dict:
								A_									= html_progress_bar(self.value      ,       self.total      ,       self.prefix      ,       self.label      ,       self.width)
								if self.parent is not None:
											# If this is a child bar, the parent will take care of the display.
											self.parent.display()
											return
								if self.output is None:
											A_									= disp.display(disp.HTML(self.html_code)      ,       display_id=_lowercase)
								else:
											self.output.update(disp.HTML(self.html_code))



					def     __snake_case						(	self     :						List[Any])    ->							Optional[Any]:
								if self.parent is None and self.output is not None:
											self.output.update(disp.HTML(''))





class   __UpperCAmelCase				(     lowerCAmelCase				):



					'''simple docstring'''





					def __init__(	self     :						int      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						str=None)    ->							str:
								super().__init__(_lowercase)
								A_									= None if column_names is None else [column_names]
								A_									= None



					def     __snake_case						(	self     :						Dict)    ->							List[Any]:
								A_									= html_progress_bar(self.value      ,       self.total      ,       self.prefix      ,       self.label      ,       self.width)
								if self.inner_table is not None:
											self.html_code += text_to_html_table(self.inner_table)
								if self.child_bar is not None:
											self.html_code += self.child_bar.html_code
								if self.output is None:
											A_									= disp.display(disp.HTML(self.html_code)      ,       display_id=_lowercase)
								else:
											self.output.update(disp.HTML(self.html_code))



					def     __snake_case						(	self     :						str      ,       _lowercase     :						int)    ->							Optional[int]:
								if self.inner_table is None:
											A_									= [list(values.keys()), list(values.values())]
								else:
											A_									= self.inner_table[0]
											if len(self.inner_table) == 1:
														# We give a chance to update the column names at the first iteration
														for key in values.keys():
																	if key not in columns:
																				columns.append(_lowercase)
														A_									= columns
											self.inner_table.append([values[c] for c in columns])



					def     __snake_case						(	self     :						List[Any]      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						str=None      ,       _lowercase     :						Optional[int]=300)    ->							Dict:
								A_									= NotebookProgressBar(_lowercase      ,       prefix=_lowercase      ,       parent=self      ,       width=_lowercase)
								return self.child_bar



					def     __snake_case						(	self     :						Any)    ->							int:
								A_									= None
								self.display()





class   __UpperCAmelCase				(     lowerCAmelCase				):



					'''simple docstring'''





					def __init__(	self     :						Dict)    ->							Tuple:
								A_									= None
								A_									= None
								A_									= False



					def     __snake_case						(	self     :						int      ,       _lowercase     :						str      ,       _lowercase     :						str      ,       _lowercase     :						str      ,       **_lowercase     :						List[Any])    ->							List[Any]:
								A_									= 'Epoch' if args.evaluation_strategy == IntervalStrategy.EPOCH else 'Step'
								A_									= 0
								A_									= 0
								A_									= [self.first_column] + ['Training Loss']
								if args.evaluation_strategy != IntervalStrategy.NO:
											column_names.append('Validation Loss')
								A_									= NotebookTrainingTracker(state.max_steps      ,       _lowercase)



					def     __snake_case						(	self     :						Tuple      ,       _lowercase     :						Union[str, Any]      ,       _lowercase     :						List[Any]      ,       _lowercase     :						List[str]      ,       **_lowercase     :						Union[str, Any])    ->							str:
								A_									= int(state.epoch) if int(state.epoch) == state.epoch else F'{state.epoch:.2f}'
								self.training_tracker.update(
								    state.global_step + 1      ,       comment=F'Epoch {epoch}/{state.num_train_epochs}'      ,       force_update=self._force_next_update      ,       )
								A_									= False



					def     __snake_case						(	self     :						Union[str, Any]      ,       _lowercase     :						Any      ,       _lowercase     :						int      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						List[Any]=None      ,       **_lowercase     :						Any)    ->							Union[str, Any]:
								if not has_length(_lowercase):
											return
								if self.prediction_bar is None:
											if self.training_tracker is not None:
														A_									= self.training_tracker.add_child(len(_lowercase))
											else:
														A_									= NotebookProgressBar(len(_lowercase))
											self.prediction_bar.update(1)
								else:
											self.prediction_bar.update(self.prediction_bar.value + 1)



					def     __snake_case						(	self     :						List[Any]      ,       _lowercase     :						List[str]      ,       _lowercase     :						Any      ,       _lowercase     :						Union[str, Any]      ,       **_lowercase     :						Optional[int])    ->							Optional[Any]:
								if self.prediction_bar is not None:
											self.prediction_bar.close()
								A_									= None



					def     __snake_case						(	self     :						Dict      ,       _lowercase     :						Dict      ,       _lowercase     :						str      ,       _lowercase     :						str      ,       _lowercase     :						Optional[Any]=None      ,       **_lowercase     :						Dict)    ->							Optional[int]:
								# Only for when there is no evaluation
								if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
											A_									= {'Training Loss': logs['loss']}
											# First column is necessarily Step sine we're not in epoch eval strategy
											A_									= state.global_step
											self.training_tracker.write_line(_lowercase)



					def     __snake_case						(	self     :						List[Any]      ,       _lowercase     :						Any      ,       _lowercase     :						Optional[int]      ,       _lowercase     :						str      ,       _lowercase     :						Optional[Any]=None      ,       **_lowercase     :						Union[str, Any])    ->							Union[str, Any]:
								if self.training_tracker is not None:
											A_									= {'Training Loss': 'No log', 'Validation Loss': 'No log'}
											for log in reversed(state.log_history):
														if "loss" in log:
																	A_									= log['loss']
																	break

											if self.first_column == "Epoch":
														A_									= int(state.epoch)
											else:
														A_									= state.global_step
											A_									= 'eval'
											for k in metrics:
														if k.endswith('_loss'):
																	A_									= re.sub(r'\_loss$'      ,       ''      ,       _lowercase)
											A_									= metrics.pop('total_flos'      ,       _lowercase)
											A_									= metrics.pop('epoch'      ,       _lowercase)
											A_									= metrics.pop(F'{metric_key_prefix}_runtime'      ,       _lowercase)
											A_									= metrics.pop(F'{metric_key_prefix}_samples_per_second'      ,       _lowercase)
											A_									= metrics.pop(F'{metric_key_prefix}_steps_per_second'      ,       _lowercase)
											A_									= metrics.pop(F'{metric_key_prefix}_jit_compilation_time'      ,       _lowercase)
											for k, v in metrics.items():
														if k == F'{metric_key_prefix}_loss':
																	A_									= v
														else:
																	A_									= k.split('_')
																	A_									= ' '.join([part.capitalize() for part in splits[1:]])
																	A_									= v
											self.training_tracker.write_line(_lowercase)
											self.training_tracker.remove_child()
											A_									= None
											# Evaluation takes a long time so we should force the next update.
											A_									= True



					def     __snake_case						(	self     :						Tuple      ,       _lowercase     :						Dict      ,       _lowercase     :						str      ,       _lowercase     :						List[str]      ,       **_lowercase     :						str)    ->							Optional[int]:
								self.training_tracker.update(
								    state.global_step      ,       comment=F'Epoch {int(state.epoch)}/{state.num_train_epochs}'      ,       force_update=_lowercase)
								A_									= None




