class_docstr: Stores a constituency model and its optimizer
class_docstr_tok: ["Stores","a","constituency","model","and","its","optimizer"]
docstr: save the current model, optimizer, and other state to filename
  
  epochs_trained can be passed as a parameter to handle saving at the end of an epoch
docstr_tok: ["save","the","current","model",",","optimizer",",","and","other","state","to","filename","epochs_trained","can","be","passed","as","a","parameter","to","handle","saving","at","the","end","of","an","epoch"]
code: def save(
      self,
      filename,
      epochs_trained=None,
      skip_modules=True,
      save_optimizer=True,
  ):
      """
      save the current model, optimizer, and other state to filename
  
      epochs_trained can be passed as a parameter to handle saving at the end of an epoch
      """
      if epochs_trained is None:
          epochs_trained = self.epochs_trained
      save_dir = os.path.split(filename)[0]
      os.makedirs(save_dir, exist_ok=True)
      model_params = self.model.get_params(skip_modules)
      params = {
          "params": model_params,
          "epochs_trained": epochs_trained,
          "global_step": self.global_step,
          "best_score": self.best_score,
      }
      if save_optimizer and self.optimizer is not None:
          params["optimizer_state_dict"] = self.optimizer.state_dict()
      torch.save(params, filename, _use_new_zipfile_serialization=False)
      logger.info("Model saved to {}".format(filename))
  
file_path: stanza/stanza/models/classifiers/trainer.py
imports: import logging
  import os
  import torch
  import torch.optim
  import stanza.models.classifiers.data
  import stanza.models.classifiers.cnn_classifier
  import stanza.models.classifiers.constituency_classifier
  from stanza.models.classifiers.utils import ModelType
  from stanza.models.common.foundation_cache import load_bert, load_charlm, load_pretrain
  from stanza.models.common.pretrain import Pretrain
  from stanza.models.constituency.tree_embedding import TreeEmbedding
label_desc: Use image node_id 2 for calling the Trainer obj's underlying member method code with example usage: obj.save(filename, epochs_trained, skip_modules, save_optimizer) without return types