code: def test_ridge_regression_requires_grad(
      reg_lambda, use_woodbury, scale, bias
  ):
      # Numpy
      num_classes = 3
      embeddings_np = np.random.randn(5, 7).astype(np.float32)
      targets_np = np.random.randint(0, num_classes, size=(5,))
  
      # PyTorch
      embeddings_th = torch.as_tensor(embeddings_np).requires_grad_()
      targets_th = torch.as_tensor(targets_np)
      model = MetaLinear(7, 3, bias=bias)
  
      solution = ridge_regression(
          embeddings_th,
          targets_th,
          reg_lambda,
          num_classes,
          use_woodbury=use_woodbury,
          scale=scale,
          bias=bias,
      )
      params = OrderedDict([("weight", solution.weight)])
      if bias:
          params["bias"] = solution.bias
  
      # Compute loss on test/query samples
      test_embeddings = torch.randn(11, 7)
      test_logits = model(test_embeddings, params=params)
      test_targets = torch.randint(num_classes, size=(11,))
      loss = F.cross_entropy(test_logits, test_targets)
  
      # Backpropagation
      loss.backward()
  
      assert embeddings_th.grad is not None
  
file_path: pytorch-meta/torchmeta/tests/utils/test_r2d2.py
imports: import pytest
  import numpy
  import torch
  import torch.nn.functional
  from collections import OrderedDict
  from torchmeta.modules import MetaLinear
  from torchmeta.utils.r2d2 import ridge_regression
label_desc: Use image node_id 2 for calling a global function with example usage: test_ridge_regression_requires_grad(reg_lambda, use_woodbury, scale, bias) without return types