This repository was archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add WorldLogger to train_model script. #4369
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,13 @@ | |
import unittest | ||
import json | ||
import parlai.utils.testing as testing_utils | ||
from parlai.utils.io import PathManager | ||
from parlai.core.metrics import AverageMetric | ||
from parlai.core.worlds import create_task | ||
from parlai.core.opt import Opt | ||
from parlai.core.params import ParlaiParser | ||
from parlai.core.agents import register_agent, Agent | ||
from parlai.scripts.eval_model import get_task_world_logs | ||
|
||
|
||
class TestTrainModel(unittest.TestCase): | ||
|
@@ -223,6 +225,52 @@ def test_opt_step(self): | |
def test_opt_step_update_freq_2(self): | ||
self._test_opt_step_opts(2) | ||
|
||
def test_save_world_logs(self): | ||
""" | ||
Test that we can save world logs from train model. | ||
""" | ||
with testing_utils.tempdir() as tmpdir: | ||
log_report = os.path.join(tmpdir, 'world_logs.jsonl') | ||
valid, test = testing_utils.train_model( | ||
{ | ||
'task': 'integration_tests', | ||
'validation_max_exs': 10, | ||
'model': 'repeat_label', | ||
'short_final_eval': True, | ||
'num_epochs': 1.0, | ||
'world_logs': log_report, | ||
} | ||
) | ||
with PathManager.open(log_report) as f: | ||
json_lines = f.readlines() | ||
assert len(json_lines) == 10 | ||
|
||
def test_save_multiple_world_logs(self): | ||
""" | ||
Test that we can save multiple world_logs from train model on multiple tasks. | ||
""" | ||
with testing_utils.tempdir() as tmpdir: | ||
log_report = os.path.join(tmpdir, 'world_logs.jsonl') | ||
multitask = 'integration_tests,integration_tests:ReverseTeacher' | ||
valid, test = testing_utils.train_model( | ||
{ | ||
'task': multitask, | ||
'validation_max_exs': 10, | ||
'model': 'repeat_label', | ||
'short_final_eval': True, | ||
'num_epochs': 1.0, | ||
'world_logs': log_report, | ||
} | ||
) | ||
|
||
for task in multitask.split(','): | ||
task_log_report = get_task_world_logs( | ||
task, log_report, is_multitask=True | ||
) | ||
with PathManager.open(task_log_report) as f: | ||
json_lines = f.readlines() | ||
assert len(json_lines) == 5 | ||
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. why is there only 5 lines instead of 10? |
||
|
||
|
||
@register_agent("fake_report") | ||
class FakeReportAgent(Agent): | ||
|
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.
@jxmsML This is why we have only 5 lines instead of 10, cuz during multitask
len(valid_worlds)
> 1