docstr: Make sure PyTorch and Apex gradient clipping produce same results
docstr_tok: ["Make","sure","PyTorch","and","Apex","gradient","clipping","produce","same","results"]
code: def test_matches_pytorch(
      self,
      num_params=41,
      dtypes=[torch.float32, torch.float16, torch.float64],
      devices=["cuda", "cpu"],
      max_norm=0.54321,
      norm_type=2.0,
      rtol=1e-3,
      atol=1e-20,
  ):
      """Make sure PyTorch and Apex gradient clipping produce same results"""
  
      # Construct identical sets of parameters
      torch_params, apex_params = make_params(
          num_params,
          dtypes=dtypes,
          devices=devices,
          make_copy=True,
      )
  
      # Apply gradient clipping
      torch_norm = torch.nn.utils.clip_grad_norm_(
          torch_params,
          max_norm,
          norm_type=norm_type,
      )
      apex_norm = clip_grad_norm_(
          apex_params,
          max_norm,
          norm_type=norm_type,
      )
  
      # Make sure PyTorch and Apex get same results
      torch.testing.assert_close(
          apex_norm,
          torch_norm,
          rtol=rtol,
          atol=atol,
          check_dtype=False,
      )
      for torch_p, apex_p in zip(torch_params, apex_params):
          torch.testing.assert_close(
              apex_p,
              torch_p,
              rtol=0,
              atol=0,
          )  # Params should be unaffected
          torch.testing.assert_close(
              apex_p.grad,
              torch_p.grad,
              rtol=rtol,
              atol=atol,
          )
  
file_path: apex/apex/contrib/test/clip_grad/test_clip_grad.py
imports: import random
  import unittest
  import torch
label_desc: Use image node_id 2 for calling the ClipGradNormTest obj's underlying member method code with example usage: obj.test_matches_pytorch(num_params, dtypes, devices, max_norm, norm_type, rtol, atol) without return types