code: def train(
      sess_config,
      input_hooks,
      model,
      data_init_op,
      config,
      tf_config=None,
      server=None,
  ):
      steps = config["train_steps"]
      checkpoint_dir = config["checkpoint_dir"]
  
      model.is_training = True
      hooks = []
      hooks.extend(input_hooks)
  
      scaffold = tf.train.Scaffold(
          local_init_op=tf.group(
              tf.local_variables_initializer(), data_init_op
          ),
          saver=tf.train.Saver(
              max_to_keep=config["keep_checkpoint_max"]
          ),
      )
  
      stop_hook = tf.train.StopAtStepHook(last_step=steps)
      log_hook = tf.train.LoggingTensorHook(
          {"steps": model.global_step, "loss": model.loss},
          every_n_iter=100,
      )
      hooks.append(stop_hook)
      hooks.append(log_hook)
      if config["timeline"] > 0:
          hooks.append(
              tf.train.ProfilerHook(
                  save_steps=config["timeline"],
                  output_dir=checkpoint_dir,
              )
          )
      save_steps = (
          config["save_steps"]
          if config["save_steps"] or config["no_eval"]
          else steps
      )
      """
                              Incremental_Checkpoint
      Please add `save_incremental_checkpoint_secs` in 'tf.train.MonitoredTrainingSession'
      it's default to None, Incremental_save checkpoint time in seconds can be set
      to use incremental checkpoint function, like `tf.train.MonitoredTrainingSession(
          save_incremental_checkpoint_secs=args.incremental_ckpt)`
      """
      if config["incremental_ckpt"] and not config["tf"]:
          print("Incremental_Checkpoint is not really enabled.")
          print("Please see the comments in the code.")
          sys.exit()
  
      print("Creating session")
      t = time.time()
      with tf.train.MonitoredTrainingSession(
          master=server.target if server else "",
          is_chief=tf_config["is_chief"] if tf_config else True,
          hooks=hooks,
          scaffold=scaffold,
          checkpoint_dir=checkpoint_dir,
          save_checkpoint_steps=save_steps,
          summary_dir=checkpoint_dir,
          save_summaries_steps=config["save_steps"],
          config=sess_config,
      ) as sess:
          print(f"Session creation time: {time.time() - t:.8f}s")
          while not sess.should_stop():
              sess.run([model.loss, model.train_op])
      print("Training completed.")
  
imports: import time
  import argparse
  import tensorflow
  import os
  import sys
  import math
  import collections
  from tensorflow.python.client import timeline
  import json
  from tensorflow.python.ops import partitioned_variables
  import ray
  from bigdl.dllib.utils.log4Error import *
  from bigdl.orca import init_orca_context, stop_orca_context, OrcaContext
  from bigdl.orca.data.utils import process_spark_xshards
  from bigdl.orca.learn.utils import maybe_dataframe_to_xshards
  from bigdl.friesian.feature import FeatureTable
label_desc: Use image node_id 2 for calling a global function with example usage: train(sess_config, input_hooks, model, data_init_op, config, tf_config, server) without return types