From e0deec2e5443e4cc2c85f5ff462e8c27c047b1f0 Mon Sep 17 00:00:00 2001 From: Ole Petersen <56505957+peteole@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:23:35 +0200 Subject: [PATCH 1/3] Fix memory leak in base_class.py Loading the data return value is not necessary since it is unused. Loading the data causes a memory leak through the ep_info_buffer variable. I found this while loading a PPO learner from storage on a multi-GPU system since the ep_info_buffer is loaded to the memory location it was on while it was saved to disk, instead of the target loading location, and is then not cleaned up. --- stable_baselines3/common/base_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable_baselines3/common/base_class.py b/stable_baselines3/common/base_class.py index e6c7d3cfc..ac4258648 100644 --- a/stable_baselines3/common/base_class.py +++ b/stable_baselines3/common/base_class.py @@ -592,7 +592,7 @@ def set_parameters( if isinstance(load_path_or_dict, dict): params = load_path_or_dict else: - _, params, _ = load_from_zip_file(load_path_or_dict, device=device) + _, params, _ = load_from_zip_file(load_path_or_dict, device=device, load_data=False) # Keep track which objects were updated. # `_get_torch_save_params` returns [params, other_pytorch_variables]. From 57e3f107074baae137a5a327cfef9035a3070a10 Mon Sep 17 00:00:00 2001 From: Ole Petersen <56505957+peteole@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:29:24 +0200 Subject: [PATCH 2/3] Update changelog.rst --- docs/misc/changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index db065ee4a..e46f04cb0 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -8,6 +8,7 @@ Release 2.3.1 (2024-04-22) Bug Fixes: ^^^^^^^^^^ +- Fix memory leak when loading learner from storage (@peteole) - Cast return value of learning rate schedule to float, to avoid issue when loading model because of ``weights_only=True`` (@markscsmith) Documentation: @@ -1606,4 +1607,4 @@ And all the contributors: @anand-bala @hughperkins @sidney-tio @AlexPasqua @dominicgkerr @Akhilez @Rocamonde @tobirohrer @ZikangXiong @ReHoss @DavyMorgan @luizapozzobon @Bonifatius94 @theSquaredError @harveybellini @DavyMorgan @FieteO @jonasreiher @npit @WeberSamuel @troiganto @lutogniew @lbergmann1 @lukashass @BertrandDecoster @pseudo-rnd-thoughts @stefanbschneider @kyle-he @PatrickHelm @corentinlger -@marekm4 @stagoverflow @rushitnshah @markscsmith +@marekm4 @stagoverflow @rushitnshah @markscsmith @peteole From 5eff0abcaa6a178ab658730d924fbf8daa14315e Mon Sep 17 00:00:00 2001 From: Antonin Raffin Date: Wed, 15 May 2024 15:44:00 +0200 Subject: [PATCH 3/3] Update changelog --- docs/misc/changelog.rst | 7 ++++--- stable_baselines3/version.txt | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index 977f03815..d77388534 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -3,7 +3,7 @@ Changelog ========== -Release 2.4.0a0 (WIP) +Release 2.4.0a1 (WIP) -------------------------- Breaking Changes: @@ -14,7 +14,8 @@ New Features: Bug Fixes: ^^^^^^^^^^ -- Fix memory leak when loading learner from storage (@peteole) +- Fixed memory leak when loading learner from storage, ``set_parameters()`` does not try to load the object data anymore + and only loads the PyTorch parameters (@peteole) - Cast type in compute gae method to avoid error when using torch compile (@amjames) `SB3-Contrib`_ @@ -31,7 +32,7 @@ Deprecations: Others: ^^^^^^^ -- Fix various typos (@cschindlbeck) +- Fixed various typos (@cschindlbeck) Bug Fixes: ^^^^^^^^^^ diff --git a/stable_baselines3/version.txt b/stable_baselines3/version.txt index e96f44fb3..48adc0106 100644 --- a/stable_baselines3/version.txt +++ b/stable_baselines3/version.txt @@ -1 +1 @@ -2.4.0a0 +2.4.0a1