code: def train(
      model, data_loader, optim, log_per_step=1000, threshold=0.3
  ):
      model.train()
      total_loss = 0.0
      total_sample = 0
      bce_loss = paddle.nn.BCEWithLogitsLoss()
      test_probs_vals, test_labels_vals, test_topk_vals = [], [], []
  
      for batch, (node, labels) in enumerate(data_loader):
          num_samples = len(node)
          node = paddle.to_tensor(node)
          labels = paddle.to_tensor(labels)
          logits = model(node)
          probs = paddle.nn.functional.sigmoid(logits)
          loss = bce_loss(logits, labels)
          loss.backward()
          optim.step()
          optim.clear_grad()
  
          topk = labels.sum(-1)
          test_probs_vals.append(probs.numpy())
          test_labels_vals.append(labels.numpy())
          test_topk_vals.append(topk.numpy())
  
          total_loss += float(loss) * num_samples
          total_sample += num_samples
  
      test_probs_array = np.concatenate(test_probs_vals)
      test_labels_array = np.concatenate(test_labels_vals)
      test_topk_array = np.concatenate(test_topk_vals)
      test_macro_f1 = topk_f1_score(
          test_labels_array,
          test_probs_array,
          test_topk_array,
          "macro",
          threshold,
      )
      test_micro_f1 = topk_f1_score(
          test_labels_array,
          test_probs_array,
          test_topk_array,
          "micro",
          threshold,
      )
      test_loss_val = total_loss / total_sample
      log.info(
          "Train Loss: %f " % test_loss_val
          + "Train Macro F1: %f " % test_macro_f1
          + "Train Micro F1: %f " % test_micro_f1
      )
      return total_loss / total_sample
  
imports: import argparse
  import time
  import os
  import math
  import glob
  import numpy
  import paddle
  from easydict import EasyDict
  import pgl
  import yaml
  from paddle.optimizer import Adam
  import tqdm
  from pgl.utils.logger import log
  from sklearn.metrics import f1_score
  from dataset import ShardedDataset
label_desc: Use image node_id 4 for calling a global function with example usage: train(model, data_loader, optim, log_per_step, threshold) and returns: unknown