Add argument to children to yield the name of the modules#941
Add argument to children to yield the name of the modules#941apaszke merged 9 commits intopytorch:masterfrom
Conversation
|
I guess we could return an empty name for it. |
|
Ok, let me add it to |
|
Pushed a version for the |
|
I don't think changing the return type based on a boolean arg is a good idea. Maybe it would be better to put these as separate functions: childrens_dict() and modules_dict |
|
On the one hand, I didn't like the extra complexity that was added into |
|
@apaszke added |
|
|
||
| Example: | ||
| >>> for name, module in model.named_children(): | ||
| >>> if name in PRINT_LIST: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| @@ -340,14 +340,45 @@ def parameters(self, memo=None): | |||
| yield p | |||
|
|
|||
| def children(self): | |||
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| prefix = [] | ||
| if self not in memo: | ||
| memo.add(self) | ||
| yield '.'.join(prefix), self |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| block.add_module('linear2', l2) | ||
| n = Net() | ||
| s = nn.Sequential(n, n, n, n) | ||
| self.assertEqual(list(s.named_modules()), [('', s), ('0', n), ('0.l1', l), |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Add tests for children and named_children, and reuse code between functions
|
@apaszke addressed your comments. |
| if prefix: | ||
| submodule_prefix = prefix + '.' + name | ||
| else: | ||
| submodule_prefix = name |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| self.assertEqual(num_params(n), 3) | ||
| self.assertEqual(num_params(s), 3) | ||
|
|
||
| def test_children(self): |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Generate predicates based on reference tensors. Be more aggressive on single indexing into iteration domains comprising only of merges. Add new predicate method to unswitch predicates.
* add dependencies for rocm5.0 Signed-off-by: Kyle Chen <kylechen@amd.com> * add dependencies for rocm5.0 Signed-off-by: Kyle Chen <kylechen@amd.com> * add dependencies for rocm5.0 Signed-off-by: Kyle Chen <kylechen@amd.com> * update build_rocm.sh for gfx90a and gfx1030 Signed-off-by: Kyle Chen <kylechen@amd.com> * update build_rocm.sh for gfx90a and gfx1030 Signed-off-by: Kyle Chen <kylechen@amd.com> * update build_rocm.sh for rocm5.0 Signed-off-by: Kyle Chen <kylechen@amd.com> * rebase from upstream main * Revert "add dependencies for rocm5.0" This reverts commit 678ff342c9779d90878719bac58d1b744afc3250. * add amdgpu version for rocm5.0 Signed-off-by: Kyle Chen <kylechen@amd.com>
Fixes #864.
Note that I'm not sure we should add the same option to
.modules(), as the top-most model don't have aname.