Skip to content

Commit 9f979b5

Browse files
awaelchliYifu Wangjustusschockpre-commit-ci[bot]carmocca
authored andcommitted
Clear predict_progress_bar in ProgressBar.__getstate__ (#7608)
Co-authored-by: Yifu Wang <yifuwang@[email protected]> Co-authored-by: Justus Schock <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Carlos Mocholi <[email protected]>
1 parent 6b81cd8 commit 9f979b5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77

8+
## [1.3.3] - 2021-05-27
9+
10+
### Fixed
11+
12+
- Fixed `ProgressBar` pickling after calling `trainer.predict` ([#7608](https://github.com/PyTorchLightning/pytorch-lightning/pull/7608))
13+
14+
815
## [1.3.2] - 2021-05-18
916

1017
### Changed

pytorch_lightning/callbacks/progress.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,15 @@ def __init__(self, refresh_rate: int = 1, process_position: int = 0):
283283
self.main_progress_bar = None
284284
self.val_progress_bar = None
285285
self.test_progress_bar = None
286+
self.predict_progress_bar = None
286287

287288
def __getstate__(self):
288289
# can't pickle the tqdm objects
289290
state = self.__dict__.copy()
290291
state['main_progress_bar'] = None
291292
state['val_progress_bar'] = None
292293
state['test_progress_bar'] = None
294+
state['predict_progress_bar'] = None
293295
return state
294296

295297
@property

tests/callbacks/test_progress_bar.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
import pickle
1516
import sys
1617
from typing import Optional, Union
1718
from unittest import mock
@@ -482,3 +483,17 @@ def test_progress_bar_print_disabled(tqdm_write, mock_print, tmpdir):
482483
call("test_step"),
483484
])
484485
tqdm_write.assert_not_called()
486+
487+
488+
def test_progress_bar_can_be_pickled():
489+
bar = ProgressBar()
490+
trainer = Trainer(fast_dev_run=True, callbacks=[bar], max_steps=1)
491+
model = BoringModel()
492+
493+
pickle.dumps(bar)
494+
trainer.fit(model)
495+
pickle.dumps(bar)
496+
trainer.test(model)
497+
pickle.dumps(bar)
498+
trainer.predict(model)
499+
pickle.dumps(bar)

0 commit comments

Comments
 (0)