-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix inconsistency between index_fill and index_fill_ #59863
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 |
---|---|---|
|
@@ -1621,7 +1621,7 @@ class TestDygraphInplaceIndexFill(TestDygraphInplace): | |
def init_data(self): | ||
self.input_var_numpy = np.random.random((20, 40)) | ||
self.dtype = "float32" | ||
self.axis = 0 | ||
self.axis = 1 | ||
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. 这个修改是否是必要的呢,目前axis=0是否表现正常? 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. axis=0是正常的,axis=1覆盖情况更广,之前就是因为axis=0导致没有测试到这个API的inplace版本有不一致问题 |
||
self.index = paddle.to_tensor([0, 2]) | ||
self.value = -1 | ||
|
||
|
@@ -1631,6 +1631,38 @@ def inplace_api_processing(self, var): | |
def non_inplace_api_processing(self, var): | ||
return paddle.index_fill(var, self.index, self.axis, self.value) | ||
|
||
def test_forward_version(self): | ||
with paddle.base.dygraph.guard(): | ||
var = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) | ||
self.assertEqual(var.inplace_version, 0) | ||
|
||
inplace_var = self.inplace_api_processing(var) | ||
self.assertEqual(var.inplace_version, 3) | ||
|
||
inplace_var[0] = 2 | ||
self.assertEqual(var.inplace_version, 4) | ||
|
||
inplace_var = self.inplace_api_processing(inplace_var) | ||
self.assertEqual(var.inplace_version, 7) | ||
|
||
def test_backward_error(self): | ||
with paddle.base.dygraph.guard(): | ||
var_a = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) | ||
var_a.stop_gradient = False | ||
|
||
var_b = var_a**2 | ||
|
||
var_c = var_b**2 | ||
self.inplace_api_processing(var_b) | ||
var_c = paddle.cast(var_c, "float32") | ||
|
||
loss = paddle.nn.functional.relu(var_c) | ||
with self.assertRaisesRegex( | ||
RuntimeError, | ||
f"received tensor_version:{3} != wrapper_version_snapshot:{0}", | ||
): | ||
loss.backward() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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.
目前有inplace版本
paddle.transpose_
此外,不建议在该API中使用索引语法实现赋值,会带来解析索引的耗时,此前使用transpose + index_put的逻辑,本质上是已经根据该场景解析过后决定了要调用哪些API
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.
1.目前paddle文档上没有paddle.transpose_
2.使用paddle.transpose_实现会有inplace_version跳变问题,inplace_version貌似在python端只能增不能减,所以我更改了一部分version相关测试