code: def save_file(data, filename, append_to_json=True, verbose=True):
      """
      Common i/o utility to handle saving data to various file formats.
      Supported:
          .pkl, .pickle, .npy, .json
      Specifically for .json, users have the option to either append (default)
      or rewrite by passing in Boolean value to append_to_json.
      """
      if verbose:
          logging.info(f"Saving data to file: {filename}")
      file_ext = os.path.splitext(filename)[1]
      if file_ext in [".pkl", ".pickle"]:
          with g_pathmgr.open(filename, "wb") as fopen:
              pickle.dump(data, fopen, pickle.HIGHEST_PROTOCOL)
      elif file_ext == ".npy":
          with g_pathmgr.open(filename, "wb") as fopen:
              np.save(fopen, data)
      elif file_ext == ".json":
          if append_to_json:
              with g_pathmgr.open(filename, "a") as fopen:
                  fopen.write(json.dumps(data, sort_keys=True) + "\n")
                  fopen.flush()
          else:
              with g_pathmgr.open(filename, "w") as fopen:
                  fopen.write(json.dumps(data, sort_keys=True) + "\n")
                  fopen.flush()
      elif file_ext == ".yaml":
          with g_pathmgr.open(filename, "w") as fopen:
              dump = yaml.dump(data)
              fopen.write(dump)
              fopen.flush()
      else:
          raise Exception(f"Saving {file_ext} is not supported yet")
  
      if verbose:
          logging.info(f"Saved data to file: {filename}")
  
imports: import json
  import logging
  import os
  import pickle
  import re
  import shutil
  import time
  from urllib.parse import urlparse
  import numpy
  import pandas
  import yaml
  from iopath.common.download import download
  from iopath.common.file_io import file_lock, g_pathmgr
  from vissl.utils.slurm import get_slurm_dir
label_desc: Use image node_id 3 for calling a global function with example usage: save_file(data, filename, append_to_json, verbose) without return types