Skip to content

Commit 3f9eaba

Browse files
authored
Merge pull request freqtrade#12979 from freqtrade/fix/freqai_torch
Fix freqai torch model loading
2 parents fd858b7 + d557b4b commit 3f9eaba

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

docs/freqai-configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ freqtrade trade --config config_examples/config_freqai.example.json --strategy F
260260

261261
PyTorch dropped support for macOS x64 (intel based Apple devices) in version 2.3. Subsequently, freqtrade also dropped support for PyTorch on this platform.
262262

263+
!!! Danger "Security notice"
264+
Loading saved models from disk can cause security issues if using remote model files (files you downloaded from the internet or received from an untrusted source) due to having the necessity to have `weights_only=False`, which can cause security problems.
265+
As long as you only load models that you have trained yourself, there is no risk.
266+
263267
### Structure
264268

265269
#### Model

docs/freqai-running.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ To save the models generated during a particular backtest so that you can start
8787
To ensure that the model can be reused, freqAI will call your strategy with a dataframe of length 1.
8888
If your strategy requires more data than this to generate the same features, you can't reuse backtest predictions for live deployment and need to update your `identifier` for each new backtest.
8989

90+
!!! Danger "Security notice"
91+
Loading saved models from disk can cause security issues if using remote model files (files you downloaded from the internet or received from an untrusted source) due to having the necessity to have `weights_only=False`, which can cause security problems.
92+
As long as you only load models that you have trained yourself, there is no risk.
93+
9094
### Backtest live collected predictions
9195

9296
FreqAI allow you to reuse live historic predictions through the backtest parameter `--freqai-backtest-live-models`. This can be useful when you want to reuse predictions generated in dry/run for comparison or other study.

freqtrade/freqai/data_drawer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,13 @@ def load_data(self, coin: str, dk: FreqaiDataKitchen) -> Any:
614614
elif self.model_type == "pytorch":
615615
import torch
616616

617-
zipfile = torch.load(dk.data_path / f"{dk.model_filename}_model.zip")
618-
model = zipfile["pytrainer"]
619-
model = model.load_from_checkpoint(zipfile)
617+
zipfile = torch.load(
618+
dk.data_path / f"{dk.model_filename}_model.zip",
619+
weights_only=False,
620+
)
621+
# weights_only is necessary due to pytrainer being a serialized python object.
622+
_trainer = zipfile["pytrainer"]
623+
model = _trainer.load_from_checkpoint(zipfile)
620624

621625
if not model:
622626
raise OperationalException(

0 commit comments

Comments
 (0)