-
Notifications
You must be signed in to change notification settings - Fork 98
[API Compatibility No.246, 247] align torch.Tensor.retain_grad And torch.Tensor.sparse_mask with ChangePrefix -part #848
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
Changes from all commits
8f836f1
3338b47
d3bfa1c
baa450d
a061c9a
3fa5c47
a4c9316
7357cf5
9d7bf12
7fa8154
5eee1cc
74be5ab
ddc87b2
9198d4a
e797526
da2c02f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import textwrap | ||
|
|
||
| from apibase import APIBase | ||
|
|
||
| obj = APIBase("torch.tensor.sparse_mask") | ||
|
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. torch.Tensor.sparse_mask 文件命名为
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. 已改 |
||
|
|
||
|
|
||
| def test_case_1(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch | ||
| dense = torch.tensor([[1, 2, 3], [4, 5, 6]]) | ||
| indices = torch.tensor([[0, 1], [1, 2]]) | ||
| values = torch.tensor([0, 0]) | ||
| mask = torch.sparse_coo_tensor(indices, values, dense.size()) | ||
| result_sparse = dense.sparse_mask(mask) | ||
| result = result_sparse.to_dense() | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_2(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch | ||
| dense = torch.tensor([[5, 0, 3], [0, 8, 2]]) | ||
| indices = torch.tensor([[0, 1], [1, 0]]) # 提取 (0,1)=0 和 (1,0)=0 | ||
| values = torch.tensor([1, 1]) | ||
| mask = torch.sparse_coo_tensor(indices, values, dense.size()) | ||
| result_sparse = dense.sparse_mask(mask) | ||
| result = result_sparse.to_dense() | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_3(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch | ||
| dense = torch.arange(24).reshape(2, 3, 4) | ||
| indices = torch.tensor([[0, 1], [1, 2], [3, 0]]) # 提取两个位置 | ||
| values = torch.tensor([-1, -1]) | ||
| mask = torch.sparse_coo_tensor(indices, values, dense.size()) | ||
| result_sparse = dense.sparse_mask(mask) | ||
|
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. 使用关键字测一下
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.
|
||
| result = result_sparse.to_dense() | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_4(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch | ||
| dense = torch.tensor([[7, 8, 9], [10, 11, 12]]) | ||
| indices = torch.tensor([[0, 1], [0, 2]]) | ||
| values = torch.tensor([1, 1]) | ||
| mask = torch.sparse_coo_tensor(indices, values, dense.size()) | ||
| result_sparse = dense.sparse_mask(mask=mask) | ||
| result = result_sparse.to_dense() | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
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.
这个没有对应的单测,你需要补一下单测
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.
好的