This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix bug with lazy data loading, un-implement __len__ on AllennlpLazyDataset #4328
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
55053fb
improve support for lazy data loading
epwalsh 9341ef5
update changelog
epwalsh e02277c
raise TypeError instead
epwalsh f98b2bf
fix
epwalsh 0239375
use num_steps_per_epoch=None with lazy
epwalsh 463af52
Merge branch 'master' into lazy-data-loading
epwalsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import logging | ||
from typing import List | ||
from typing import List, Optional | ||
|
||
from overrides import overrides | ||
import torch | ||
|
@@ -33,7 +33,7 @@ class SlantedTriangular(LearningRateScheduler): | |
This argument does not get an entry in a configuration file for the object. | ||
num_epochs : `int`, required. | ||
The total number of epochs for which the model should be trained. | ||
num_steps_per_epoch : `int`, required. | ||
num_steps_per_epoch : `Optional[int]`, optional (default = `None`) | ||
The number of steps (updates, batches) per training epoch. | ||
cut_frac : `float`, optional (default = `0.1`). | ||
The fraction of the steps to increase the learning rate. | ||
|
@@ -53,7 +53,7 @@ def __init__( | |
self, | ||
optimizer: torch.optim.Optimizer, | ||
num_epochs: int, | ||
num_steps_per_epoch: int, | ||
num_steps_per_epoch: Optional[int] = None, | ||
cut_frac: float = 0.1, | ||
ratio: int = 32, | ||
last_epoch: int = -1, | ||
|
@@ -138,7 +138,9 @@ def get_values(self): | |
self.batch_num_total_epoch_end[-1] / (len(self.batch_num_total_epoch_end) - 1) | ||
) | ||
else: | ||
actual_num_steps_per_epoch = max(self.num_steps_per_epoch, self.last_batch_num_total) | ||
actual_num_steps_per_epoch = max( | ||
self.num_steps_per_epoch or 1, self.last_batch_num_total | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives the same behavior as it was before. I'm not sure if that's an issue. |
||
) | ||
|
||
if self.freezing_current: | ||
# if we still freeze, we restrict the schedule to the current epoch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,7 +361,7 @@ def __init__( | |
self.optimizer = optimizer | ||
|
||
if patience is None: # no early stopping | ||
if validation_data_loader: | ||
if validation_data_loader is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need this so |
||
logger.warning( | ||
"You provided a validation dataset but patience was set to None, " | ||
"meaning that early stopping is disabled" | ||
|
@@ -508,9 +508,15 @@ def _train_epoch(self, epoch: int) -> Dict[str, float]: | |
|
||
logger.info("Training") | ||
|
||
num_training_batches = math.ceil( | ||
len(self.data_loader) / self._num_gradient_accumulation_steps | ||
) | ||
num_training_batches: Union[int, float] | ||
try: | ||
len_data_loader = len(self.data_loader) | ||
num_training_batches = math.ceil( | ||
len_data_loader / self._num_gradient_accumulation_steps | ||
) | ||
except TypeError: | ||
num_training_batches = float("inf") | ||
|
||
# Having multiple tqdm bars in case of distributed training will be a mess. Hence only the master's | ||
# progress is shown | ||
if self._master: | ||
|
@@ -1061,8 +1067,12 @@ def from_partial_objects( | |
if not optimizer_: | ||
optimizer_ = Optimizer.default(parameters) | ||
|
||
batches_per_epoch = len(data_loader) # returns "1" instead of TypeError for _LazyInstances | ||
batches_per_epoch = math.ceil(batches_per_epoch / num_gradient_accumulation_steps) | ||
batches_per_epoch: Optional[int] | ||
try: | ||
batches_per_epoch = len(data_loader) | ||
batches_per_epoch = math.ceil(batches_per_epoch / num_gradient_accumulation_steps) | ||
except TypeError: | ||
batches_per_epoch = None | ||
|
||
moving_average_ = moving_average.construct(parameters=parameters) | ||
learning_rate_scheduler_ = learning_rate_scheduler.construct( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need this so
len()
is not called.