docstr: Test that it is possible to add and remove parametrizations on buffers
docstr_tok: ["Test","that","it","is","possible","to","add","and","remove","parametrizations","on","buffers"]
code: def test_register_and_remove_buffer_parametrization(self):
      r"""Test that it is possible to add and remove parametrizations on buffers"""
  
      # Define a couple vector parametrizations
      class FirstZero(nn.Module):
          def forward(self, x):
              return torch.cat([x.new_zeros(1), x[1:]])
  
      class LastZero(nn.Module):
          def forward(self, x):
              return torch.cat([x[:-1], x.new_zeros(1)])
  
      model = nn.Linear(8, 8)
  
      # Instantiate parametrizations on buffers. It should work as expected
      delattr(model, "bias")
      model.register_buffer("bias", torch.ones(8))
      parametrize.register_parametrization(model, "bias", FirstZero())
      parametrize.register_parametrization(model, "bias", LastZero())
      self.assertTrue(parametrize.is_parametrized(model))
      self.assertTrue(parametrize.is_parametrized(model, "bias"))
      self.assertEqual(model.bias[0].item(), 0.0)
      self.assertEqual(model.bias[-1].item(), 0.0)
      self.assertTrue((model.bias[1:-1] == torch.ones(6)).all())
      self.assertEqual(len(list(model.parameters())), 1)
  
      # Remove parametrizations on buffers. It should work as expected
      parametrize.remove_parametrizations(
          model, "bias", leave_parametrized=True
      )
      self.assertFalse(parametrize.is_parametrized(model))
      self.assertFalse(parametrize.is_parametrized(model, "bias"))
      self.assertEqual(model.bias[0].item(), 0.0)
      self.assertEqual(model.bias[-1].item(), 0.0)
      self.assertTrue((model.bias[1:-1] == torch.ones(6)).all())
      self.assertEqual(len(list(model.parameters())), 1)
  
imports: from copy import deepcopy
  from itertools import product
  import pickle
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.nn.init
  import torch.nn.utils.parametrize
  from torch.nn import Parameter
  from torch.testing._internal.common_utils import run_tests, skipIfNoLapack, TemporaryFileName, instantiate_parametrized_tests, set_default_dtype
  from torch.testing._internal.common_device_type import instantiate_device_type_tests
  from torch.testing._internal.common_cuda import TEST_MULTIGPU
  from torch.testing._internal.common_nn import NNTestCase
  from torch.testing._internal.common_utils import gradcheck
label_desc: Use image node_id 3 for calling the TestNNParametrization obj's underlying member method code with example usage: obj.test_register_and_remove_buffer_parametrization() and returns: torch, torch