code: def test_lightning_module_configure_gradient_clipping(tmpdir):
      """Test custom gradient clipping inside `configure_gradient_clipping` hook."""
  
      class TestModel(BoringModel):
          has_validated_gradients = False
          custom_gradient_clip_val = 1e-2
  
          def configure_gradient_clipping(
              self,
              optimizer,
              gradient_clip_val,
              gradient_clip_algorithm,
          ):
              assert gradient_clip_val == self.trainer.gradient_clip_val
              assert (
                  gradient_clip_algorithm
                  == self.trainer.gradient_clip_algorithm
              )
  
              for pg in optimizer.param_groups:
                  for p in pg["params"]:
                      p.grad.clamp_(
                          min=0, max=self.custom_gradient_clip_val
                      )
  
      model = TestModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=1,
          limit_val_batches=0,
          gradient_clip_val=1e-4,
      )
      trainer.fit(model)
  
      optimizer = model.optimizers()
      for pg in optimizer.param_groups:
          for p in pg["params"]:
              if p.grad is not None:
                  assert p.grad.min() >= 0
                  assert p.grad.max() <= model.custom_gradient_clip_val
  
imports: import sys
  import weakref
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.fabric import Fabric
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_1_13, _TORCH_GREATER_EQUAL_2_0
  from lightning.pytorch import LightningModule, Trainer
  from lightning.pytorch.core.module import _TrainerFabricShim
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers import TensorBoardLogger
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from torch import nn
  from torch.optim import SGD, Adam
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 13 for calling a global function with example usage: test_lightning_module_configure_gradient_clipping(tmpdir) without return types