-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unknown number of batches with data loaders
- Loading branch information
Showing
11 changed files
with
164 additions
and
113 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,3 @@ | |
|
||
callbacks | ||
checkpoint | ||
utils |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from dataclasses import dataclass | ||
|
||
from ..config import StrEnum | ||
|
||
|
||
class DurationUnit(StrEnum): | ||
""" | ||
Units that can be used to define a :class:`Duration`. | ||
""" | ||
|
||
steps = "steps" | ||
""" | ||
Steps (batches). | ||
""" | ||
epochs = "epochs" | ||
""" | ||
Epochs. | ||
""" | ||
tokens = "tokens" | ||
""" | ||
Tokens. | ||
""" | ||
|
||
|
||
@dataclass | ||
class Duration: | ||
value: int | ||
""" | ||
The value of the duration. | ||
""" | ||
unit: DurationUnit | ||
""" | ||
The unit associated with the :data:`value`. | ||
""" | ||
|
||
@classmethod | ||
def steps(cls, steps: int) -> "Duration": | ||
""" | ||
Define a duration from a number of steps. | ||
""" | ||
return cls(value=steps, unit=DurationUnit.steps) | ||
|
||
@classmethod | ||
def epochs(cls, epochs: int) -> "Duration": | ||
""" | ||
Define a duration from a number of epochs. | ||
""" | ||
return cls(value=epochs, unit=DurationUnit.epochs) | ||
|
||
@classmethod | ||
def tokens(cls, tokens: int) -> "Duration": | ||
""" | ||
Define a duration from a number of tokens. | ||
""" | ||
return cls(value=tokens, unit=DurationUnit.tokens) | ||
|
||
def due(self, *, step: int, tokens: int, epoch: int) -> bool: | ||
""" | ||
Check if the duration is due. | ||
""" | ||
if self.unit == DurationUnit.steps: | ||
return step >= self.value | ||
elif self.unit == DurationUnit.tokens: | ||
return tokens >= self.value | ||
elif self.unit == DurationUnit.epochs: | ||
return epoch > self.value | ||
else: | ||
raise NotImplementedError | ||
|
||
|
||
class LoadStrategy(StrEnum): | ||
""" | ||
Determines the strategy for loading checkpoints prior to training. | ||
""" | ||
|
||
if_available = "if_available" | ||
""" | ||
Only load from the load path if a checkpoint exists there. | ||
""" | ||
|
||
always = "always" | ||
""" | ||
Always try loading from the load path. | ||
""" | ||
|
||
never = "never" | ||
""" | ||
Never load from the load path. | ||
""" | ||
|
||
|
||
class ReduceType(StrEnum): | ||
""" | ||
An enumeration of the allowed ways to reduce a metric across ranks. | ||
""" | ||
|
||
mean = "mean" | ||
""" | ||
Average across the process group. | ||
""" | ||
|
||
sum = "sum" | ||
""" | ||
Add across the process group. | ||
""" | ||
|
||
max = "max" | ||
""" | ||
Take the max across the process group. | ||
""" | ||
|
||
l2_norm = "l2_norm" | ||
""" | ||
For metrics that are computed as L2 norms on each rank, this will correctly reduce the norm | ||
across the process group to produce the global L2 norm. | ||
""" |
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
Oops, something went wrong.