code: def broadcast_from_last_to_first_pipeline_stage(
      size, dtype, tensor=None
  ):
      """Broadcast tensor values from last stage into the first stage."""
  
      is_last_stage = mpu.is_pipeline_last_stage()
      is_first_stage = mpu.is_pipeline_first_stage()
      # If first stage and last state are the same, then there is no
      # pipeline parallelism and no need to communicate.
      if is_first_stage and is_last_stage:
          return tensor
      # Only first and last stage pipeline stages need to be involved.
      if is_last_stage or is_first_stage:
          if is_last_stage:
              _is_cuda_contiguous(tensor)
          else:
              tensor = torch.empty(
                  size, dtype=dtype, device=torch.cuda.current_device()
              )
          src = mpu.get_pipeline_model_parallel_last_rank()
          group = mpu.get_embedding_group()
          # Broadcast from last stage into the first stage.
          torch.distributed.broadcast(tensor, src, group)
      else:
          tensor = None
  
      return tensor
  
file_path: megatron-lm/megatron/text_generation/communication.py
imports: import torch
  from megatron.core import mpu
label_desc: Use image node_id 6 for calling a global function with example usage: broadcast_from_last_to_first_pipeline_stage(size, dtype, tensor) and returns: tensor, tensor