-
Notifications
You must be signed in to change notification settings - Fork 32k
[OPT] Run test in lower precision on GPU #17353
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
8 commits
Select commit
Hold shift + click to select a range
db27c99
[OPT] Run test only in half precision
patrickvonplaten 77b2f6e
up
patrickvonplaten a533e06
up
patrickvonplaten cccd907
up
patrickvonplaten 6002a65
up
patrickvonplaten f72ae0d
finish
patrickvonplaten 3db3ac2
fix on GPU
patrickvonplaten 8f1cc48
Update tests/models/opt/test_modeling_opt.py
patrickvonplaten 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
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 |
|---|---|---|
|
|
@@ -271,14 +271,25 @@ class OPTModelIntegrationTests(unittest.TestCase): | |
| def test_inference_no_head(self): | ||
| model = OPTModel.from_pretrained("facebook/opt-350m").to(torch_device) | ||
| input_ids = _long_tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]) | ||
|
|
||
| with torch.no_grad(): | ||
| output = model(input_ids=input_ids).last_hidden_state | ||
|
|
||
| expected_shape = torch.Size((1, 11, 512)) | ||
| self.assertEqual(output.shape, expected_shape) | ||
| expected_slice = torch.tensor( | ||
| [[-0.2867, -1.9256, -0.3062], [-1.2711, -0.1337, -0.1897], [0.4109, 0.1187, -1.3142]], device=torch_device | ||
| [[-0.2873, -1.9242, -0.3059], [-1.2738, -0.1333, -0.1877], [0.4116, 0.1192, -1.3107]], | ||
| device=torch_device, | ||
| ) | ||
| self.assertTrue(torch.allclose(output[:, :3, :3], expected_slice, atol=1e-3)) | ||
| # Getting different logits results on GPU depending on PyTorch version (1.10+cu11.0 vs. 1.11+cu11.4) | ||
| # and results also differ between CPU and GPU. Only on CPU it seems to be deterministic. | ||
|
|
||
| # It's not because the weights are saved & loaded in FP16 | ||
| # checked that the same happens when weights are stored in fp32 and loaded in fp32. | ||
| # The differences start to creep in in the first linear projection matrix project_in_dim | ||
| # It however also happens for BART (maybe related to training model in fp16?) | ||
| atol = 1e-2 if torch_device != "cpu" else 1e-3 | ||
| assert_tensors_close(output[0, :3, :3], expected_slice, atol=atol) | ||
|
Comment on lines
+291
to
+292
Collaborator
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. Ouch, that's some difference. |
||
|
|
||
|
|
||
| @require_torch | ||
|
|
||
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.
Cleaned this up a bit. Think we should try to align it as much as possible to Bart here
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 :) , I have to update the tf code based on that I think