code: def train(model, data_iterator, optimizer, params, ex_params):
      """Train the model one epoch"""
      # set model to training mode
      model.train()
  
      loss_avg = util.RunningAverage()
      loss_avg_seq = util.RunningAverage()
      loss_avg_mat = util.RunningAverage()
      loss_avg_rel = util.RunningAverage()
  
      # Use tqdm for progress bar
      # one epoch
      t = trange(len(data_iterator), ascii=True)
      for step, _ in enumerate(t):
          # fetch the next training batch
          batch = next(iter(data_iterator))
          batch = tuple(t.to(params.device) for t in batch)
          (
              input_ids,
              attention_mask,
              seq_tags,
              relations,
              corres_tags,
              rel_tags,
          ) = batch
  
          # compute model output and loss
          loss, loss_seq, loss_mat, loss_rel = model(
              input_ids,
              attention_mask=attention_mask,
              seq_tags=seq_tags,
              potential_rels=relations,
              corres_tags=corres_tags,
              rel_tags=rel_tags,
              ex_params=ex_params,
          )
  
          if params.n_gpu > 1 and params.multi_gpu:
              loss = loss.mean()  # mean() to average on multi-gpu.
          if params.gradient_accumulation_steps > 1:
              loss = loss / params.gradient_accumulation_steps
  
          # back-prop
          loss.backward()
  
          if (step + 1) % params.gradient_accumulation_steps == 0:
              # performs updates using calculated gradients
              optimizer.step()
              model.zero_grad()
  
          # update the average loss
          loss_avg.update(
              loss.item() * params.gradient_accumulation_steps
          )
          loss_avg_seq.update(loss_seq.item())
          loss_avg_mat.update(loss_mat.item())
          loss_avg_rel.update(loss_rel.item())
          # 右边第一个0为填充数，第二个5为数字个数为5位，第三个3为小数点有效数为3，最后一个f为数据类型为float类型。
          t.set_postfix(
              loss="{:05.3f}".format(loss_avg()),
              loss_seq="{:05.3f}".format(loss_avg_seq()),
              loss_mat="{:05.3f}".format(loss_avg_mat()),
              loss_rel="{:05.3f}".format(loss_avg_rel()),
          )
  
file_path: DeepKE/example/triple/PRGC/run.py
imports: import os
  import hydra
  from hydra.utils import get_original_cwd
  import torch
  from transformers import BertConfig
  import random
  import logging
  from tqdm import trange
  import argparse
  import wandb
  from deepke.triple_extraction.PRGC import *
label_desc: Use image node_id 1 for calling a global function with example usage: train(model, data_iterator, optimizer, params, ex_params) without return types