Skip to content

Commit ed27190

Browse files
yifuwangYifu Wangjustusschockpre-commit-ci[bot]carmocca
authored
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 8266b14 commit ed27190

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
106106
- Fixed parsing of multiple training dataloaders ([#7433](https://github.com/PyTorchLightning/pytorch-lightning/pull/7433))
107107

108108

109+
- Fixed `ProgressBar` pickling after calling `trainer.predict` ([#7608](https://github.com/PyTorchLightning/pytorch-lightning/pull/7608))
110+
111+
109112
- Fixed recursive passing of `wrong_type` keyword argument in `pytorch_lightning.utilities.apply_to_collection` ([#7433](https://github.com/PyTorchLightning/pytorch-lightning/pull/7433))
110113

111114

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)