code: def handle_metrics(split, metrics, output_dir):
      """
      Log and save metrics
  
      Args:
      - split: one of train, val, test
      - metrics: metrics dict
      - output_dir: where to save the metrics
      """
  
      logger.info(f"***** {split} metrics *****")
      for key in sorted(metrics.keys()):
          logger.info(f"  {key} = {metrics[key]}")
      save_json(
          metrics, os.path.join(output_dir, f"{split}_results.json")
      )
  
file_path: transformers/examples/legacy/seq2seq/finetune_trainer.py
imports: import logging
  import os
  import sys
  from dataclasses import dataclass, field
  from typing import Optional
  from seq2seq_trainer import Seq2SeqTrainer
  from seq2seq_training_args import Seq2SeqTrainingArguments
  import transformers
  from transformers import AutoConfig, AutoModelForSeq2SeqLM, AutoTokenizer, HfArgumentParser, MBartTokenizer, MBartTokenizerFast, set_seed
  from transformers.trainer_utils import EvaluationStrategy, is_main_process
  from transformers.training_args import ParallelMode
  from utils import Seq2SeqDataCollator, Seq2SeqDataset, assert_all_frozen, build_compute_metrics_fn, check_output_dir, freeze_embeds, freeze_params, lmap, save_json, use_task_specific_params, write_txt_file
label_desc: Use image node_id 1 for calling a global function with example usage: handle_metrics(split, metrics, output_dir) without return types