code: def test_zero_grad_ctx(self):
      params = (Parameter(torch.rand(1)), Parameter(torch.rand(1)))
      sum(params).backward()
      with zero_grad_ctx(
          params, zero_on_enter=False, zero_on_exit=True
      ):
          self.assertFalse(any(x.grad.eq(0).all() for x in params))
      self.assertTrue(all(x.grad.eq(0).all() for x in params))
  
      sum(params).backward()
      with zero_grad_ctx(
          params, zero_on_enter=True, zero_on_exit=False
      ):
          self.assertTrue(all(x.grad.eq(0).all() for x in params))
          sum(params).backward()
      self.assertFalse(any(x.grad.eq(0).all() for x in params))
  
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 6 for calling the TestContextManagers obj's underlying member method code with example usage: obj.test_zero_grad_ctx() without return types