code: def test_saliency_mapping():
      """Test computing a saliency map."""
      n_tasks = 3
      n_features = 5
      pytorch_model = torch.nn.Sequential(
          torch.nn.Linear(n_features, 20),
          torch.nn.Tanh(),
          torch.nn.Linear(20, n_tasks),
      )
      model = dc.models.TorchModel(
          pytorch_model, dc.models.losses.L2Loss()
      )
      x = np.random.random(n_features)
      s = model.compute_saliency(x)
      assert s.shape[0] == n_tasks
      assert s.shape[1] == n_features
  
      # Take a tiny step in the direction of s and see if the output changes by
      # the expected amount.
  
      delta = 0.01
      for task in range(n_tasks):
          norm = np.sqrt(np.sum(s[task] ** 2))
          step = 0.5 * delta / norm
          pred1 = model.predict_on_batch(
              (x + s[task] * step).reshape((1, n_features))
          ).flatten()
          pred2 = model.predict_on_batch(
              (x - s[task] * step).reshape((1, n_features))
          ).flatten()
          assert np.allclose(
              pred1[task], (pred2 + norm * delta)[task], atol=1e-6
          )
  
file_path: deepchem/deepchem/models/tests/test_torch_model.py
imports: import os
  import pytest
  import deepchem
  import numpy
  import math
  import unittest
label_desc: Use image node_id 8 for calling a global function with example usage: test_saliency_mapping() without return types