Skip to content

Support deleting a parameter/buffer by name #46886

@vadimkantorov

Description

@vadimkantorov

This is need for some reparametrization code.

Weight norm code uses del module._parameters[name] for that.

Also requested on forum: https://discuss.pytorch.org/t/how-to-unregister-a-parameter-from-a-module/36424 and many other: https://discuss.pytorch.org/t/exclude-parameters-from-model/77238/6 https://discuss.pytorch.org/t/how-to-exclude-parameters-from-model/6151 https://discuss.pytorch.org/t/delete-unregister-a-parameter-in-a-module/66302. Maybe it is a duplicate issue as well? I may have missed it

I used module.register_parameter('weight', None) for that goal (to overwrite an existing parameter with a None one)

Having an explicit/documented method may be useful

cc @albanD @mruberry

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA request for a proper, new feature.module: nnRelated to torch.nnmodule: uxtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions