code: def save_checkpoint(
      f: io.IOBase,
      config: PyTextConfig,
      model: Model,
      meta: Optional[CommonMetadata],
      tensorizers: Dict[str, Tensorizer],
      training_state: Optional[TrainingState] = None,
  ) -> str:
      # Currently torch.save() has error pickling certain models when not saving
      # by model.state_dict(), thus currently overriding the model in
      # training_state with None, and put back saving
      # https://github.com/pytorch/pytorch/issues/15116
      model_in_training_state = None
      if training_state:
          model_in_training_state, training_state.model = (
              training_state.model,
              None,
          )
      try:
          state = {
              DATA_STATE: meta,
              CONFIG_JSON: config_to_json(PyTextConfig, config),
              MODEL_STATE: model.state_dict(),
              SERIALIZE_VERSION_KEY: LATEST_SERIALIZE_VERSION,
              TENSORIZERS: tensorizers,
              TRAINING_STATE: training_state,
          }
          torch.save(state, f)
      finally:
          if training_state:
              training_state.model = model_in_training_state
  
imports: import io
  import logging
  import os
  from typing import Dict, Optional
  import torch
  from pytext.config import config_to_json, pytext_config_from_json, PyTextConfig
  from pytext.data import CommonMetadata
  from pytext.data.tensorizers import Tensorizer
  from pytext.models import Model
  from pytext.trainers.training_state import TrainingState
  from pytext.utils.file_io import PathManager
  from .pytext_checkpoint_management import get_checkpoint_manager
label_desc: Use image node_id 6 for calling a global function with example usage: save_checkpoint(f, config, model, meta, tensorizers, training_state) without return types