-
Notifications
You must be signed in to change notification settings - Fork 39
[Accuracy diff No.25、101] Fix accuracy diff for paddle.linalg.eigh API #276
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 4 commits
Commits
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 |
|---|---|---|
|
|
@@ -233,6 +233,28 @@ def test(self): | |
| # torch's from_dlpack now don't support negative strides | ||
| paddle_output = paddle_output.contiguous() | ||
|
|
||
| paddle_output_cache = [] | ||
| if self.api_config.api_name == "paddle.linalg.eigh": | ||
| # The output of eigen vectors are not unique, because multiplying an eigen vector by -1 in the real case | ||
| # or by e^(i*\theta) in the complex case produces another set of valid eigen vectors of the matrix. | ||
| # So we test whether the elements of each coef_vector (i.e. paddle_output / torch_output for each eigen vector) | ||
| # are all the same and whether the |coef| == 1 for simplicity. | ||
| paddle_output, torch_output = list(paddle_output), list(torch_output) | ||
| paddle_output_cache = [i.clone() for i in paddle_output] | ||
NKNaN marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| eigvector_len = paddle_output[1].shape[-2] | ||
| paddle_eigvectors = paddle_output.pop(1).matrix_transpose().reshape([-1, eigvector_len]) | ||
| torch_eigvectors = torch_output.pop(1).transpose(-1, -2).reshape((-1, eigvector_len)) | ||
| for i in range(paddle_eigvectors.shape[0]): | ||
| coef_vector = paddle.to_tensor(paddle_eigvectors[i].numpy()/torch_eigvectors[i].numpy(), dtype=paddle_eigvectors[i].dtype) | ||
| coef_vector = coef_vector.round(2) | ||
| coef_0 = paddle_eigvectors[i].numpy()[0]/torch_eigvectors[i].numpy()[0] | ||
| coef_vector_approx = torch.tensor([coef_0] * eigvector_len) | ||
| abs_coef = coef_vector.abs().astype("float64")[0] | ||
| one = torch.tensor(1.0, dtype=torch.float64) | ||
| paddle_output.append([coef_vector, abs_coef]) | ||
| torch_output.append([coef_vector_approx, one]) | ||
|
Comment on lines
+252
to
+253
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. 我的想法是: 这样可以同时比较绝对误差和相对误差,不需要 paddle_output_cache~
Contributor
Author
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. 嗯嗯,忘记删了 |
||
|
|
||
|
|
||
| if isinstance(paddle_output, paddle.Tensor): | ||
| if isinstance(torch_output, torch.Tensor): | ||
| try: | ||
|
|
@@ -332,6 +354,9 @@ def test(self): | |
| write_to_log("accuracy_error", self.api_config.config) | ||
| return | ||
|
|
||
| if self.api_config.api_name == "paddle.linalg.eigh": | ||
| paddle_output = paddle_output_cache | ||
|
|
||
NKNaN marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.need_check_grad() and torch_grad_success: | ||
| try: | ||
| paddle_out_grads = None | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.