Skip to content

Add argument to children to yield the name of the modules#941

Merged
apaszke merged 9 commits intopytorch:masterfrom
fmassa:named_children
Mar 24, 2017
Merged

Add argument to children to yield the name of the modules#941
apaszke merged 9 commits intopytorch:masterfrom
fmassa:named_children

Conversation

@fmassa
Copy link
Copy Markdown
Member

@fmassa fmassa commented Mar 6, 2017

Fixes #864.

Note that I'm not sure we should add the same option to .modules(), as the top-most model don't have a name.

@apaszke
Copy link
Copy Markdown
Contributor

apaszke commented Mar 6, 2017

I guess we could return an empty name for it.

@fmassa
Copy link
Copy Markdown
Member Author

fmassa commented Mar 6, 2017

Ok, let me add it to modules as well.

@fmassa
Copy link
Copy Markdown
Member Author

fmassa commented Mar 6, 2017

Pushed a version for the .modules() as well. Will add some tests tomorrow.

@colesbury
Copy link
Copy Markdown
Member

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

@fmassa
Copy link
Copy Markdown
Member Author

fmassa commented Mar 7, 2017

On the one hand, I didn't like the extra complexity that was added into .modules() only to support returning the names of the modules. On the other hand, I fell that adding an extra function with almost the same functionality as another one (just adding a new return value) is a bit redundant.
But I'm glad to change it if you prefer otherwise.

@pytorchbot pytorchbot added ready for review (this tag is deprecated) All PRs are ready for review unless they are draft, WIP, or have undismissed requested changes and removed requested changes labels Mar 23, 2017
@fmassa
Copy link
Copy Markdown
Member Author

fmassa commented Mar 23, 2017

@apaszke added named_module and named_children, docs and a test.

@pytorchbot pytorchbot added requested changes and removed ready for review (this tag is deprecated) All PRs are ready for review unless they are draft, WIP, or have undismissed requested changes labels Mar 23, 2017
Comment thread torch/nn/modules/module.py Outdated

Example:
>>> for name, module in model.named_children():
>>> if name in PRINT_LIST:

This comment was marked as off-topic.

@@ -340,14 +340,45 @@ def parameters(self, memo=None):
yield p

def children(self):

This comment was marked as off-topic.

Comment thread torch/nn/modules/module.py Outdated
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.

This comment was marked as off-topic.

Comment thread test/test_nn.py
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.

Add tests for children and named_children, and reuse code between functions
@fmassa
Copy link
Copy Markdown
Member Author

fmassa commented Mar 24, 2017

@apaszke addressed your comments.

Comment thread torch/nn/modules/module.py Outdated
if prefix:
submodule_prefix = prefix + '.' + name
else:
submodule_prefix = name

This comment was marked as off-topic.

This comment was marked as off-topic.

Comment thread test/test_nn.py
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.

@apaszke apaszke merged commit dd89339 into pytorch:master Mar 24, 2017
@fmassa fmassa deleted the named_children branch March 24, 2017 19:02
jjsjann123 pushed a commit to jjsjann123/pytorch that referenced this pull request Aug 5, 2021
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.
zhuhong61 pushed a commit to zhuhong61/pytorch that referenced this pull request Jun 8, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants