code: def _torch_snapshot_object(trainer, target, filename, savefun):
      from chainer.serializers import DictionarySerializer
  
      # make snapshot_dict dictionary
      s = DictionarySerializer()
      s.save(trainer)
      if hasattr(trainer.updater.model, "model"):
          # (for TTS)
          if hasattr(trainer.updater.model.model, "module"):
              model_state_dict = (
                  trainer.updater.model.model.module.state_dict()
              )
          else:
              model_state_dict = (
                  trainer.updater.model.model.state_dict()
              )
      else:
          # (for ASR)
          if hasattr(trainer.updater.model, "module"):
              model_state_dict = (
                  trainer.updater.model.module.state_dict()
              )
          else:
              model_state_dict = trainer.updater.model.state_dict()
      snapshot_dict = {
          "trainer": s.target,
          "model": model_state_dict,
          "optimizer": trainer.updater.get_optimizer(
              "main"
          ).state_dict(),
      }
  
      # save snapshot dictionary
      fn = filename.format(trainer)
      prefix = "tmp" + fn
      tmpdir = tempfile.mkdtemp(prefix=prefix, dir=trainer.out)
      tmppath = os.path.join(tmpdir, fn)
      try:
          savefun(snapshot_dict, tmppath)
          shutil.move(tmppath, os.path.join(trainer.out, fn))
      finally:
          shutil.rmtree(tmpdir)
  
imports: import argparse
  import copy
  import json
  import logging
  import os
  import shutil
  import tempfile
  import numpy
  import torch
label_desc: Use image node_id 8 for calling a global function with example usage: _torch_snapshot_object(trainer, target, filename, savefun) without return types