code: def test_precision_16_clip_gradients(
      mock_clip_grad_norm, clip_val, tmpdir
  ):
      """Ensure that clip gradients is only called if the value is greater than 0."""
      model = BoringModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          enable_progress_bar=False,
          max_epochs=1,
          devices=1,
          precision="16-mixed",
          limit_train_batches=4,
          limit_val_batches=0,
          gradient_clip_val=clip_val,
      )
      trainer.fit(model)
  
      if clip_val > 0:
          mock_clip_grad_norm.assert_called()
      else:
          mock_clip_grad_norm.assert_not_called()
  
file_path: pytorch-lightning/tests/tests_pytorch/models/test_amp.py
imports: import os
  from unittest import mock
  import pytest
  import torch
  from lightning.fabric.plugins.environments import SLURMEnvironment
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from torch.utils.data import DataLoader
  import tests_pytorch.helpers.utils
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 4 for calling a global function with example usage: test_precision_16_clip_gradients(mock_clip_grad_norm, clip_val, tmpdir) without return types