






import enum
import warnings

from .. import MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_CAUSAL_LM_MAPPING
from ..utils import add_end_docstrings, is_tf_available
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
       import tensorflow as tf







class 		_A						( enum.Enum ):
  lowercase_						:			Any						=					0
  lowercase_						:			str						=					1
  lowercase_						:			Optional[Any]						=					2







@add_end_docstrings(UpperCAmelCase_ )
class 		_A						( UpperCAmelCase_ ):
  lowercase_						:			int						=					'''
    In 1991, the remains of Russian Tsar Nicholas II and his family (except for Alexei and Maria) are discovered. The
    voice of Nicholas\'s young son, Tsarevich Alexei Nikolaevich, narrates the remainder of the story. 1883 Western
    Siberia, a young Grigori Rasputin is asked by his father and a group of men to perform magic. Rasputin has a vision
    and denounces one of the men as a horse thief. Although his father initially slaps him for making such an
    accusation, Rasputin watches as the man is chased outside and beaten. Twenty years later, Rasputin sees a vision of
    the Virgin Mary, prompting him to become a priest. Rasputin quickly becomes famous, with people, even a bishop,
    begging for his blessing. <eod> </s> <eos>
    '''

  def __init__(    self						:	List[str]   ,				*lowerCamelCase__						:	Dict   ,				**lowerCamelCase__						:	Tuple			):
     """simple docstring"""

     super().__init__(*lowerCamelCase__   ,				**lowerCamelCase__			)
     self.check_model_type(
         TF_MODEL_FOR_CAUSAL_LM_MAPPING if self.framework == """tf""" else MODEL_FOR_CAUSAL_LM_MAPPING			)
     if "prefix" not in self._preprocess_params:
        # This is very specific. The logic is quite complex and needs to be done
        # as a "default".
        # It also defines both some preprocess_kwargs and generate_kwargs
        # which is why we cannot put them in their respective methods.
        __UpperCamelCase	:			Dict					=					None
        if self.model.config.prefix is not None:
           __UpperCamelCase	:			Optional[Any]					=					self.model.config.prefix
        if prefix is None and self.model.__class__.__name__ in [
            "XLNetLMHeadModel",
            "TransfoXLLMHeadModel",
            "TFXLNetLMHeadModel",
            "TFTransfoXLLMHeadModel",
        ]:
           # For XLNet and TransformerXL we add an article to the prompt to give more state to the model.
           __UpperCamelCase	:			List[str]					=					self.XL_PREFIX
        if prefix is not None:
           # Recalculate some generate_kwargs linked to prefix.
           __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase	:			str					=					self._sanitize_parameters(prefix=lowerCamelCase__   ,				**self._forward_params			)
           __UpperCamelCase	:			Union[str, Any]					=					{**self._preprocess_params, **preprocess_params}
           __UpperCamelCase	:			List[str]					=					{**self._forward_params, **forward_params}

  def    a					(    self						:	int   ,				lowerCamelCase__						:	Dict=None   ,				lowerCamelCase__						:	Dict=None   ,				lowerCamelCase__						:	Optional[int]=None   ,				lowerCamelCase__						:	int=None   ,				lowerCamelCase__						:	Tuple=None   ,				lowerCamelCase__						:	Dict=None   ,				lowerCamelCase__						:	Dict=None   ,				lowerCamelCase__						:	List[str]=None   ,				**lowerCamelCase__						:	Dict   ,				):
     """simple docstring"""

     __UpperCamelCase	:			List[str]					=					{}
     if prefix is not None:
        __UpperCamelCase	:			List[str]					=					prefix
     if prefix:
        __UpperCamelCase	:			Any					=					self.tokenizer(
            lowerCamelCase__   ,				padding=lowerCamelCase__   ,				add_special_tokens=lowerCamelCase__   ,				return_tensors=self.framework			)
        __UpperCamelCase	:			str					=					prefix_inputs["""input_ids"""].shape[-1]

     if handle_long_generation is not None:
        if handle_long_generation not in {"hole"}:
           raise ValueError(
               f'{handle_long_generation} is not a valid value for `handle_long_generation` parameter expected'
               """ [None, 'hole']"""			)
        __UpperCamelCase	:			Dict					=					handle_long_generation

     preprocess_params.update(lowerCamelCase__			)
     __UpperCamelCase	:			Optional[Any]					=					generate_kwargs

     __UpperCamelCase	:			List[str]					=					{}
     if return_full_text is not None and return_type is None:
        if return_text is not None:
           raise ValueError("""`return_text` is mutually exclusive with `return_full_text`"""			)
        if return_tensors is not None:
           raise ValueError("""`return_full_text` is mutually exclusive with `return_tensors`"""			)
        __UpperCamelCase	:			Union[str, Any]					=					ReturnType.FULL_TEXT if return_full_text else ReturnType.NEW_TEXT
     if return_tensors is not None and return_type is None:
        if return_text is not None:
           raise ValueError("""`return_text` is mutually exclusive with `return_tensors`"""			)
        __UpperCamelCase	:			Any					=					ReturnType.TENSORS
     if return_type is not None:
        __UpperCamelCase	:			List[str]					=					return_type
     if clean_up_tokenization_spaces is not None:
        __UpperCamelCase	:			List[Any]					=					clean_up_tokenization_spaces

     if stop_sequence is not None:
        __UpperCamelCase	:			Optional[int]					=					self.tokenizer.encode(lowerCamelCase__   ,				add_special_tokens=lowerCamelCase__			)
        if len(lowerCamelCase__			) > 1:
           warnings.warn(
               """Stopping on a multiple token sequence is not yet supported on transformers. The first token of"""
               """ the stop sequence will be used as the stop sequence string in the interim."""			)
        __UpperCamelCase	:			List[Any]					=					stop_sequence_ids[0]

     return preprocess_params, forward_params, postprocess_params

  def    a					(    self						:	List[str]   ,				*lowerCamelCase__						:	Tuple   ,				**lowerCamelCase__						:	Any			):
     """simple docstring"""

     if self.model.__class__.__name__ in ["TransfoXLLMHeadModel"]:
        kwargs.update({"""add_space_before_punct_symbol""": True}			)

     return super()._parse_and_tokenize(*lowerCamelCase__   ,				**lowerCamelCase__			)

  def __call__(    self						:	Dict   ,				lowerCamelCase__						:	List[Any]   ,				**lowerCamelCase__						:	Dict			):
     """simple docstring"""

     return super().__call__(lowerCamelCase__   ,				**lowerCamelCase__			)

  def    a					(    self						:	List[Any]   ,				lowerCamelCase__						:	Optional[int]   ,				lowerCamelCase__						:	str=""   ,				lowerCamelCase__						:	Optional[Any]=None   ,				**lowerCamelCase__						:	int			):
     """simple docstring"""

     __UpperCamelCase	:			Optional[int]					=					self.tokenizer(
         prefix + prompt_text   ,				padding=lowerCamelCase__   ,				add_special_tokens=lowerCamelCase__   ,				return_tensors=self.framework			)
     __UpperCamelCase	:			Optional[Any]					=					prompt_text

     if handle_long_generation == "hole":
        __UpperCamelCase	:			Any					=					inputs["""input_ids"""].shape[-1]
        if "max_new_tokens" in generate_kwargs:
           __UpperCamelCase	:			List[str]					=					generate_kwargs["""max_new_tokens"""]
        else:
           __UpperCamelCase	:			str					=					generate_kwargs.get("""max_length"""   ,				self.model.config.max_length			) - cur_len
           if new_tokens < 0:
              raise ValueError("""We cannot infer how many new tokens are expected"""			)
        if cur_len + new_tokens > self.tokenizer.model_max_length:
           __UpperCamelCase	:			int					=					self.tokenizer.model_max_length - new_tokens
           if keep_length <= 0:
              raise ValueError(
                  """We cannot use `hole` to handle this generation the number of desired tokens exceeds the"""
                  """ models max length"""			)

           __UpperCamelCase	:			str					=					inputs["""input_ids"""][:, -keep_length:]
           if "attention_mask" in inputs:
              __UpperCamelCase	:			Any					=					inputs["""attention_mask"""][:, -keep_length:]

     return inputs

  def    a					(    self						:	int   ,				lowerCamelCase__						:	Optional[int]   ,				**lowerCamelCase__						:	List[Any]			):
     """simple docstring"""

     __UpperCamelCase	:			int					=					model_inputs["""input_ids"""]
     __UpperCamelCase	:			str					=					model_inputs.get("""attention_mask"""   ,				lowerCamelCase__			)
     # Allow empty prompts
     if input_ids.shape[1] == 0:
        __UpperCamelCase	:			Optional[int]					=					None
        __UpperCamelCase	:			str					=					None
        __UpperCamelCase	:			str					=					1
     else:
        __UpperCamelCase	:			str					=					input_ids.shape[0]
     __UpperCamelCase	:			int					=					model_inputs.pop("""prompt_text"""			)

     # If there is a prefix, we may need to adjust the generation length. Do so without permanently modifying
     # generate_kwargs, as some of the parameterization may come from the initialization of the pipeline.
     __UpperCamelCase	:			Union[str, Any]					=					generate_kwargs.pop("""prefix_length"""   ,				0			)
     if prefix_length > 0:
        __UpperCamelCase	:			Optional[Any]					=					"""max_new_tokens""" in generate_kwargs or (
            """generation_config""" in generate_kwargs
            and generate_kwargs["""generation_config"""].max_new_tokens is not None
        )
        if not has_max_new_tokens:
           __UpperCamelCase	:			Any					=					generate_kwargs.get("""max_length"""			) or self.model.config.max_length
           generate_kwargs["max_length"] += prefix_length
        __UpperCamelCase	:			Any					=					"""min_new_tokens""" in generate_kwargs or (
            """generation_config""" in generate_kwargs
            and generate_kwargs["""generation_config"""].min_new_tokens is not None
        )
        if not has_min_new_tokens and "min_length" in generate_kwargs:
           generate_kwargs["min_length"] += prefix_length

        # BS x SL
     __UpperCamelCase	:			str					=					self.model.generate(input_ids=lowerCamelCase__   ,				attention_mask=lowerCamelCase__   ,				**lowerCamelCase__			)
     __UpperCamelCase	:			Optional[int]					=					generated_sequence.shape[0]
     if self.framework == "pt":
        __UpperCamelCase	:			str					=					generated_sequence.reshape(lowerCamelCase__   ,				out_b // in_b   ,				*generated_sequence.shape[1:]			)
     elif self.framework == "tf":
        __UpperCamelCase	:			List[Any]					=					tf.reshape(lowerCamelCase__   ,				(in_b, out_b // in_b, *generated_sequence.shape[1:])			)
     return {"generated_sequence": generated_sequence, "input_ids": input_ids, "prompt_text": prompt_text}

  def    a					(    self						:	Any   ,				lowerCamelCase__						:	Optional[Any]   ,				lowerCamelCase__						:	str=ReturnType.FULL_TEXT   ,				lowerCamelCase__						:	Any=True			):
     """simple docstring"""

     __UpperCamelCase	:			List[Any]					=					model_outputs["""generated_sequence"""][0]
     __UpperCamelCase	:			Optional[int]					=					model_outputs["""input_ids"""]
     __UpperCamelCase	:			Dict					=					model_outputs["""prompt_text"""]
     __UpperCamelCase	:			Dict					=					generated_sequence.numpy().tolist()
     __UpperCamelCase	:			Tuple					=					[]
     for sequence in generated_sequence:
        if return_type == ReturnType.TENSORS:
           __UpperCamelCase	:			Optional[Any]					=					{"""generated_token_ids""": sequence}
        elif return_type in {ReturnType.NEW_TEXT, ReturnType.FULL_TEXT}:
           # Decode text
           __UpperCamelCase	:			Dict					=					self.tokenizer.decode(
               lowerCamelCase__   ,				skip_special_tokens=lowerCamelCase__   ,				clean_up_tokenization_spaces=lowerCamelCase__   ,				)

           # Remove PADDING prompt of the sequence if XLNet or Transfo-XL model is used
           if input_ids is None:
              __UpperCamelCase	:			Optional[int]					=					0
           else:
              __UpperCamelCase	:			Any					=					len(
                  self.tokenizer.decode(
                      input_ids[0]   ,				skip_special_tokens=lowerCamelCase__   ,				clean_up_tokenization_spaces=lowerCamelCase__   ,				)			)

           if return_type == ReturnType.FULL_TEXT:
              __UpperCamelCase	:			Optional[int]					=					prompt_text + text[prompt_length:]
           else:
              __UpperCamelCase	:			Dict					=					text[prompt_length:]

           __UpperCamelCase	:			Union[str, Any]					=					{"""generated_text""": all_text}
        records.append(lowerCamelCase__			)

     return records











import logging

import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEncoder,
    BertModel,
    BertPreTrainedModel,
)


UpperCamelCase    							=      logging.getLogger(__name__)







class 		_A						( UpperCAmelCase_ ):

  def    a					(    self						:	Tuple   ,				lowerCamelCase__						:	Optional[int]   ,				lowerCamelCase__						:	Union[str, Any]   ,				lowerCamelCase__						:	str=None   ,				lowerCamelCase__						:	int=None			):
     """simple docstring"""

     __UpperCamelCase	:			Optional[Any]					=					self.layer[current_layer](lowerCamelCase__   ,				lowerCamelCase__   ,				head_mask[current_layer]			)

     __UpperCamelCase	:			Optional[Any]					=					layer_outputs[0]

     return hidden_states







@add_start_docstrings(
    '''The bare Bert Model transformer with PABEE outputting raw hidden-states without any specific head on top.'''	,				UpperCAmelCase_	,				)
class 		_A						( UpperCAmelCase_ ):

  def __init__(    self						:	Tuple   ,				lowerCamelCase__						:	Tuple			):
     """simple docstring"""

     super().__init__(lowerCamelCase__			)

     __UpperCamelCase	:			List[str]					=					BertEncoderWithPabee(lowerCamelCase__			)

     self.init_weights()
     __UpperCamelCase	:			Optional[int]					=					0
     __UpperCamelCase	:			Tuple					=					0
     __UpperCamelCase	:			Any					=					0

     __UpperCamelCase	:			Optional[Any]					=					0

  def    a					(    self						:	Union[str, Any]   ,				lowerCamelCase__						:	Any			):
     """simple docstring"""

     __UpperCamelCase	:			List[Any]					=					threshold

  def    a					(    self						:	Optional[int]   ,				lowerCamelCase__						:	Union[str, Any]			):
     """simple docstring"""

     __UpperCamelCase	:			int					=					patience

  def    a					(    self						:	Optional[int]			):
     """simple docstring"""

     __UpperCamelCase	:			int					=					0
     __UpperCamelCase	:			Tuple					=					0

  def    a					(    self						:	int			):
     """simple docstring"""

     __UpperCamelCase	:			int					=					self.inference_layers_num / self.inference_instances_num
     __UpperCamelCase	:			str					=					(
         f'*** Patience = {self.patience} Avg. Inference Layers = {avg_inf_layers:.2f} Speed Up ='
         f' {1 - avg_inf_layers / self.config.num_hidden_layers:.2f} ***'
     )
     print(lowerCamelCase__			)

  @add_start_docstrings_to_model_forward(lowerCamelCase__			)
  def    a					(    self						:	Any   ,				lowerCamelCase__						:	List[Any]=None   ,				lowerCamelCase__						:	List[str]=None   ,				lowerCamelCase__						:	List[Any]=None   ,				lowerCamelCase__						:	Optional[Any]=None   ,				lowerCamelCase__						:	List[str]=None   ,				lowerCamelCase__						:	str=None   ,				lowerCamelCase__						:	List[Any]=None   ,				lowerCamelCase__						:	Any=None   ,				lowerCamelCase__						:	List[str]=None   ,				lowerCamelCase__						:	List[str]=None   ,				lowerCamelCase__						:	str=False   ,				):
     """simple docstring"""

     if input_ids is not None and inputs_embeds is not None:
        raise ValueError("""You cannot specify both input_ids and inputs_embeds at the same time"""			)
     elif input_ids is not None:
        __UpperCamelCase	:			Optional[Any]					=					input_ids.size()
     elif inputs_embeds is not None:
        __UpperCamelCase	:			Tuple					=					inputs_embeds.size()[:-1]
     else:
        raise ValueError("""You have to specify either input_ids or inputs_embeds"""			)

     __UpperCamelCase	:			Tuple					=					input_ids.device if input_ids is not None else inputs_embeds.device

     if attention_mask is None:
        __UpperCamelCase	:			Optional[Any]					=					torch.ones(lowerCamelCase__   ,				device=lowerCamelCase__			)
     if token_type_ids is None:
        __UpperCamelCase	:			str					=					torch.zeros(lowerCamelCase__   ,				dtype=torch.long   ,				device=lowerCamelCase__			)

     # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
     # ourselves in which case we just need to make it broadcastable to all heads.
     __UpperCamelCase	:			torch.Tensor					=					self.get_extended_attention_mask(lowerCamelCase__   ,				lowerCamelCase__   ,				lowerCamelCase__			)

     # If a 2D ou 3D attention mask is provided for the cross-attention
     # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
     if self.config.is_decoder and encoder_hidden_states is not None:
        __UpperCamelCase	,     __UpperCamelCase	,     __UpperCamelCase	:			Optional[Any]					=					encoder_hidden_states.size()
        __UpperCamelCase	:			Union[str, Any]					=					(encoder_batch_size, encoder_sequence_length)
        if encoder_attention_mask is None:
           __UpperCamelCase	:			Union[str, Any]					=					torch.ones(lowerCamelCase__   ,				device=lowerCamelCase__			)
        __UpperCamelCase	:			Optional[int]					=					self.invert_attention_mask(lowerCamelCase__			)
     else:
        __UpperCamelCase	:			str					=					None

     # Prepare head mask if needed
     # 1.0 in head_mask indicate we keep the head
     # attention_probs has shape bsz x n_heads x N x N
     # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
     # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
     __UpperCamelCase	:			int					=					self.get_head_mask(lowerCamelCase__   ,				self.config.num_hidden_layers			)

     __UpperCamelCase	:			Any					=					self.embeddings(
         input_ids=lowerCamelCase__   ,				position_ids=lowerCamelCase__   ,				token_type_ids=lowerCamelCase__   ,				inputs_embeds=lowerCamelCase__			)
     __UpperCamelCase	:			Optional[int]					=					embedding_output

     if self.training:
        __UpperCamelCase	:			List[Any]					=					[]
        for i in range(self.config.num_hidden_layers			):
           __UpperCamelCase	:			List[Any]					=					self.encoder.adaptive_forward(
               lowerCamelCase__   ,				current_layer=lowerCamelCase__   ,				attention_mask=lowerCamelCase__   ,				head_mask=lowerCamelCase__			)

           __UpperCamelCase	:			Tuple					=					self.pooler(lowerCamelCase__			)
           __UpperCamelCase	:			str					=					output_layers[i](output_dropout(lowerCamelCase__			)			)
           res.append(lowerCamelCase__			)
     elif self.patience == 0:  # Use all layers for inference
        __UpperCamelCase	:			Union[str, Any]					=					self.encoder(
            lowerCamelCase__   ,				attention_mask=lowerCamelCase__   ,				head_mask=lowerCamelCase__   ,				encoder_hidden_states=lowerCamelCase__   ,				encoder_attention_mask=lowerCamelCase__   ,				)
        __UpperCamelCase	:			Optional[int]					=					self.pooler(encoder_outputs[0]			)
        __UpperCamelCase	:			Union[str, Any]					=					[output_layers[self.config.num_hidden_layers - 1](lowerCamelCase__			)]
     else:
        __UpperCamelCase	:			Union[str, Any]					=					0
        __UpperCamelCase	:			Optional[Any]					=					None
        __UpperCamelCase	:			List[Any]					=					0
        for i in range(self.config.num_hidden_layers			):
           calculated_layer_num += 1
           __UpperCamelCase	:			Union[str, Any]					=					self.encoder.adaptive_forward(
               lowerCamelCase__   ,				current_layer=lowerCamelCase__   ,				attention_mask=lowerCamelCase__   ,				head_mask=lowerCamelCase__			)

           __UpperCamelCase	:			str					=					self.pooler(lowerCamelCase__			)
           __UpperCamelCase	:			Any					=					output_layers[i](lowerCamelCase__			)
           if regression:
              __UpperCamelCase	:			Optional[int]					=					logits.detach()
              if patient_result is not None:
                 __UpperCamelCase	:			Dict					=					patient_result.detach()
              if (patient_result is not None) and torch.abs(patient_result - labels			) < self.regression_threshold:
                 patient_counter += 1
              else:
                 __UpperCamelCase	:			List[str]					=					0
           else:
              __UpperCamelCase	:			Optional[int]					=					logits.detach().argmax(dim=1			)
              if patient_result is not None:
                 __UpperCamelCase	:			Union[str, Any]					=					patient_result.detach().argmax(dim=1			)
              if (patient_result is not None) and torch.all(labels.eq(lowerCamelCase__			)			):
                 patient_counter += 1
              else:
                 __UpperCamelCase	:			str					=					0

           __UpperCamelCase	:			Union[str, Any]					=					logits
           if patient_counter == self.patience:
              break
        __UpperCamelCase	:			List[str]					=					[patient_result]
        self.inference_layers_num += calculated_layer_num
        self.inference_instances_num += 1

     return res







@add_start_docstrings(
    '''Bert Model transformer with PABEE and a sequence classification/regression head on top (a linear layer on top of
    the pooled output) e.g. for GLUE tasks. '''	,				UpperCAmelCase_	,				)
class 		_A						( UpperCAmelCase_ ):

  def __init__(    self						:	Any   ,				lowerCamelCase__						:	Union[str, Any]			):
     """simple docstring"""

     super().__init__(lowerCamelCase__			)
     __UpperCamelCase	:			Dict					=					config.num_labels

     __UpperCamelCase	:			List[Any]					=					BertModelWithPabee(lowerCamelCase__			)
     __UpperCamelCase	:			Optional[int]					=					nn.Dropout(config.hidden_dropout_prob			)
     __UpperCamelCase	:			List[Any]					=					nn.ModuleList(
         [nn.Linear(config.hidden_size   ,				self.config.num_labels			) for _ in range(config.num_hidden_layers			)]			)

     self.init_weights()

  @add_start_docstrings_to_model_forward(lowerCamelCase__			)
  def    a					(    self						:	List[Any]   ,				lowerCamelCase__						:	Union[str, Any]=None   ,				lowerCamelCase__						:	Dict=None   ,				lowerCamelCase__						:	Union[str, Any]=None   ,				lowerCamelCase__						:	List[Any]=None   ,				lowerCamelCase__						:	Optional[Any]=None   ,				lowerCamelCase__						:	Optional[int]=None   ,				lowerCamelCase__						:	Dict=None   ,				):
     """simple docstring"""

     __UpperCamelCase	:			str					=					self.bert(
         input_ids=lowerCamelCase__   ,				attention_mask=lowerCamelCase__   ,				token_type_ids=lowerCamelCase__   ,				position_ids=lowerCamelCase__   ,				head_mask=lowerCamelCase__   ,				inputs_embeds=lowerCamelCase__   ,				output_dropout=self.dropout   ,				output_layers=self.classifiers   ,				regression=self.num_labels == 1   ,				)

     __UpperCamelCase	:			List[str]					=					(logits[-1],)

     if labels is not None:
        __UpperCamelCase	:			Tuple					=					None
        __UpperCamelCase	:			Union[str, Any]					=					0
        for ix, logits_item in enumerate(lowerCamelCase__			):
           if self.num_labels == 1:
              #  We are doing regression
              __UpperCamelCase	:			Union[str, Any]					=					MSELoss()
              __UpperCamelCase	:			Optional[Any]					=					loss_fct(logits_item.view(-1			)   ,				labels.view(-1			)			)
           else:
              __UpperCamelCase	:			Dict					=					CrossEntropyLoss()
              __UpperCamelCase	:			Dict					=					loss_fct(logits_item.view(-1   ,				self.num_labels			)   ,				labels.view(-1			)			)
           if total_loss is None:
              __UpperCamelCase	:			Dict					=					loss
           else:
              total_loss += loss * (ix + 1)
           total_weights += ix + 1
        __UpperCamelCase	:			Tuple					=					(total_loss / total_weights,) + outputs

     return outputs



