def test_grad_ignore_value_():
    """
    **Overview**:
        Test function of grad ignore clip.
    """
    # batch size=4, action=32
    B, N = 4, 32
    # Set clip_value as 0.5.
    clip_value = 0.5
    # Generate logit and label.
    logit = torch.randn(B, N).requires_grad_(True)
    label = torch.randn(B, N)
    # Define criterion and compute loss.
    criterion = torch.nn.MSELoss()
    output = criterion(logit, label)
    # Loss backward and compute gradients.
    output.backward()
    # Set a gradient that exceeds the threshold.
    logit.grad[0] = 0.6
    # Clip the gradient
    grad_ignore_value(logit, clip_value)
    # Assert that all gradients are clipped to zero.
    assert isinstance(logit.grad, torch.Tensor)
    for g in logit.grad:
        assert (g == 0).all()

    **Overview**:
        Test function of grad ignore clip.
    
chapter7_tricks/grad_ignore.py