Skip to content
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

[cherry pick] make DataLoader warning less noisy #34001

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions python/paddle/fluid/dataloader/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import logging
from ..log_helper import get_logger
from collections.abc import Sequence, Mapping

from collections.abc import Sequence
_WARNING_TO_LOG = True


class _DatasetFetcher(object):
Expand All @@ -24,13 +25,17 @@ def __init__(self, dataset, auto_collate_batch, collate_fn, drop_last):
self.auto_collate_batch = auto_collate_batch
self.collate_fn = collate_fn
self.drop_last = drop_last
self._is_warning_logged = False

def fetch(self, batch_indices):
raise NotImplementedError("'fetch' not implement for class {}".format(
self.__class__.__name__))

def _log_warning(self):
# only log warning on GPU 0 when distributed launch
from ...distributed import get_world_size, get_rank
if get_world_size() >= 2 and get_rank() != 0:
return

warn_str = "Detect dataset only contains single fileds, return format " \
"changed since Paddle 2.1. In Paddle <= 2.0, DataLoader add " \
"a list surround output data(e.g. return [data]), and in " \
Expand Down Expand Up @@ -77,10 +82,12 @@ def fetch(self, batch_indices):
if len(data) == 0 or (self.drop_last and
len(data) < len(batch_indices)):
raise StopIteration
if not isinstance(data[0],
Sequence) and not self._is_warning_logged:

global _WARNING_TO_LOG
if not isinstance(data[0], (Sequence, Mapping)) \
and _WARNING_TO_LOG:
self._log_warning()
self._is_warning_logged = True
_WARNING_TO_LOG = False
else:
data = next(self.dataset_iter)

Expand All @@ -98,10 +105,11 @@ def fetch(self, batch_indices):
if self.auto_collate_batch:
data = [self.dataset[idx] for idx in batch_indices]

if not isinstance(data[0],
Sequence) and not self._is_warning_logged:
global _WARNING_TO_LOG
if not isinstance(data[0], (Sequence, Mapping)) \
and _WARNING_TO_LOG:
self._log_warning()
self._is_warning_logged = True
_WARNING_TO_LOG = False
else:
data = self.dataset[batch_indices]

Expand Down