Skip to content

Do not use deepcopy to copy nn.modules (including entire models) #2177

Closed
@mikekgfb

Description

@mikekgfb

copy.deepcopy is not defined for nn.module() and does not reliably copy an nn.module hierrchy, such as a model or partial model. Our tutorials should using copy.deepcopy() as this will induce our users to make incorrect use of the primitive.

Please update https://pytorch.org/tutorials/beginner/transformer_tutorial.html and other tutorials to avoid the use. Recommended way for snapshotting is to use torch.save() for trained models. to create multiple clones of an untrained model, create multiple copies from first principles from the model architectural parameters.

cc @pytorch/team-text-core @Nayef211

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions