code: def train(config, exe, program, reader, loss):
      total_loss = 0.0
      global_step = 0
      reader.start()
      start = time.time()
      try:
          while True:
              global_step += 1
              (t_loss,) = exe.run(program, fetch_list=[loss.name])
              t_loss = t_loss.mean()
  
              total_loss += t_loss
              if global_step % config.log_steps == 0:
                  avg_loss = total_loss / config.log_steps
                  total_loss = 0.0
                  sec_per_batch = (
                      time.time() - start
                  ) / config.log_steps
                  start = time.time()
                  log.info(
                      "sec/batch: %.6f | step: %s | train_loss: %.6f"
                      % (sec_per_batch, global_step, avg_loss)
                  )
  
              if (
                  fleet.is_first_worker()
                  and global_step % config.save_steps == 0
              ):
                  log.info(
                      "saving model on step %s to %s"
                      % (global_step, config.save_dir)
                  )
                  fleet.save_persistables(
                      exe,
                      config.save_dir,
                      paddle.static.default_main_program(),
                  )
      except paddle.framework.core.EOFException:
          reader.reset()
  
      if fleet.is_first_worker():
          log.info(
              "saving model to %s after training" % (config.save_dir)
          )
          fleet.save_persistables(
              exe, config.save_dir, paddle.static.default_main_program()
          )
  
file_path: PGL/apps/Graph4Rec/env_run/src/dist_cpu_train.py
imports: import os
  import sys
  import time
  import tqdm
  import yaml
  import argparse
  import numpy
  import pgl
  from pgl.utils.logger import log
  import paddle
  import paddle.nn
  from paddle.optimizer import Adam
  import paddle.distributed.fleet
  from utils.config import prepare_config
  from utils.logger import log_to_file
  import models
  from datasets.dist_dataloader import DistCPUDataloader
  import datasets.dataset
label_desc: Use image node_id 2 for calling a global function with example usage: train(config, exe, program, reader, loss) without return types