docstr: tests `influence._utils.common._functional_call` for a simple case where the
  model and loss are linear regression and squared error.  `method` can either be
  `_custom_functional_call`, which uses the custom implementation that is used
  if pytorch does not provide one, or `_functional_call`, which uses a pytorch
  implementation if available.
docstr_tok: ["tests","`","influence._utils.common._functional_call","`","for","a","simple","case","where","the","model","and","loss","are","linear","regression","and","squared","error",".","`","method","`","can","either","be","`","_custom_functional_call","`",",","which","uses","the","custom","implementation","that","is","used","if","pytorch","does","not","provide","one",",","or","`","_functional_call","`",",","which","uses","a","pytorch","implementation","if","available","."]
code: def test_functional_call(self, method):
      """
      tests `influence._utils.common._functional_call` for a simple case where the
      model and loss are linear regression and squared error.  `method` can either be
      `_custom_functional_call`, which uses the custom implementation that is used
      if pytorch does not provide one, or `_functional_call`, which uses a pytorch
      implementation if available.
      """
      # get linear model and a batch
      batch_size = 25
      num_features = 5
      batch_samples = torch.normal(0, 1, (batch_size, num_features))
      batch_labels = torch.normal(0, 1, (batch_size, 1))
      net = Linear(num_features)
  
      # get the analytical gradient wrt to model parameters
      batch_predictions = net(batch_samples)
      analytical_grad = 2 * torch.sum(
          (batch_predictions - batch_labels) * batch_samples, dim=0
      )
  
      # get gradient as computed using `_functional_call`
      param = net.linear.weight.detach().clone().requires_grad_(True)
      _batch_predictions = method(
          net, {"linear.weight": param}, (batch_samples,)
      )
      loss = torch.sum((_batch_predictions - batch_labels) ** 2)
      actual_grad = torch.autograd.grad(loss, param)[0][0]
  
      # they should be the same
      assertTensorAlmostEqual(
          self, actual_grad, analytical_grad, delta=1e-3, mode="max"
      )
  
file_path: captum/tests/influence/_core/test_naive_influence.py
imports: import tempfile
  from typing import Callable, List, Tuple, Union
  import torch
  import torch.nn
  from captum._utils.common import _parse_version
  from captum.influence._core.influence_function import NaiveInfluenceFunction
  from captum.influence._utils.common import _custom_functional_call, _flatten_params, _functional_call, _unflatten_params_factory
  from parameterized import parameterized
  from tests.helpers.basic import assertTensorAlmostEqual, assertTensorTuplesAlmostEqual, BaseTest
  from tests.influence._utils.common import _format_batch_into_tuple, build_test_name_func, DataInfluenceConstructor, ExplicitDataset, get_random_model_and_data, Linear, UnpackDataset, USE_GPU_LIST
  from torch.utils.data import DataLoader
label_desc: Use image node_id 3 for calling the TestNaiveInfluence obj's underlying member method code with example usage: obj.test_functional_call(method) without return types