Skip to content

Commit

Permalink
Fix dummy batch when --max-tokens is small (fixes facebookresearch#347)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebookresearch#366

Differential Revision: D13058513

Pulled By: myleott

fbshipit-source-id: a146d2cfb345d404775ed8d6b8e4a4ad4e7a33b4
  • Loading branch information
myleott authored and facebook-github-bot committed Nov 14, 2018
1 parent 1f4e1e8 commit 3707c03
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fairseq/data/language_pair_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_dummy_batch(self, num_tokens, max_positions, src_len=128, tgt_len=128):
max_positions,
(self.max_source_positions, self.max_target_positions),
)
bsz = num_tokens // max(src_len, tgt_len)
bsz = max(num_tokens // max(src_len, tgt_len), 1)
return self.collater([
{
'id': i,
Expand Down
2 changes: 1 addition & 1 deletion fairseq/data/monolingual_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_dummy_batch(self, num_tokens, max_positions, tgt_len=128):
"""Return a dummy batch with a given number of tokens."""
if isinstance(max_positions, float) or isinstance(max_positions, int):
tgt_len = min(tgt_len, max_positions)
bsz = num_tokens // tgt_len
bsz = max(num_tokens // tgt_len, 1)
target = self.vocab.dummy_sentence(tgt_len + 2)
source, past_target, future_target = target[1:-1], target[2:], target[:-2]
source, target = self._make_source_target(source, past_target, future_target)
Expand Down

0 comments on commit 3707c03

Please sign in to comment.