class_docstr: Solver for raw tensorflow model.
class_docstr_tok: ["Solver","for","raw","tensorflow","model","."]
docstr: Build the model for training, eval and infer.
docstr_tok: ["Build","the","model","for","training",",","eval","and","infer","."]
code: def build(self, mode: str):
      """Build the model for training, eval and infer."""
      inputs = self.input_fn(mode)
      logging.info("build input data done...")
  
      model = self.model_fn()
      training = mode == utils.TRAIN
      model.logits = model(inputs["input_x_dict"], training=training)
      model.input_x_len = inputs["input_x_len"]
      model.iterator = inputs["iterator"]
      model.input_x_dict = inputs["input_x_dict"]
      model.input_x_len = inputs["input_x_len"]
      model.loss_fn = self.get_loss_fn()
      if mode != utils.INFER or not self.infer_no_label:
          input_y = inputs["input_y_dict"]["input_y"]
          if isinstance(model.loss_fn, list):
              model.loss = []
              for i, one_loss_fn in enumerate(model.loss_fn):
                  one_loss = one_loss_fn(
                      labels=input_y[i],
                      logits=model.logits[i],
                      input_length=model.input_x_len,
                      model=model,
                      name="loss_{}".format(i),
                  )
                  model.loss.append(one_loss)
              model.loss_op = tf.add_n(model.loss, name="loss_sum")
          else:
              model.loss = model.loss_fn(
                  labels=input_y,
                  logits=model.logits,
                  input_length=model.input_x_len,
                  model=model,
                  name="loss",
              )
              model.loss_op = model.loss
          logging.info("model.loss done")
          model.input_y = input_y
  
      # output related
      self.build_output(model)
      return model
  
imports: import re
  import math
  import numpy
  import delta.compat
  from absl import logging
  from delta.utils.solver.base_solver import Solver
  from delta import utils
  from delta.utils.register import registers
  from delta.utils.solver.utils.solver_utils import get_checkpoint_dir
  from delta.utils.solver.utils.solver_utils import get_ckpt_state
  from delta.utils.solver.utils.solver_utils import get_session_conf
  from delta.utils.solver.utils.solver_utils import to_saved_model
  from delta.utils.solver.utils.solver_utils import run_metrics
label_desc: Use image node_id 9 for calling the RawSolver obj's underlying member method code with example usage: obj.build(mode) and returns: model