class_docstr: Abstract class implementing a model which wraps around another internal model.
  
  The actual underlying model is stored in ``model.config.model``, and ``model.model`` is a property which references
  this. This is to allow the model to retain the initializer ``LayeredModel(config)``, and to ensure that various
  attributes do not become de-synchronized (e.g. if we were to store ``config.model_config`` and ``model.model``
  separately).
  
  We define the *base model* as the non-layered model at the base of the overall model hierarchy.
  
  The layered model is allowed to access any callable attribute of the base model,
  e.g. ``model.set_seasonality(...)`` resolves to ``model.base_model.set_seasonality(...)`` for a `SeasonalityModel`.
  If the base model is a forecaster, the layered model will automatically inherit from `ForecasterBase`; similarly
  for `DetectorBase` or `ForecastingDetectorBase`. The abstract methods (``forecast`` and ``get_anomaly_score``)
  are overridden to call the underlying model.
  
  If the base model is a forecaster, the top-level config ``model.config`` does not duplicate attributes of the
  underlying forecaster config (e.g. ``max_forecast_steps`` or ``target_seq_index``). Instead,
  ``model.config.max_forecast_steps`` will resolve to ``model.config.base_model.max_forecast_steps``.
  As a result, you will only need to specify this parameter once. The same holds true for `DetectorConfig` attributes
  (e.g. ``threshold`` or ``calibrator``) when the base model is an anomaly detector.
  
  .. note::
  
      For the time being, every layer of the model is allowed to have its own ``transform``. However, after the
      model is trained, the entire transform will be composed as a single `TransformSequence` and will be owned by
      the base model.
class_docstr_tok: ["Abstract","class","implementing","a","model","which","wraps","around","another","internal","model",".","The","actual","underlying","model","is","stored","in","``","model.config.model","``",",","and","``","model.model","``","is","a","property","which","references","this",".","This","is","to","allow","the","model","to","retain","the","initializer","``","LayeredModel","(","config",")","``",",","and","to","ensure","that","various","attributes","do","not","become","de-synchronized","(","e.g",".","if","we","were","to","store","``","config.model_config","``","and","``","model.model","``","separately",")",".","We","define","the","*","base","model","*","as","the","non-layered","model","at","the","base","of","the","overall","model","hierarchy",".","The","layered","model","is","allowed","to","access","any","callable","attribute","of","the","base","model",",","e.g",".","``","model.set_seasonality","(","...",")","``","resolves","to","``","model.base_model.set_seasonality","(","...",")","``","for","a","`","SeasonalityModel","`",".","If","the","base","model","is","a","forecaster",",","the","layered","model","will","automatically","inherit","from","`","ForecasterBase","`",";","similarly","for","`","DetectorBase","`","or","`","ForecastingDetectorBase","`",".","The","abstract","methods","(","``","forecast","``","and","``","get_anomaly_score","``",")","are","overridden","to","call","the","underlying","model",".","If","the","base","model","is","a","forecaster",",","the","top-level","config","``","model.config","``","does","not","duplicate","attributes","of","the","underlying","forecaster","config","(","e.g",".","``","max_forecast_steps","``","or","``","target_seq_index","``",")",".","Instead",",","``","model.config.max_forecast_steps","``","will","resolve","to","``","model.config.base_model.max_forecast_steps","``",".","As","a","result",",","you","will","only","need","to","specify","this","parameter","once",".","The","same","holds","true","for","`","DetectorConfig","`","attributes","(","e.g",".","``","threshold","``","or","``","calibrator","``",")","when","the","base","model","is","an","anomaly","detector",".","..","note",":",":","For","the","time","being",",","every","layer","of","the","model","is","allowed","to","have","its","own","``","transform","``",".","However",",","after","the","model","is","trained",",","the","entire","transform","will","be","composed","as","a","single","`","TransformSequence","`","and","will","be","owned","by","the","base","model","."]
code: def _save_state(
      self,
      state_dict: Dict[str, Any],
      filename: str = None,
      **save_config,
  ) -> Dict[str, Any]:
      state_dict.pop(
          "config", None
      )  # don't save the model's config in binary
      if self.model is not None:
          state_dict["model"] = self.model._save_state(
              state_dict["model"], filename=None, **save_config
          )
      return super()._save_state(state_dict, filename, **save_config)
  
imports: import copy
  import inspect
  import logging
  from typing import Any, Dict, List, Union
  import pandas
  from merlion.models.base import Config, ModelBase
  from merlion.models.factory import ModelFactory
  from merlion.models.anomaly.base import DetectorBase, DetectorConfig
  from merlion.models.forecast.base import ForecasterBase, ForecasterConfig, ForecasterExogBase, ForecasterExogConfig
  from merlion.models.anomaly.forecast_based.base import ForecastingDetectorBase
  from merlion.transform.base import Identity
  from merlion.transform.resample import TemporalResample
  from merlion.transform.sequence import TransformSequence
  from merlion.utils import TimeSeries
  from merlion.utils.misc import AutodocABCMeta, call_with_accepted_kwargs
label_desc: Use image node_id 17 for calling the LayeredModel obj's underlying member method code with example usage: obj._save_state(state_dict, filename) and returns: super