def METHOD_NAME(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())