code: def train(model_args, data_args, training_args, args):
      logger.info(f"Start Time: {get_format_time()}")
      logger.info(
          f"model_args:{model_args}\ndata_args:{data_args}\ntraining_args:{training_args}\n"
      )
      model_class, tokenizer_class, trainer_class = get_model_tokenizer(
          model_args.model_name
      )
      logger.info(
          f"model_class:{model_class}\ntokenizer_class:{tokenizer_class}\ntrainer_class:{trainer_class}\n"
      )
      tokenizer = tokenizer_class.from_pretrained(
          model_args.model_name_or_path,
          trust_remote_code=args.trust_remote_code,
      )
      model, args = get_accelerate_model(args, model_class)
      model.config.use_cache = False
      model.print_trainable_parameters()
      world_size = int(os.environ.get("WORLD_SIZE", 1))
      ddp = world_size != 1
      if ddp:
          training_args.ddp_find_unused_parameters = False
      else:
          training_args.ddp_find_unused_parameters = None
  
      if data_args.train_file is not None:
          train_data = Dataset.from_json(data_args.train_file)
      if data_args.valid_file is not None:
          valid_data = Dataset.from_json(data_args.valid_file)
      else:
          if training_args.do_eval and data_args.val_set_size > 0:
              train_val = train_data.train_test_split(
                  test_size=data_args.val_set_size,
                  shuffle=True,
                  seed=42,
              )
              train_data = train_val["train"]
              valid_data = train_val["test"]
  
      coll_fn, data_collator, prompter = get_specific(
          model_args.model_name, tokenizer, model, data_args
      )
      fn_kwargs = {
          "prompter": prompter,
          "tokenizer": tokenizer,
          "options": data_args,
      }
      logger.info(
          f"coll_fn:{coll_fn}\ndata_collator:{data_collator}\nprompter:{prompter}\n"
      )
      logger.info(
          f"BOS:{tokenizer.bos_token_id},{tokenizer.bos_token}\tEOS:{tokenizer.eos_token_id},{tokenizer.eos_token}\tPAD:{tokenizer.pad_token_id},{tokenizer.pad_token}"
      )
  
      if training_args.do_train:
          train_data = train_data.shuffle().map(
              coll_fn,
              num_proc=data_args.preprocessing_num_workers,
              remove_columns=train_data.column_names,
              load_from_cache_file=True,
              fn_kwargs=fn_kwargs,
          )
      if training_args.do_eval:
          valid_data = valid_data.shuffle().map(
              coll_fn,
              num_proc=data_args.preprocessing_num_workers,
              remove_columns=valid_data.column_names,
              load_from_cache_file=True,
              fn_kwargs=fn_kwargs,
          )
  
      trainer = trainer_class(
          model=model,
          train_dataset=train_data if training_args.do_train else None,
          eval_dataset=valid_data if training_args.do_eval else None,
          args=training_args,
          data_collator=data_collator,
      )
  
      all_metrics = {}
      verify_datatype(model)
      if args.do_train:
          logger.info("*** Train ***")
          # Note: `resume_from_checkpoint` not supported for adapter checkpoints by HF.
          # Currently adapter checkpoint is reloaded as expected but optimizer/scheduler states are not.
          print(
              "args.resume_from_checkpoint", args.resume_from_checkpoint
          )
          train_result = trainer.train(
              resume_from_checkpoint=args.resume_from_checkpoint
          )
          metrics = train_result.metrics
          trainer.log_metrics("train", metrics)
          trainer.save_metrics("train", metrics)
          trainer.save_state()
          all_metrics.update(metrics)
      if args.do_eval:
          logger.info("*** Evaluate ***")
          metrics = trainer.evaluate(metric_key_prefix="eval")
          trainer.log_metrics("eval", metrics)
          trainer.save_metrics("eval", metrics)
          all_metrics.update(metrics)
  
      logger.info(f"End Time: {get_format_time()}")
  
file_path: DeepKE/example/llm/InstructKGC/src/finetune.py
imports: import os
  import sys
  import logging
  import argparse
  from datasets import Dataset
  import torch
  from transformers import HfArgumentParser, DataCollatorForSeq2Seq, GenerationConfig, BitsAndBytesConfig
  from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training, set_peft_model_state_dict
  from peft.tuners.lora import LoraLayer
  from utils.general_utils import LORA_TARGET_MODULES_DICT, seed_torch, get_model_tokenizer, get_model_name, get_format_time
  from utils.prompter import Prompter
  from utils.args import DataArguments, ModelArguments, TrainingArguments, GenerationArguments
  from datamodule import COLL_FN_DICT, DataCollatorForCPMBEE
label_desc: Use image node_id 4 for calling a global function with example usage: train(model_args, data_args, training_args, args) without return types