code: def main():
      args = parse_args()
      cfg = Config.fromfile(args.config)
  
      init_default_scope(cfg.get("default_scope", "mmocr"))
  
      if args.cfg_options is not None:
          cfg.merge_from_dict(args.cfg_options)
      if cfg.get("work_dir", None) is None:
          # use config filename as default work_dir if cfg.work_dir is None
          cfg.work_dir = osp.join(
              "./work_dirs", osp.splitext(osp.basename(args.config))[0]
          )
  
      cfg.log_level = args.log_level
  
      # make sure save_root exists
      if args.save_path and not args.save_path.parent.exists():
          raise FileNotFoundError(
              f"The save path is {args.save_path}, and directory "
              f"'{args.save_path.parent}' do not exist."
          )
  
      # init logger
      print("Param_scheduler :")
      rich.print_json(json.dumps(cfg.param_scheduler))
  
      # prepare data loader
      batch_size = cfg.train_dataloader.batch_size * args.ngpus
  
      if "by_epoch" in cfg.train_cfg:
          by_epoch = cfg.train_cfg.get("by_epoch")
      elif "type" in cfg.train_cfg:
          by_epoch = cfg.train_cfg.get("type") == "EpochBasedTrainLoop"
      else:
          raise ValueError("please set `train_cfg`.")
  
      if args.dataset_size is None and by_epoch:
          dataset_size = len(
              build_dataset(cfg.train_dataloader.dataset)
          )
      else:
          dataset_size = args.dataset_size or batch_size
  
      class FakeDataloader(list):
          dataset = MagicMock(metainfo=None)
  
      data_loader = FakeDataloader(range(dataset_size // batch_size))
      dataset_info = (
          f"\nDataset infos:"
          f"\n - Dataset size: {dataset_size}"
          f"\n - Batch size per GPU: {cfg.train_dataloader.batch_size}"
          f"\n - Number of GPUs: {args.ngpus}"
          f"\n - Total batch size: {batch_size}"
      )
      if by_epoch:
          dataset_info += (
              f"\n - Iterations per epoch: {len(data_loader)}"
          )
      rich.print(dataset_info + "\n")
  
      # simulation training process
      param_dict = simulate_train(data_loader, cfg, by_epoch)
      param_list = param_dict[args.parameter]
  
      if args.parameter == "lr":
          param_name = "Learning Rate"
      elif args.parameter == "momentum":
          param_name = "Momentum"
      else:
          param_name = "Weight Decay"
      plot_curve(
          param_list, args, param_name, len(data_loader), by_epoch
      )
  
      if args.save_path:
          plt.savefig(args.save_path)
          print(
              f"\nThe {param_name} graph is saved at {args.save_path}"
          )
  
      if not args.not_show:
          plt.show()
  
imports: import argparse
  import json
  import os.path
  import re
  from pathlib import Path
  from unittest.mock import MagicMock
  import matplotlib.pyplot
  import rich
  import torch.nn
  from mmengine.config import Config, DictAction
  from mmengine.hooks import Hook
  from mmengine.model import BaseModel
  from mmengine.registry import init_default_scope
  from mmengine.runner import Runner
  from mmengine.visualization import Visualizer
  from rich.progress import BarColumn, MofNCompleteColumn, Progress, TextColumn
  from mmocr.registry import DATASETS
label_desc: Use image node_id 5 for calling a global function with example usage: main() without return types