code: def test_dl_attr_with_input_roles(self, input_roles) -> None:
      n_inputs = len(input_roles)
      n_forward_inputs = sum(
          1 for r in input_roles if r != InputRole.no_forward
      )
      n_attr_inputs = sum(
          1 for r in input_roles if r == InputRole.need_attr
      )
  
      def reduce(accum, cur_output, cur_inputs):
          # all inputs from dataloader should be given to reduce
          self.assertEqual(len(cur_inputs), n_inputs)
  
          return (
              cur_output
              if accum is None
              else torch.cat([accum, cur_output])
          )
  
      def forward(*forward_inputs):
          # inputs of InputRole.no_forward should not be passed to forward
          self.assertEqual(len(forward_inputs), n_forward_inputs)
          return sum_forward(*forward_inputs)
  
      fa = FeatureAblation(forward)
      dl_fa = DataLoaderAttribution(fa)
  
      batch_size = 2
      dataloader = DataLoader(mock_dataset, batch_size=batch_size)
  
      dl_attributions = dl_fa.attribute(
          dataloader,
          input_roles=input_roles,
          reduce=reduce,
      )
  
      # only inputs needs
      self.assertEqual(len(dl_attributions), n_attr_inputs)
  
      # default reduce of DataLoaderAttribution works the same as concat all batches
      attr_list = []
      for batch in dataloader:
          attr_inputs = tuple(
              _
              for _, role in zip(batch, input_roles)
              if role == InputRole.need_attr
          )
          additional_forward_args = tuple(
              _
              for _, role in zip(batch, input_roles)
              if role == InputRole.need_forward
          )
  
          batch_attr = fa.attribute(
              attr_inputs,
              additional_forward_args=additional_forward_args,
          )
          attr_list.append(batch_attr)
  
      expected_attr = tuple(
          torch.cat(feature_attrs, dim=0)
          for feature_attrs in zip(*attr_list)
      )
  
      assertAttributionComparision(self, dl_attributions, expected_attr)
  
imports: import math
  from typing import cast
  from unittest.mock import Mock, patch
  import torch
  from captum.attr._core.dataloader_attr import DataLoaderAttribution, InputRole
  from captum.attr._core.feature_ablation import FeatureAblation
  from parameterized import parameterized
  from tests.helpers.basic import assertAttributionComparision, assertTensorAlmostEqual, BaseTest
  from torch import Tensor
  from torch.utils.data import DataLoader, TensorDataset
label_desc: Use image node_id 5 for calling the Test obj's underlying member method code with example usage: obj.test_dl_attr_with_input_roles(input_roles) and returns: unknown, sum_forward