code: def assert_close(x, y, atol=None, rtol=None, err_msg=""):
      import numpy as np
      import torch
  
      # canonicalize arguments to be tensors
      if not isinstance(x, torch.Tensor):
          x = torch.tensor(x)
      if not isinstance(y, torch.Tensor):
          y = torch.tensor(y)
      # absolute tolerance
      if atol is None:
          atol = 1e-2
      atol = atol(x.dtype) if callable(atol) else atol
      # relative tolerance hook
      if rtol is None:
          rtol = 0.0
      rtol = rtol(x.dtype) if callable(rtol) else rtol
      # we use numpy instead of pytorch
      # as it seems more memory efficient
      # pytorch tends to oom on large tensors
      if isinstance(x, torch.Tensor):
          if x.dtype == torch.bfloat16:
              x = x.float()
          x = x.cpu().detach().numpy()
      if isinstance(y, torch.Tensor):
          if y.dtype == torch.bfloat16:
              y = y.float()
          y = y.cpu().detach().numpy()
      # we handle size==1 case separately as we can
      # provide better error message there
      if x.size > 1 or y.size > 1:
          np.testing.assert_allclose(
              x, y, atol=atol, rtol=rtol, equal_nan=True
          )
          return
      if not np.allclose(x, y, atol=atol, rtol=rtol):
          raise AssertionError(
              f"{err_msg} {x} is not close to {y} (atol={atol}, rtol={rtol})"
          )
  
imports: import functools
  import os
  import subprocess
  import sys
  from contextlib import contextmanager
  from typing import Any, Dict, List
  from .None import language
label_desc: Use image node_id 4 for calling a global function with example usage: assert_close(x, y, atol, rtol, err_msg) without return types