gsyyysg / StockFormer

PyTorch implementation for Paper "StockFormer: Learning Hybrid Trading Machines with Predictive Coding".
219 stars 54 forks source link

强化学习阶段加载模型报错“Fail to load agent!”,是因为内存不够还是需要修改代码啊? #18

Open yo-yoo opened 1 month ago

yo-yoo commented 1 month ago

/content/gdrive/MyDrive/Colab/StockFormer-main/code/stable_baselines3/common/save_util.py:166: UserWarning: Could not deserialize object action_space. Consider using custom_objects argument to replace this object. warnings.warn( Successfully initialize transformer model... /content/gdrive/MyDrive/Colab/StockFormer-main/code/stable_baselines3/common/buffers.py:219: UserWarning: This system does not have apparently enough memory to store the complete replay buffer 37.28GB > 1.61GB warnings.warn( Traceback (most recent call last): File "/content/gdrive/MyDrive/Colab/StockFormer-main/code/MySAC/models/DRLAgent.py", line 185, in DRL_prediction_load_from_file model = MODELS[model_name].load(cwd) File "/content/gdrive/MyDrive/Colab/StockFormer-main/code/stable_baselines3/common/base_class.py", line 721, in load model.set_parameters(params, exact_match=True, device=device) File "/content/gdrive/MyDrive/Colab/StockFormer-main/code/stable_baselines3/common/base_class.py", line 630, in set_parameters attr.load_state_dict(params[name], strict=exact_match) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 2189, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for SACPolicy: size mismatch for actor.mu.weight: copying a param with shape torch.Size([88, 256]) from checkpoint, the shape in current model is torch.Size([31064, 256]). size mismatch for actor.mu.bias: copying a param with shape torch.Size([88]) from checkpoint, the shape in current model is torch.Size([31064]). size mismatch for actor.log_std.weight: copying a param with shape torch.Size([88, 256]) from checkpoint, the shape in current model is torch.Size([31064, 256]). size mismatch for actor.log_std.bias: copying a param with shape torch.Size([88]) from checkpoint, the shape in current model is torch.Size([31064]). size mismatch for critic.qf0.0.weight: copying a param with shape torch.Size([256, 11440]) from checkpoint, the shape in current model is torch.Size([256, 42416]). size mismatch for critic.qf1.0.weight: copying a param with shape torch.Size([256, 11440]) from checkpoint, the shape in current model is torch.Size([256, 42416]). size mismatch for critic_target.qf0.0.weight: copying a param with shape torch.Size([256, 11440]) from checkpoint, the shape in current model is torch.Size([256, 42416]). size mismatch for critic_target.qf1.0.weight: copying a param with shape torch.Size([256, 11440]) from checkpoint, the shape in current model is torch.Size([256, 42416]).

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/content/gdrive/MyDrive/Colab/StockFormer-main/code/train_rl.py", line 224, in results = DRLAgent.DRL_prediction_load_from_file(model_name='maesac',environment=test_trade_gym, cwd=model_path) File "/content/gdrive/MyDrive/Colab/StockFormer-main/code/MySAC/models/DRLAgent.py", line 188, in DRL_prediction_load_from_file raise ValueError("Fail to load agent!") ValueError: Fail to load agent!