Skip to content
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
19 changes: 12 additions & 7 deletions ppsci/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,21 @@ def build_dataloader(_dataset, cfg):
sampler_cfg["batch_size"] = cfg["batch_size"]
batch_sampler = getattr(io, batch_sampler_cls)(_dataset, **sampler_cfg)
else:
if cfg["batch_size"] != 1:
raise ValueError(
f"`batch_size` should be 1 when sampler config is None, but got {cfg['batch_size']}."
batch_sampler_cls = "BatchSampler"
if world_size > 1:
batch_sampler_cls = "DistributedBatchSampler"
logger.warning(
f"Automatically use 'DistributedBatchSampler' instead of "
f"'BatchSampler' when world_size({world_size}) > 1."
)
logger.warning(
"`batch_size` is set to 1 as neither sampler config nor batch_size is set."
)
batch_sampler = io.BatchSampler(
batch_sampler = getattr(io, batch_sampler_cls)(
_dataset,
batch_size=cfg["batch_size"],
shuffle=False,
drop_last=False,
)
logger.message(
"'shuffle' and 'drop_last' are both set to False in default as sampler config is not specified."
)

# build collate_fn if specified
Expand Down