





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_ (							A_):
    UpperCamelCase__:	Dict					=     int(_lowerCAmelCase)
    UpperCamelCase__:	Any					=     t // 36_00, (t // 60) % 60, t % 60
    return F"{h}:{m:02d}:{s:02d}" if h != 0 else F"{m:02d}:{s:02d}"



def 				lowerCAmelCase_ (							A_    ,A_    ,A_    ,A_    ,A_=3_00):
    # 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_ (							A_):
    UpperCamelCase__:	Optional[int]					=     '<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:
            UpperCamelCase__:	str					=     F"{elt:.6f}" if isinstance(_lowerCAmelCase    ,_lowerCAmelCase) else str(_lowerCAmelCase)
            html_code += F"      <td>{elt}</td>\n"
        html_code += "    </tr>\n"
    html_code += "  </tbody>\n</table><p>"
    return html_code




class        _a    :

      """simple docstring"""


      UpperCamelCase__  		=       5
      UpperCamelCase__  		=       0.2






      def __init__(		self:			Union[str, Any]	,    __lowerCamelCase:			int	,    __lowerCamelCase:			Optional[str] = None	,    __lowerCamelCase:			bool = True	,    __lowerCamelCase:			Optional["NotebookTrainingTracker"] = None	,    __lowerCamelCase:			int = 300	,    ):
          '''simple docstring'''


          UpperCamelCase__:	Tuple					=     total
          UpperCamelCase__:	Optional[int]					=     '' if prefix is None else prefix
          UpperCamelCase__:	List[Any]					=     leave
          UpperCamelCase__:	Optional[int]					=     parent
          UpperCamelCase__:	Optional[Any]					=     width
          UpperCamelCase__:	Tuple					=     None
          UpperCamelCase__:	Optional[int]					=     None
          UpperCamelCase__:	Dict					=     None






      def 			UpperCAmelCase_       (		self:			int	,    __lowerCamelCase:			int	,    __lowerCamelCase:			bool = False	,    __lowerCamelCase:			str = None					):
          '''simple docstring'''


          UpperCamelCase__:	List[Any]					=     value
          if comment is not None:
              UpperCamelCase__:	List[str]					=     comment
          if self.last_value is None:
              UpperCamelCase__:	Union[str, Any]					=     time.time()
              UpperCamelCase__:	Optional[Any]					=     value
              UpperCamelCase__:	List[str]					=     None
              UpperCamelCase__:	str					=     self.warmup
              UpperCamelCase__:	Optional[int]					=     1
              self.update_bar(_a					)
          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
              UpperCamelCase__:	Union[str, Any]					=     time.time()
              UpperCamelCase__:	str					=     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:
                  UpperCamelCase__:	Optional[int]					=     self.elapsed_time / (value - self.start_value)
              else:
                  UpperCamelCase__:	List[Any]					=     None
              if value >= self.total:
                  UpperCamelCase__:	Tuple					=     self.total
                  UpperCamelCase__:	Any					=     None
                  if not self.leave:
                      self.close()
              elif self.average_time_per_item is not None:
                  UpperCamelCase__:	Optional[Any]					=     self.average_time_per_item * (self.total - value)
              self.update_bar(_a					)
              UpperCamelCase__:	Tuple					=     value
              UpperCamelCase__:	Dict					=     current_time
              if self.average_time_per_item is None:
                  UpperCamelCase__:	Dict					=     1
              else:
                  UpperCamelCase__:	Tuple					=     max(int(self.update_every / self.average_time_per_item					)	,    1					)






      def 			UpperCAmelCase_       (		self:			Optional[Any]	,    __lowerCamelCase:			List[str]	,    __lowerCamelCase:			Tuple=None					):
          '''simple docstring'''


          UpperCamelCase__:	List[Any]					=     ' ' * (len(str(self.total					)					) - len(str(_a					)					)) + str(_a					)
          if self.elapsed_time is None:
              UpperCamelCase__:	Tuple					=     F"[{spaced_value}/{self.total} : < :"
          elif self.predicted_remaining is None:
              UpperCamelCase__:	int					=     F"[{spaced_value}/{self.total} {format_time(self.elapsed_time					)}"
          else:
              UpperCamelCase__:	Dict					=     (
                  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 			UpperCAmelCase_       (		self:			List[str]					):
          '''simple docstring'''


          UpperCamelCase__:	Tuple					=     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:
              UpperCamelCase__:	Optional[int]					=     disp.display(disp.HTML(self.html_code					)	,    display_id=_a					)
          else:
              self.output.update(disp.HTML(self.html_code					)					)






      def 			UpperCAmelCase_       (		self:			str					):
          '''simple docstring'''


          if self.parent is None and self.output is not None:
              self.output.update(disp.HTML(""					)					)




class        _a    (    SCREAMING_SNAKE_CASE_):

      """simple docstring"""


      def __init__(		self:			Optional[int]	,    __lowerCamelCase:			Optional[Any]	,    __lowerCamelCase:			str=None					):
          '''simple docstring'''


          super().__init__(_a					)
          UpperCamelCase__:	str					=     None if column_names is None else [column_names]
          UpperCamelCase__:	str					=     None






      def 			UpperCAmelCase_       (		self:			List[str]					):
          '''simple docstring'''


          UpperCamelCase__:	str					=     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:
              UpperCamelCase__:	Dict					=     disp.display(disp.HTML(self.html_code					)	,    display_id=_a					)
          else:
              self.output.update(disp.HTML(self.html_code					)					)






      def 			UpperCAmelCase_       (		self:			Tuple	,    __lowerCamelCase:			Union[str, Any]					):
          '''simple docstring'''


          if self.inner_table is None:
              UpperCamelCase__:	List[Any]					=     [list(values.keys()					), list(values.values()					)]
          else:
              UpperCamelCase__:	str					=     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(_a					)
                  UpperCamelCase__:	Dict					=     columns
              self.inner_table.append([values[c] for c in columns]					)






      def 			UpperCAmelCase_       (		self:			int	,    __lowerCamelCase:			Union[str, Any]	,    __lowerCamelCase:			Union[str, Any]=None	,    __lowerCamelCase:			Union[str, Any]=300					):
          '''simple docstring'''


          UpperCamelCase__:	int					=     NotebookProgressBar(_a	,    prefix=_a	,    parent=self	,    width=_a					)
          return self.child_bar






      def 			UpperCAmelCase_       (		self:			List[Any]					):
          '''simple docstring'''


          UpperCamelCase__:	Union[str, Any]					=     None
          self.display()




class        _a    (    SCREAMING_SNAKE_CASE_):

      """simple docstring"""


      def __init__(		self:			Any					):
          '''simple docstring'''


          UpperCamelCase__:	Union[str, Any]					=     None
          UpperCamelCase__:	List[str]					=     None
          UpperCamelCase__:	Dict					=     False






      def 			UpperCAmelCase_       (		self:			Tuple	,    __lowerCamelCase:			int	,    __lowerCamelCase:			Union[str, Any]	,    __lowerCamelCase:			Union[str, Any]	,    **__lowerCamelCase:			Optional[int]					):
          '''simple docstring'''


          UpperCamelCase__:	List[Any]					=     'Epoch' if args.evaluation_strategy == IntervalStrategy.EPOCH else 'Step'
          UpperCamelCase__:	Union[str, Any]					=     0
          UpperCamelCase__:	Optional[int]					=     0
          UpperCamelCase__:	Optional[Any]					=     [self.first_column] + ['Training Loss']
          if args.evaluation_strategy != IntervalStrategy.NO:
              column_names.append("Validation Loss"					)
          UpperCamelCase__:	List[str]					=     NotebookTrainingTracker(state.max_steps	,    _a					)






      def 			UpperCAmelCase_       (		self:			Optional[int]	,    __lowerCamelCase:			List[str]	,    __lowerCamelCase:			Dict	,    __lowerCamelCase:			Any	,    **__lowerCamelCase:			Optional[int]					):
          '''simple docstring'''


          UpperCamelCase__:	Union[str, Any]					=     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	,    )
          UpperCamelCase__:	Optional[int]					=     False






      def 			UpperCAmelCase_       (		self:			Optional[int]	,    __lowerCamelCase:			Any	,    __lowerCamelCase:			Optional[int]	,    __lowerCamelCase:			List[Any]	,    __lowerCamelCase:			List[Any]=None	,    **__lowerCamelCase:			Any					):
          '''simple docstring'''


          if not has_length(_a					):
              return
          if self.prediction_bar is None:
              if self.training_tracker is not None:
                  UpperCamelCase__:	List[Any]					=     self.training_tracker.add_child(len(_a					)					)
              else:
                  UpperCamelCase__:	Union[str, Any]					=     NotebookProgressBar(len(_a					)					)
              self.prediction_bar.update(1					)
          else:
              self.prediction_bar.update(self.prediction_bar.value + 1					)






      def 			UpperCAmelCase_       (		self:			Optional[Any]	,    __lowerCamelCase:			str	,    __lowerCamelCase:			Dict	,    __lowerCamelCase:			Dict	,    **__lowerCamelCase:			List[str]					):
          '''simple docstring'''


          if self.prediction_bar is not None:
              self.prediction_bar.close()
          UpperCamelCase__:	Any					=     None






      def 			UpperCAmelCase_       (		self:			Dict	,    __lowerCamelCase:			str	,    __lowerCamelCase:			List[str]	,    __lowerCamelCase:			Optional[Any]	,    __lowerCamelCase:			str=None	,    **__lowerCamelCase:			str					):
          '''simple docstring'''


          if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
              UpperCamelCase__:	Union[str, Any]					=     {'Training Loss': logs['loss']}
              # First column is necessarily Step sine we're not in epoch eval strategy
              UpperCamelCase__:	Union[str, Any]					=     state.global_step
              self.training_tracker.write_line(_a					)






      def 			UpperCAmelCase_       (		self:			int	,    __lowerCamelCase:			int	,    __lowerCamelCase:			List[Any]	,    __lowerCamelCase:			List[str]	,    __lowerCamelCase:			Dict=None	,    **__lowerCamelCase:			List[Any]					):
          '''simple docstring'''


          if self.training_tracker is not None:
              UpperCamelCase__:	Optional[Any]					=     {'Training Loss': 'No log', 'Validation Loss': 'No log'}
              for log in reversed(state.log_history					):
                  if "loss" in log:
                      UpperCamelCase__:	Optional[int]					=     log['loss']
                      break

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






      def 			UpperCAmelCase_       (		self:			int	,    __lowerCamelCase:			Tuple	,    __lowerCamelCase:			Union[str, Any]	,    __lowerCamelCase:			str	,    **__lowerCamelCase:			Tuple					):
          '''simple docstring'''


          self.training_tracker.update(
              state.global_step	,    comment=F"Epoch {int(state.epoch					)}/{state.num_train_epochs}"	,    force_update=_a					)
          UpperCamelCase__:	Tuple					=     None






'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCamelCase											=		{'configuration_ibert': ['IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'IBertConfig', 'IBertOnnxConfig']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _UpperCamelCase											=		[
       'IBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'IBertForMaskedLM',
       'IBertForMultipleChoice',
       'IBertForQuestionAnswering',
       'IBertForSequenceClassification',
       'IBertForTokenClassification',
       'IBertModel',
       'IBertPreTrainedModel',
   ]

if TYPE_CHECKING:
   from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_ibert import (
          IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          IBertForMaskedLM,
          IBertForMultipleChoice,
          IBertForQuestionAnswering,
          IBertForSequenceClassification,
          IBertForTokenClassification,
          IBertModel,
          IBertPreTrainedModel,
      )

else:
   import sys

   _UpperCamelCase											=		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






