class_docstr: An abstract class representing an ensemble of multiple models.
class_docstr_tok: ["An","abstract","class","representing","an","ensemble","of","multiple","models","."]
docstr: Saves the model's state to the the specified file, or just modifies the state_dict as needed.
  
  :param state_dict: The state dict to save.
  :param filename: The name of the file to save the model to.
  :param save_only_used_models: whether to save only the models that are actually used by the ensemble.
  :param save_config: additional configurations (if needed)
  :return: The state dict to save.
docstr_tok: ["Saves","the","model","'s","state","to","the","the","specified","file",",","or","just","modifies","the","state_dict","as","needed",".",":","param","state_dict",":","The","state","dict","to","save",".",":","param","filename",":","The","name","of","the","file","to","save","the","model","to",".",":","param","save_only_used_models",":","whether","to","save","only","the","models","that","are","actually","used","by","the","ensemble",".",":","param","save_config",":","additional","configurations","(","if","needed",")",":","return",":","The","state","dict","to","save","."]
code: def _save_state(
      self,
      state_dict: Dict[str, Any],
      filename: str = None,
      save_only_used_models=False,
      **save_config,
  ) -> Dict[str, Any]:
      """
      Saves the model's state to the the specified file, or just modifies the state_dict as needed.
  
      :param state_dict: The state dict to save.
      :param filename: The name of the file to save the model to.
      :param save_only_used_models: whether to save only the models that are actually used by the ensemble.
      :param save_config: additional configurations (if needed)
      :return: The state dict to save.
      """
      state_dict.pop(
          "config", None
      )  # don't save the model's config in binary
      if self.models is not None:
          model_states = []
          for model, model_state, model_used in zip(
              self.models, state_dict["models"], self.models_used
          ):
              if save_only_used_models and not model_used:
                  model_states.append(None)
              else:
                  model_states.append(
                      model._save_state(
                          model_state,
                          None,
                          save_only_used_models=save_only_used_models,
                          **save_config,
                      )
                  )
          state_dict["models"] = model_states
      return super()._save_state(state_dict, filename, **save_config)
  
imports: import copy
  import logging
  from typing import Any, Dict, List, Tuple, Union
  import numpy
  import pandas
  from merlion.models.base import ModelBase, Config
  from merlion.models.ensemble.combine import CombinerBase, CombinerFactory, Mean
  from merlion.models.factory import ModelFactory
  from merlion.utils import TimeSeries
  from merlion.utils.misc import AutodocABCMeta
  from merlion.utils.resample import to_offset
label_desc: Use image node_id 14 for calling the EnsembleBase obj's underlying member method code with example usage: obj._save_state(state_dict, filename, save_only_used_models) and returns: super