-
Notifications
You must be signed in to change notification settings - Fork 812
Parameterized XLMR and Roberta model integration tests #1496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94a3349
Updated max seq length for truncate in xlmr base. Updated xlmr docs. …
60bb626
Removing changes to truncate transform
514e9fc
Merge branch 'main' into update_xlmr_encoder
b6f08ed
Remove documentation changes from PR
e2c79e7
Parameterized model tests
964b30b
Merge branch 'main' into update_xlmr_encoder
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 hidden or 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 |
---|---|---|
@@ -1,67 +1,56 @@ | ||
import torch | ||
import torchtext | ||
from parameterized import parameterized | ||
from torchtext.models import ( | ||
XLMR_BASE_ENCODER, | ||
XLMR_LARGE_ENCODER, | ||
ROBERTA_BASE_ENCODER, | ||
ROBERTA_LARGE_ENCODER, | ||
) | ||
|
||
from ..common.assets import get_asset_path | ||
from ..common.torchtext_test_case import TorchtextTestCase | ||
|
||
TEST_MODELS_PARAMETERIZED_ARGS = [ | ||
("xlmr.base.output.pt", "XLMR base Model Comparison", XLMR_BASE_ENCODER), | ||
("xlmr.large.output.pt", "XLMR base Model Comparison", XLMR_LARGE_ENCODER), | ||
( | ||
"roberta.base.output.pt", | ||
"Roberta base Model Comparison", | ||
ROBERTA_BASE_ENCODER, | ||
), | ||
( | ||
"roberta.large.output.pt", | ||
"Roberta base Model Comparison", | ||
ROBERTA_LARGE_ENCODER, | ||
), | ||
] | ||
|
||
class TestModels(TorchtextTestCase): | ||
def test_roberta_base(self): | ||
asset_path = get_asset_path("roberta.base.output.pt") | ||
test_text = "Roberta base Model Comparison" | ||
|
||
roberta_base = torchtext.models.ROBERTA_BASE_ENCODER | ||
transform = roberta_base.transform() | ||
model = roberta_base.get_model() | ||
model = model.eval() | ||
|
||
model_input = torch.tensor(transform([test_text])) | ||
actual = model(model_input) | ||
expected = torch.load(asset_path) | ||
torch.testing.assert_close(actual, expected) | ||
|
||
def test_roberta_base_jit(self): | ||
asset_path = get_asset_path("roberta.base.output.pt") | ||
test_text = "Roberta base Model Comparison" | ||
|
||
roberta_base = torchtext.models.ROBERTA_BASE_ENCODER | ||
transform = roberta_base.transform() | ||
transform_jit = torch.jit.script(transform) | ||
model = roberta_base.get_model() | ||
model = model.eval() | ||
model_jit = torch.jit.script(model) | ||
|
||
model_input = torch.tensor(transform_jit([test_text])) | ||
actual = model_jit(model_input) | ||
expected = torch.load(asset_path) | ||
torch.testing.assert_close(actual, expected) | ||
|
||
def test_roberta_large(self): | ||
asset_path = get_asset_path("roberta.large.output.pt") | ||
test_text = "Roberta base Model Comparison" | ||
class TestModels(TorchtextTestCase): | ||
@parameterized.expand(TEST_MODELS_PARAMETERIZED_ARGS) | ||
def test_model(self, expected_asset_name, test_text, model_bundler): | ||
expected_asset_path = get_asset_path(expected_asset_name) | ||
|
||
roberta_large = torchtext.models.ROBERTA_LARGE_ENCODER | ||
transform = roberta_large.transform() | ||
model = roberta_large.get_model() | ||
transform = model_bundler.transform() | ||
model = model_bundler.get_model() | ||
model = model.eval() | ||
|
||
model_input = torch.tensor(transform([test_text])) | ||
actual = model(model_input) | ||
expected = torch.load(asset_path) | ||
expected = torch.load(expected_asset_path) | ||
torch.testing.assert_close(actual, expected) | ||
|
||
def test_roberta_large_jit(self): | ||
asset_path = get_asset_path("roberta.large.output.pt") | ||
test_text = "Roberta base Model Comparison" | ||
@parameterized.expand(TEST_MODELS_PARAMETERIZED_ARGS) | ||
def test_model_jit(self, expected_asset_name, test_text, model_bundler): | ||
expected_asset_path = get_asset_path(expected_asset_name) | ||
|
||
roberta_large = torchtext.models.ROBERTA_LARGE_ENCODER | ||
transform = roberta_large.transform() | ||
transform = model_bundler.transform() | ||
transform_jit = torch.jit.script(transform) | ||
model = roberta_large.get_model() | ||
model = model_bundler.get_model() | ||
model = model.eval() | ||
model_jit = torch.jit.script(model) | ||
|
||
model_input = torch.tensor(transform_jit([test_text])) | ||
actual = model_jit(model_input) | ||
expected = torch.load(asset_path) | ||
expected = torch.load(expected_asset_path) | ||
torch.testing.assert_close(actual, expected) |
This file contains hidden or 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
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.
I think you can go further to make the jit part parameterized as well.
You can parameterize the behavior around jitting in
test_model
, then make a Cartesian product ofTEST_MODELS_PARAMETERIZED_ARGS
andjit=True|False
to run all the tests.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.
Thanks for the feedback. Will do this in a followup PR by pulling in the
nested_params
helper method from torchaudio.