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

[World logging] Fix world logging for dynamic batching #3867

Merged
merged 5 commits into from
Aug 8, 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
10 changes: 9 additions & 1 deletion parlai/utils/world_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def _add_episode(self, episode):
"""
self._logs.append(episode)

def _check_episode_done(self, parley) -> bool:
"""
Check whether an episode is done for a given parley.
"""
if parley[0]:
return parley[0].get('episode_done', False)
return False

def _is_batch_world(self, world):
return (
isinstance(world, BatchWorld) or isinstance(world, DynamicBatchWorld)
Expand All @@ -111,7 +119,7 @@ def _log_batch(self, world):
# in the buffer
idx = parley[0]['dyn_batch_idx'] if 'dyn_batch_idx' in parley[0] else i
self._add_msgs(parley, idx=idx)
if world.worlds[idx].episode_done():
if self._check_episode_done(parley):
self.reset_world(idx=idx)

def log(self, world):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_dynamicbatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ def test_world_logging(self):
# we log the batch index in the teacher acts only
self.assertEquals(dyn_batch_idx, turn['dyn_batch_idx'])

def test_world_logging_buffersize(self):
"""
Test world logging with dynamic batching.

Checks when the number of examples exceeds the buffersize.
"""
with testing_utils.tempdir() as tmpdir:
save_report = os.path.join(tmpdir, 'report')
testing_utils.eval_model(
dict(
model_file='zoo:unittest/transformer_generator2/model',
task='integration_tests:RepeatTeacher:2000',
world_logs=save_report + '.jsonl',
report_filename=save_report,
truncate=1024,
dynamic_batching='full',
batchsize=4,
),
valid_datatype='train:evalmode',
skip_test=True,
)
convo_fle = str(save_report) + '.jsonl'
convos = Conversations(convo_fle)
# we expect there to be 2000 episodes logged in the convos
self.assertEquals(len(convos), 2000)

def test_weird_batchsize(self):
# intentionally a difficult number
self._test_correct_processed(NUM_TEST, batchsize=7)
Expand Down