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

Don't reshuffle eval data each "epoch" #229

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions olmo/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List

from torch.utils.data import DataLoader, DistributedSampler

Expand All @@ -15,14 +15,15 @@

def build_memmap_dataset(train_config: TrainConfig, data_config: DataConfig) -> MemMapDataset:
paths: List[str]
metadata: Optional[List[Dict[str, Any]]] = None
metadata: List[Dict[str, Any]] = []
if data_config.paths:
if data_config.datasets:
raise OlmoConfigurationError("DataConfig.paths is mutually exclusive with DataConfig.datasets")
paths = data_config.paths
for path in paths:
metadata.append({"path": str(path)})
elif data_config.datasets:
paths = []
metadata = []
for label in sorted(data_config.datasets.keys()):
label_paths = data_config.datasets[label]
paths.extend(label_paths)
Expand Down
2 changes: 1 addition & 1 deletion olmo/eval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def make_metric():
label=eval_config.label,
type=eval_config.type,
eval_loader=eval_loader,
eval_batches=cycle_through_epochs(eval_loader),
eval_batches=cycle_through_epochs(eval_loader, update_epoch_seed=False),
eval_metric=eval_metric,
subset_num_batches=eval_config.subset_num_batches,
)
Expand Down
6 changes: 4 additions & 2 deletions olmo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,14 @@ def peak_gpu_memory(reset: bool = False) -> Optional[float]:
return peak_mb


def cycle_through_epochs(dataloader: DataLoader) -> Generator[Dict[str, Any], None, None]:
def cycle_through_epochs(
dataloader: DataLoader, update_epoch_seed: bool = True
) -> Generator[Dict[str, Any], None, None]:
while True:
for batch in dataloader:
yield batch

if isinstance(dataloader.sampler, DistributedSampler):
if update_epoch_seed and isinstance(dataloader.sampler, DistributedSampler):
epoch = dataloader.sampler.epoch + 1
dataloader.sampler.set_epoch(epoch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how skipping this makes sure it starts from scratch every epoch. I thought we'd have to reset the data loader somehow every time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each validation loop through a dataset is a complete loop / epoch over the dataset (less the extra examples, since drop_last=True). The DistributedSampler reshuffles each epoch with a specific seed that's shared across all processes. That seed never changes unless you call DistributedSampler.set_epoch(). See https://pytorch.org/docs/stable/data.html#torch.utils.data.distributed.DistributedSampler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the fact that this is confusing, err kind of works by exploiting a nuance of the DistributedSampler, tells me that this probably isn't the best way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated: 9b52525

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need cycle_through_epoch then? Or at least, do we still need this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed: ac8322c


Expand Down