code: def reduce_avg(
      avg_val: torch.Tensor,
      sum_weight: torch.Tensor,
      cur_distributed_avg_val: torch.Tensor,
      cur_distributed_sum_weight: torch.Tensor,
  ) -> torch.Tensor:
      """
      Get the new weighted average value of a tensor. Steps:
      1. Sum across all trainers the weighted sum of values. This is implemented as a sum of product of
           current-epoch weighted average value and total weight.
      2. Get the new weighted average value by dividing the total weighted sum by the total weight.
          - The total are a sum of the current-epoch values across all trainers and the values from previous
              epochs stored in `avg_val` and `sum_weight`.
  
      Args:
          avg_val: Current weighted average value (from previous epochs).
          sum_weight: Total weight (from previous epochs).
          cur_distributed_avg_val: Current weighted average value in each trainers in current epoch.
          cur_distributed_sum_weight: Total weight in each trainer in current epoch.
      Returns:
          A new weighted average value.
      """
      total_weight = (
          sync_ddp_if_available(
              cur_distributed_sum_weight.clone(),
              # pyre-fixme[6]: For 2nd argument expected `Union[None, str, ReduceOp]`
              #  but got `RedOpType`.
              reduce_op=ReduceOp.SUM,
          )
          + sum_weight
      )  # clone the tensor, so that it's not modified in-place
      return (
          avg_val * sum_weight
          + sync_ddp_if_available(
              cur_distributed_avg_val * cur_distributed_sum_weight,
              # pyre-fixme[6]: For 2nd argument expected `Union[None, str, ReduceOp]`
              #  but got `RedOpType`.
              reduce_op=ReduceOp.SUM,
          )
      ) / total_weight
  
file_path: ReAgent/reagent/models/linear_regression.py
imports: import logging
  from typing import Dict, Optional
  import torch
  from pytorch_lightning.utilities.distributed import ReduceOp, sync_ddp_if_available
  from reagent.models.cb_base_model import UCBBaseModel
label_desc: Use image node_id 3 for calling a global function with example usage: reduce_avg(avg_val, sum_weight, cur_distributed_avg_val, cur_distributed_sum_weight) and returns: unknown