You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BUG] Re-training DetectorEnsemble with TSADEvaluator does not ensure 'train_config' to be DetectorEnsembleTrainConfig: 'dict' object has no attribute 'valid_frac'
#175
Open
AtanasGruev opened this issue
Nov 14, 2024
· 1 comment
Describe the bug
Simulating live model deployment of the standard multivariate model DefaultDetector (i.e. DetectorEnsemble of VAE and RRCF) by means of the TSADEvaluator leads to periodic re-training. Initially, TSADEvaluator's default_retrain_kwargs() method ensures that train_config for training the DetectorEnsemble is an instance of DetectorEnsembleTrainConfig. However, after passing down re-training from DetectorEnsemble to the individual models, no care is taken to ensure that the train_config for the DefaultDetector will be an instance of the same class. Instead, train_config for training the DetectorEnsemble that is the DefaultDetector is of type dict which leads to the bug reported.
Most likely this is related to TSADEvaluator mismatch between full_train_kwargs and full_retrain_kwargs, as the lines
merlion.evaluate.anomaly.TSADEvaluator's get_predict() invokes merlion.evaluate.base.EvaluatorBase's get_predict(). The latter contains the re-training logic.
When re-training is initiated, self.model is an instance of merlion.models.ensemble.anomaly.DetectorEnsemble. Consequently, EvaluatorBase's _train_model() invokes DetectorEnsemble's train().
merlion.models.ensemble.anomaly.DetectorEnsemble inherits from merlion.models.ensemble.base.EnsembleBase and merlion.models.anomaly.base.DetectorBase. Only the latter has a train() method. Therefore, DetectorEnsemble's train() actually calls DetectorBase's train().
Using call_with_accepted_kwargs, DetectorBase's train() invokes DetectorEnsemble's _train().
which is responsible for re-training the first ensemble model which is an instance of merlion.models.defaults.DefaultDetector. At this moment, train_kwargs['train_config'] is of type dict. Effectively, TSADEvaluator's get_predict() invokes EvaluatorBase's get_predict().
EvaluatorBases get_predict() invokes EvaluatorBase's_train_model(). The latter invokes merlion.models.defaults.DefaultDetector's train(). At this moment, train_config is of type dict.
self.model is set to be a DetectorEnsemble of VAE and RRCF, and DefaultDetector's train() invokes LayeredDetector's train(). merlion.models.layers.LayeredDetector inherits from merlion.models.layers.LayeredModel and merlion.models.anomaly.base.DetectorBase. Only the latter has a train() method. Therefore, LayeredDetector's train() invokes DetectorBase's train(). At this moment, train_config is of type dict.
Using call_with_accepted_kwargs, DetectorBase's train() invokes DetectorEnsemble's _train().
train_config is required to be an instance of DetectorEnsembleTrainConfig. We see that this is not the case. The error occurs.
The text was updated successfully, but these errors were encountered:
Describe the bug
Simulating live model deployment of the standard multivariate model
DefaultDetector
(i.e.DetectorEnsemble
of VAE and RRCF) by means of theTSADEvaluator
leads to periodic re-training. Initially,TSADEvaluator
'sdefault_retrain_kwargs()
method ensures thattrain_config
for training theDetectorEnsemble
is an instance ofDetectorEnsembleTrainConfig
. However, after passing down re-training fromDetectorEnsemble
to the individual models, no care is taken to ensure that thetrain_config
for theDefaultDetector
will be an instance of the same class. Instead,train_config
for training theDetectorEnsemble
that is theDefaultDetector
is of typedict
which leads to the bug reported.Most likely this is related to
TSADEvaluator
mismatch betweenfull_train_kwargs
andfull_retrain_kwargs
, as the linesMerlion/merlion/evaluate/base.py
Lines 191 to 192 in 085ef8a
do not ensure that
Merlion/merlion/evaluate/base.py
Line 202 in 085ef8a
train_config
.To Reproduce
Bug has been identified by going over the tutorial on "Multivariate Time Series Anomaly Detection" for Merlion v2.0.2, section "Model Inference and Quantitative Evaluation" (see https://opensource.salesforce.com/Merlion/v2.0.2/tutorials/anomaly/2_AnomalyMultivariate.html#Model-Inference-and-Quantitative-Evaluation). When performing "Sliding Window Evaluation" with
TSADEvaluator
, the ensemble fails at re-training theDefaultDetector
model due to the bug reported.Expected behavior
Successful re-training of the
DefaultDetector
model as part ofDetectorEnsemble
models when usingTSADEvaluator
.Screenshots
A screenshot of the resulting error stack trace is attached.
Desktop
Additional context
At the re-train trigger
Merlion/merlion/evaluate/base.py
Line 230 in 085ef8a
merlion.evaluate.anomaly.TSADEvaluator
'sget_predict()
invokesmerlion.evaluate.base.EvaluatorBase
'sget_predict()
. The latter contains the re-training logic.self.model
is an instance ofmerlion.models.ensemble.anomaly.DetectorEnsemble
. Consequently,EvaluatorBase
's_train_model()
invokesDetectorEnsemble
'strain()
.merlion.models.ensemble.anomaly.DetectorEnsemble
inherits frommerlion.models.ensemble.base.EnsembleBase
andmerlion.models.anomaly.base.DetectorBase
. Only the latter has atrain()
method. Therefore,DetectorEnsemble
'strain()
actually callsDetectorBase
'strain()
.call_with_accepted_kwargs
,DetectorBase
'strain()
invokesDetectorEnsemble
's_train()
.Merlion/merlion/models/ensemble/anomaly.py
Line 139 in 085ef8a
train_cfgs
becomesList[dict]
.TSADEvaluator
'sget_predict()
is invoked at the first iteration ofMerlion/merlion/models/ensemble/anomaly.py
Lines 159 to 164 in 085ef8a
merlion.models.defaults.DefaultDetector
. At this moment,train_kwargs['train_config']
is of typedict
. Effectively,TSADEvaluator
'sget_predict()
invokesEvaluatorBase
'sget_predict()
.EvaluatorBase
sget_predict()
invokesEvaluatorBase's
_train_model()
. The latter invokesmerlion.models.defaults.DefaultDetector
'strain()
. At this moment,train_config
is of typedict
.self.model
is set to be aDetectorEnsemble
of VAE and RRCF, andDefaultDetector
'strain()
invokesLayeredDetector
'strain()
.merlion.models.layers.LayeredDetector
inherits frommerlion.models.layers.LayeredModel
andmerlion.models.anomaly.base.DetectorBase
. Only the latter has atrain()
method. Therefore,LayeredDetector
'strain()
invokesDetectorBase
'strain()
. At this moment,train_config
is of typedict
.call_with_accepted_kwargs
,DetectorBase
'strain()
invokesDetectorEnsemble
's_train()
.train_config
is required to be an instance ofDetectorEnsembleTrainConfig
. We see that this is not the case. The error occurs.The text was updated successfully, but these errors were encountered: