I want to delete or unregister a parameter in a module by using erase(const Key &key) method in OrderedDict class, but from the result i see no change in the OrderedDict. What is the right way to do this?
void deleteparm(torch::nn::AnyModule & module, const std::string inName){
torch::NoGradGuard no_grad;
std::cout <<"named parameters before erase "<<inName<< ":"<< std::endl;
for (auto& p : module.ptr()->named_parameters(true)) {
    std::cout <<p.key() << std::endl;
    std::cout << p.value().sizes() << std::endl;
}
module.ptr()->named_parameters(true).erase(inName);
//TODO: erase method in CLASS OrderedDict is available online(https://pytorch.org/cppdocs/api/classtorch_1_1_ordered_dict.html#classtorch_1_1_ordered_dict)
// but not in local version: update to nightly build?

std::cout <<"named parameters after erase:" << std::endl;
for (auto& p : module.ptr()->named_parameters(true)) {
    std::cout <<p.key() << std::endl;
    std::cout << p.value().sizes() << std::endl;
}

}
auto conv2D= torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, 3).padding(1));
torch::nn::init::normal_(conv2D.ptr()->weight, 0, 1);//checked
conv2D.ptr()->bias.zero_();//conv2D.bias.zero_();
torch::nn::AnyModule my_module(conv2D);
deleteparm(my_module, "weight");

Result:
named parameters before erase weight:
weight
[512, 512, 3, 3]
bias
[512]
named parameters after erase:
weight
[512, 512, 3, 3]
bias
[512]