-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Update data_drawer.py fix weights_only bug #12017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Fix the bug: ``` _pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. (1) In PyTorch 2.6, we changed the default value of the weights_only argument in torch.load from False to True. Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source. (2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message. WeightsUnpickler error: Unsupported global: GLOBAL freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer was not an allowed global by default. Please use torch.serialization.add_safe_globals([freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer]) or the torch.serialization.safe_globals([freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer]) context manager to allowlist this global if you trust this class/function. Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html. ```
import torch | ||
|
||
zipfile = torch.load(dk.data_path / f"{dk.model_filename}_model.zip") | ||
zipfile = torch.load(dk.data_path / f"{dk.model_filename}_model.zip", weights_only=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well based on your description and the warning from pytorch - i'm not entirely sure if we explicitly want to enable this by default (it should at least be given a good thought).
When does this error happen?
when you try to load a model written with an older pytorch version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to run backtest after run hyperopt success, load old model error happen:
025-07-22 21:53:03,531 - XxxFinalV10 - INFO - 🔍 Total features before model training: 168
2025-07-22 21:53:07,060 - freqtrade.freqai.freqai_interface - INFO - Found model at /opt/raid0/ft/gpu002/user_data/models/torch-v10-67/sub-train-DOGE_1751155200/cb_doge_1751155200
2025-07-22 21:53:07,217 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/raid0/ft/freqtrade/freqtrade/main.py", line 47, in main
return_code = args["func"](https://github.com/xxx/xxx/issues/args)
^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/commands/optimize_commands.py", line 61, in start_backtesting
backtesting.start()
File "/opt/raid0/ft/freqtrade/freqtrade/optimize/backtesting.py", line 1820, in start
min_date, max_date = self.backtest_one_strategy(strat, data, timerange)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/optimize/backtesting.py", line 1730, in backtest_one_strategy
preprocessed = self.strategy.advise_all_indicators(data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/strategy/interface.py", line 1748, in advise_all_indicators
res[pair] = self.advise_indicators(pair_data.copy(), {"pair": pair}).copy()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/strategy/interface.py", line 1803, in advise_indicators
dataframe = self.populate_indicators(dataframe, metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/gpu002/user_data/strategies/XxxFinalV10.py", line 309, in populate_indicators
dataframe = self.freqai.start(dataframe, metadata, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/freqai/freqai_interface.py", line 161, in start
dk = self.start_backtesting(dataframe, metadata, self.dk, strategy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/raid0/ft/freqtrade/freqtrade/freqai/freqai_interface.py", line 390, in start_backtesting
self.model = self.dd.load_data(pair, dk)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/miniconda3/envs/freqtrade/lib/python3.12/site-packages/torch/serialization.py", line 1524, in load
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
(1) In PyTorch 2.6, we changed the default value of the weights_only argument in torch.load from False to True. Re-running torch.load with weights_only set to False will likely
succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message.
WeightsUnpickler error: Unsupported global: GLOBAL freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer was not an allowed global by default. Please use
torch.serialization.add_safe_globals([freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer]) or the
torch.serialization.safe_globals([freqtrade.freqai.torch.PyTorchModelTrainer.PyTorchLSTMTrainer]) context manager to allowlist this global if you trust this class/function.
Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.
File "/opt/raid0/ft/freqtrade/freqtrade/freqai/data_drawer.py", line 617, in load_data
zipfile = torch.load(dk.data_path / f"{dk.model_filename}_model.zip")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/miniconda3/envs/freqtrade/lib/python3.12/site-packages/torch/serialization.py", line 1524, in load
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
You seem to be using custom ft code and models. please reproduce with one of the built in PyTorch models, and with the packaged version of ft. thanks! |
@coffeecloudgit I solved this by adding this to the end of
An this to the end of
|
Fix the bug:
Summary
Solve the issue: #___
Quick changelog
What's new?