code: def gradient_norm(model, X, y, K, sw=None):
      if sw is None:
          sw = cp.ones(X.shape[0])
      else:
          sw = cp.atleast_1d(cp.array(sw, dtype=np.float64))
  
      X = cp.array(X, dtype=np.float64)
      y = cp.array(y, dtype=np.float64)
      K = cp.array(K, dtype=np.float64)
      betas = cp.array(
          as_type("cupy", model.dual_coef_), dtype=np.float64
      ).reshape(y.shape)
  
      # initialise to NaN in case below loop has 0 iterations
      grads = cp.full_like(y, np.NAN)
      for i, (beta, target, current_alpha) in enumerate(
          zip(betas.T, y.T, model.alpha)
      ):
          grads[:, i] = 0.0
          grads[:, i] = -cp.dot(K * sw, target)
          grads[:, i] += cp.dot(cp.dot(K * sw, K), beta)
          grads[:, i] += cp.dot(K * current_alpha, beta)
      return linalg.norm(grads)
  
imports: from cuml.testing.utils import as_type
  from hypothesis.extra.numpy import arrays
  from hypothesis import given, settings, assume, strategies
  from sklearn.kernel_ridge import KernelRidge
  import inspect
  import math
  import pytest
  from sklearn.metrics.pairwise import pairwise_kernels
  from cuml.metrics import pairwise_kernels, PAIRWISE_KERNEL_FUNCTIONS
  from cuml import KernelRidge
  from cuml.internals.safe_imports import cpu_only_import
  from cuml.internals.safe_imports import gpu_only_import_from
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 1 for calling a global function with example usage: gradient_norm(model, X, y, K, sw) and returns: linalg