code: def test_pytorch_embedding_similarity(
      trainable_emd, grads_shape, sparse
  ):
      """Test GradientSimilarity explainer correctly handles sparsity and non-trainable layers for pytorch.
  
      Tests that the `pytorch` embedding layers work as expected and that layers marked as
      non-trainable are not included in the gradients.
      """
  
      model = torch.nn.Sequential(
          torch.nn.Embedding(10, 4, 5, sparse=sparse),
          torch.nn.Flatten(),
          torch.nn.LazyLinear(1),
      )
  
      model[0].weight.requires_grad = trainable_emd
  
      X = torch.randint(0, 10, (1, 5))
      Y = torch.randint(0, 10, (1, 1), dtype=torch.float32)
      loss_fn = torch.nn.MSELoss()
      pt_grads = _PytorchBackend.get_grads(model, X, Y, loss_fn)
      assert pt_grads.shape == grads_shape
  
file_path: alibi/alibi/explainers/tests/test_simiarlity/test_backends.py
imports: import pytest
  import torch
  import numpy
  import tensorflow
  from alibi.explainers.similarity.backends.tensorflow.base import _TensorFlowBackend
  from alibi.explainers.similarity.backends.pytorch.base import _PytorchBackend
label_desc: Use image node_id 3 for calling a global function with example usage: test_pytorch_embedding_similarity(trainable_emd, grads_shape, sparse) without return types