class_docstr: Dump training metrics to file.
class_docstr_tok: ["Dump","training","metrics","to","file","."]
code: def __init__(self, dirpath: Path) -> None:
      self.dirpath = dirpath
      self.dirpath.mkdir(exist_ok=True, parents=True)
      self.train_records: List[dict] = []
      self.valid_records: List[dict] = []
  
imports: from __future__ import annotations
  import copy
  import os
  import shutil
  import time
  from datetime import datetime
  from pathlib import Path
  from typing import Any, List, TYPE_CHECKING
  import numpy
  import pandas
  import torch
  from qlib.log import get_module_logger
  from qlib.typehint import Literal
label_desc: Use image node_id 1 to create a new MetricsWriter object from inherited base classes: Callback with example: obj = MetricsWriter(dirpath)