Skip to main content

PyTorch apply

August 19, 2021
1 min read

A function that applies a given function to all submodules of an nn.Module, similar to map.

It traverses modules using postorder traversal, prioritizing the left child.

def do_something(m):
# do something!
return m
model = #something very complex model
result = model.apply(print_module)
Loading comments...