code: def test_parameter_rollback_ctx(self):
      # Test that only unfiltered parameters get rolled back
      a = self.module.a.detach().clone()
      b = self.module.b.detach().clone()
      c = self.module.c.detach().clone()
      parameters = dict(self.module.named_parameters())
      with parameter_rollback_ctx(
          parameters, dtype=torch.float16
      ) as ckpt:
          for (
              tnsr,
              _,
              __,
          ) in ckpt.values():  # test whether dtype is obeyed
              self.assertEqual(torch.float16, tnsr.dtype)
  
          self.module.a.data[...] = 0
          self.module.b.data[...] = 0
          self.module.c.data[...] = 0
          del ckpt[
              "c"
          ]  # test whether changes to checkpoint dict are respected
  
      self.assertTrue(self.module.a.equal(a))
      self.assertTrue(self.module.b.equal(b))
      self.assertTrue(self.module.c.eq(0).all())
  
      # Test rolling back to a user-provided checkpoint
      with parameter_rollback_ctx(
          parameters,
          checkpoint={"c": TensorCheckpoint(c, c.device, c.dtype)},
      ):
          pass
      self.assertTrue(self.module.c.equal(c))
  
file_path: botorch/test/utils/test_context_managers.py
imports: from __future__ import annotations
  from string import ascii_lowercase
  import torch
  from botorch.utils.context_managers import delattr_ctx, module_rollback_ctx, parameter_rollback_ctx, requires_grad_ctx, TensorCheckpoint, zero_grad_ctx
  from botorch.utils.testing import BotorchTestCase
  from torch.nn import Module, Parameter
label_desc: Use image node_id 4 for calling the TestContextManagers obj's underlying member method code with example usage: obj.test_parameter_rollback_ctx() without return types