-
Notifications
You must be signed in to change notification settings - Fork 98
[API Compatibility] add torch.nn.ParameterDict -part #831
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
zhwesky2010
merged 2 commits into
PaddlePaddle:master
from
Manfredss:ApiEnhance_parameterdict
Mar 16, 2026
Merged
Changes from all commits
Commits
Show all changes
2 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 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 |
|---|---|---|
|
|
@@ -92,3 +92,164 @@ def test_case_5(): | |
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_6(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict(parameters={ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| result = list(choices) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_7(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict([ | ||
| ('a', nn.Parameter(torch.ones(2, 3))), | ||
| ('b', nn.Parameter(torch.zeros(4))), | ||
| ]) | ||
| result = list(choices) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_8(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({'w': nn.Parameter(torch.ones(2, 3))}) | ||
| result = choices['w'] | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"], check_stop_gradient=False) | ||
|
|
||
|
|
||
| def test_case_9(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({ | ||
| 'a': nn.Parameter(torch.ones(1)), | ||
| 'b': nn.Parameter(torch.ones(2)), | ||
| 'c': nn.Parameter(torch.ones(3)), | ||
| }) | ||
| result = len(choices) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_10(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({ | ||
| 'a': nn.Parameter(torch.ones(1)), | ||
| 'b': nn.Parameter(torch.ones(2)), | ||
| }) | ||
| result = list(choices.keys()) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_11(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| result = list(choices.values()) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"], check_stop_gradient=False) | ||
|
|
||
|
|
||
| def test_case_12(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({'a': nn.Parameter(torch.ones(2))}) | ||
| result = 'a' in choices | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
|
|
||
|
|
||
| def test_case_14(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict(parameters={ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| result = choices['a'] | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"], check_stop_gradient=False) | ||
|
|
||
|
|
||
| def test_case_15(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict(parameters={ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| result = choices['b'] | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"], check_stop_gradient=False) | ||
|
|
||
|
|
||
| def test_case_13(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| choices = nn.ParameterDict({ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| result = choices.pop('a') | ||
|
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支持的话,这个也应该支持下,改paddle吧 |
||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"], check_stop_gradient=False) | ||
|
|
||
|
|
||
| def test_case_16(): | ||
| pytorch_code = textwrap.dedent( | ||
| """ | ||
| import torch.nn as nn | ||
| import torch | ||
| pd1 = nn.ParameterDict({ | ||
| 'a': nn.Parameter(torch.ones(2, 3)), | ||
| 'b': nn.Parameter(torch.zeros(4)), | ||
| }) | ||
| pd2 = nn.ParameterDict(pd1) | ||
| result = list(pd2) | ||
| """ | ||
| ) | ||
| obj.run(pytorch_code, ["result"]) | ||
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.
check_stop_gradient 这个关闭的原因是?