code: def save_model_with_metadata(
      model_or_state_dict: Union[nn.Module, dict],
      output_dir: str,
      file_name="model",
      metadata: Optional[dict] = None,
  ):
      if isinstance(model_or_state_dict, dict):
          state_dict = model_or_state_dict
      else:
          state_dict = torch_utils.get_model_for_saving(
              model_or_state_dict
          ).state_dict()
  
      torch.save(state_dict, os.path.join(output_dir, f"{file_name}.p"))
      if metadata is not None:
          py_io.write_json(
              metadata,
              os.path.join(output_dir, f"{file_name}.metadata.json"),
          )
  
file_path: jiant/jiant/shared/runner.py
imports: import os
  from typing import Union, Optional
  import torch
  import torch.nn
  import jiant.shared.caching
  import jiant.utils.python.io
  import jiant.utils.torch_utils
label_desc: Use image node_id 4 for calling a global function with example usage: save_model_with_metadata(model_or_state_dict, output_dir, file_name, metadata) without return types