Skip to content

TCAV for tiny-bert model report AssertionError: inputs must have type torch.Tensor but <class 'list'> found: error happened #1066

@joshua-xia

Description

@joshua-xia

🐛 Bug

when I using TCAV on tiny-bert model, the AssertionError: inputs must have type torch.Tensor but <class 'list'> found: error happened

To Reproduce

Steps to reproduce the behavior:

  1. The model need three parameters to do predict:
    def predict(model, dataloader):
    model.eval()
    for idxs, input_ids, input_mask, segment_ids in dataloader:
    with torch.no_grad():
    logits = model(input_ids, segment_ids, input_mask, labels=None)

  2. so the dataloader feed three parameters

  3. when invoke compute_cavs, the following error happened:
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/concept/_core/tcav.py", line 511, in compute_cavs
    self.generate_activations(concept_layers)
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/concept/_core/tcav.py", line 388, in generate_activations
    self.generate_activation(concept_layers[concept], concept)
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/concept/_core/tcav.py", line 360, in generate_activation
    activations = layer_act.attribute.wrapped( # type: ignore
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/attr/_core/layer/layer_activation.py", line 118, in attribute
    layer_eval = _forward_layer_eval(
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/gradient.py", line 182, in _forward_layer_eval
    return _forward_layer_eval_with_neuron_grads(
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/gradient.py", line 445, in _forward_layer_eval_with_neuron_grads
    saved_layer = _forward_layer_distributed_eval(
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/gradient.py", line 294, in _forward_layer_distributed_eval
    output = _run_forward(
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/common.py", line 455, in _run_forward
    inputs = _format_input(inputs)
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/common.py", line 167, in _format_input
    return _format_tensor_into_tuples(inputs)
    File "/devtools/anaconda3/envs/xai-env/lib/python3.8/site-packages/captum/_utils/common.py", line 159, in _format_tensor_into_tuples
    assert isinstance(
    AssertionError: inputs must have type torch.Tensor but <class 'list'> found:

Expected behavior

get the cavs score correctly

Environment

Describe the environment used for Captum

torch                         1.12.1
captum                        0.5.0

## Additional context

<!-- Add any other context about the problem here. -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions