microsoft / qlib

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.
https://qlib.readthedocs.io/en/latest/
MIT License
15.27k stars 2.61k forks source link

MetaModelInc module offline training should call eval for validation predict. #1722

Open caolongjie1101 opened 9 months ago

caolongjie1101 commented 9 months ago

🐛 Bug Description

To Reproduce

Steps to reproduce the behavior:

  1. create any module with bn or dropout layer
  2. run offline training
  3. inloop training missed model.eval(), caused batch normalization or dropout layer cannot work as predict model.

Expected Behavior

prediction should not dropout any value or using dynamic batch mean and var for batch normalization. The run_task function should be modified from :

def run_task(self, meta_input, phase): """ A single naive incremental learning task """ ......... with torch.no_grad(): pred = self.framework(meta_input["X_test"].to(self.framework.device), None) return pred.detach().cpu().numpy() to def run_task(self, meta_input, phase): """ A single naive incremental learning task """ ......... with torch.no_grad(): self.framework.eval() pred = self.framework(meta_input["X_test"].to(self.framework.device), None) return pred.detach().cpu().numpy()

SarthakNikhal commented 8 months ago

@you-n-g can I work on this issue?

USTCKevinF commented 7 months ago

We have checked out the snippet in qlib-main\qlib\contrib\meta\data_selection\model.py and we add self.tn.eval() in validation phase(line 73). Can you specify your question? Where did you find this problem