-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fixed batch sizes #68
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4543c5b
Adds `--pad_max` flag and relevant docs.
kylebgorman 064c05a
Adds a cute optimization to dataconfig.
kylebgorman 8577612
Fixed batch sizes throughout.
kylebgorman 8df8ab6
More work on mandatory fixed batch size.
kylebgorman 7c5df5d
Removes unused properties.
kylebgorman 1727f69
Update datasets.py
kylebgorman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,27 +27,32 @@ def __init__( | |
pad_idx, | ||
config: dataconfig.DataConfig, | ||
arch: str, | ||
max_source_length: int = defaults.MAX_SOURCE_LENGTH, | ||
max_target_length: int = defaults.MAX_TARGET_LENGTH, | ||
max_source_length=defaults.MAX_SOURCE_LENGTH, | ||
max_target_length=defaults.MAX_TARGET_LENGTH, | ||
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. Should this have an annotation Optional[int] ? 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. Not if it's specified a kwargs with a default value that isn't |
||
# FIXME: max features length. | ||
): | ||
"""Initializes the collator. | ||
|
||
If max source and/or target length are not specified, they are | ||
computed dynamically (i.e., for each source and target batch). | ||
|
||
Args: | ||
pad_idx (int). | ||
config (dataconfig.DataConfig). | ||
arch (str). | ||
max_source_length (int). | ||
max_target_length (int). | ||
max_source_length (int, optional). | ||
max_target_length (int, optional). | ||
""" | ||
self.pad_idx = pad_idx | ||
self.has_features = config.has_features | ||
self.has_target = config.has_target | ||
self.max_source_length = max_source_length | ||
self.max_target_length = max_target_length | ||
self.separate_features = config.has_features and arch in [ | ||
"pointer_generator_lstm", | ||
"transducer", | ||
] | ||
self.max_source_length = max_source_length | ||
self.max_target_length = max_target_length | ||
# FIXME: max features length. | ||
|
||
def _source_length_error(self, padded_length: int): | ||
"""Callback function to raise the error when the padded length of the | ||
|
@@ -69,8 +74,8 @@ def _target_length_warning(self, padded_length: int): | |
"""Callback function to log a message when the padded length of the | ||
target batch is greater than the `max_target_length` allowed. | ||
|
||
Since `max_target_length` just truncates during inference, this is | ||
simply a suggestion. | ||
Since `max_target_length` truncates during inference, this is only a | ||
suggestion; it is logged rather than converted into an error. | ||
|
||
Args: | ||
padded_length (int): The length of the the padded tensor. | ||
|
@@ -79,7 +84,7 @@ def _target_length_warning(self, padded_length: int): | |
msg = f"The length of a batch ({padded_length}) " | ||
msg += "is greater than the `--max_target_length` specified " | ||
msg += f"({self.max_target_length}). This means that " | ||
msg += "decoding at inference time will likely be truncated. " | ||
msg += "truncation may occur at inference time. " | ||
msg += "Consider increasing `--max_target_length`." | ||
util.log_info(msg) | ||
|
||
|
@@ -111,6 +116,7 @@ def pad_source( | |
return batches.PaddedTensor( | ||
[item.source for item in itemlist], | ||
self.pad_idx, | ||
self.max_source_length, | ||
self._source_length_error, | ||
) | ||
|
||
|
@@ -129,6 +135,8 @@ def pad_source_features( | |
return batches.PaddedTensor( | ||
self.concatenate_source_and_features(itemlist), | ||
self.pad_idx, | ||
self.max_source_length, | ||
# FIXME: max features length. | ||
self._source_length_error, | ||
) | ||
|
||
|
@@ -145,7 +153,9 @@ def pad_features( | |
batches.PaddedTensor. | ||
""" | ||
return batches.PaddedTensor( | ||
[item.features for item in itemlist], self.pad_idx | ||
[item.features for item in itemlist], | ||
self.pad_idx, | ||
# FIXME: max features length. | ||
) | ||
|
||
def pad_target( | ||
|
@@ -162,6 +172,7 @@ def pad_target( | |
return batches.PaddedTensor( | ||
[item.target for item in itemlist], | ||
self.pad_idx, | ||
self.max_target_length, | ||
self._target_length_warning, | ||
) | ||
|
||
|
@@ -205,3 +216,4 @@ def add_argparse_args(parser: argparse.ArgumentParser) -> None: | |
default=defaults.MAX_TARGET_LENGTH, | ||
help="Maximum target string length. Default: %(default)s.", | ||
) | ||
# FIXME: max features length. |
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.
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.
Should this have an annotation
Optional[int]
?