Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[TorchGeneratorAgent] Batchify default to not sorting #4138

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions parlai/agents/hred/hred.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def batchify(self, obs_batch, sort=True):

Store history vec as context_vec.
"""
# NOTE: `sort` is set to True here (Default is False in TorchGeneratorAgent)
# TODO: Sorting the batch will result in various local metrics being broadcasted
# back to individual examples in the wrong order, such as the lengths of
# the context and labels. Aggregate metric reports will still be accurate.
batch = super().batchify(obs_batch, sort)
# sum here is list concat, not addition
context_vec, hist_lens_ = self._pad_tensor(
Expand Down
3 changes: 3 additions & 0 deletions parlai/agents/seq2seq/seq2seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def batchify(self, *args, **kwargs):
Override batchify options for seq2seq.
"""
kwargs['sort'] = True # need sorted for pack_padded
# TODO: Sorting the batch will result in various local metrics being broadcasted
# back to individual examples in the wrong order, such as the lengths of
# the context and labels. Aggregate metric reports will still be accurate.
return super().batchify(*args, **kwargs)

def state_dict(self):
Expand Down
2 changes: 1 addition & 1 deletion parlai/core/torch_generator_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def vectorize(self, *args, **kwargs):
kwargs['add_end'] = True # we do want this
return super().vectorize(*args, **kwargs)

def batchify(self, obs_batch, sort=True):
def batchify(self, obs_batch, sort=False):
batch = super().batchify(obs_batch, sort=sort)
if (
self.beam_block_full_context
Expand Down