code: def _test_preprocessing_defences_backward(
      get_default_mnist_subset,
      image_dl_estimator,
      device_type,
      preprocessing_defences,
  ):
      (_, _), (x_test_mnist, y_test_mnist) = get_default_mnist_subset
  
      classifier_, _ = image_dl_estimator()
  
      clip_values = (0, 1)
      criterion = nn.CrossEntropyLoss()
      classifier = PyTorchClassifier(
          clip_values=clip_values,
          model=classifier_.model,
          preprocessing_defences=preprocessing_defences,
          loss=criterion,
          input_shape=(1, 28, 28),
          nb_classes=10,
          device_type=device_type,
      )
  
      # The efficient defence-chaining.
      pseudo_gradients = np.random.randn(*x_test_mnist.shape)
      gradients_in_chain = classifier._apply_preprocessing_gradient(
          x_test_mnist, pseudo_gradients
      )
  
      # Apply the same backward pass one by one.
      x = x_test_mnist
      x_intermediates = [x]
      for preprocess in classifier.preprocessing_operations[:-1]:
          x = preprocess(x)[0]
          x_intermediates.append(x)
  
      gradients = pseudo_gradients
      for preprocess, x in zip(
          classifier.preprocessing_operations[::-1],
          x_intermediates[::-1],
      ):
          gradients = preprocess.estimate_gradient(x, gradients)
  
      np.testing.assert_array_almost_equal(
          gradients_in_chain, gradients, decimal=4
      )
  
imports: import numpy
  import pytest
  import torch
  import torch.nn.functional
  import torch.nn
  import torch.optim
  import sklearn.datasets
  from art.estimators.classification.pytorch import PyTorchClassifier
  from art.defences.preprocessor.spatial_smoothing import SpatialSmoothing
  from art.defences.preprocessor.spatial_smoothing_pytorch import SpatialSmoothingPyTorch
  from art.attacks.evasion.fast_gradient import FastGradientMethod
  from art.attacks.evasion.projected_gradient_descent.projected_gradient_descent import ProjectedGradientDescent
  from tests.attacks.utils import backend_test_defended_images
  from tests.utils import ARTTestException
label_desc: Use image node_id 3 for calling a global function with example usage: _test_preprocessing_defences_backward(get_default_mnist_subset, image_dl_estimator, device_type, preprocessing_defences) without return types