Skip to content

Commit c29155b

Browse files
aobo-yfacebook-github-bot
authored andcommitted
improve error msg of invalid input types (#1083)
Summary: Discussed in #1077 (comment) , improving the error message of invalid `inputs` to tell the two types we allow: `Tensor` and `tuple[Tensor]` Pull Request resolved: #1083 Reviewed By: vivekmig Differential Revision: D41795064 Pulled By: aobo-y fbshipit-source-id: 16370e747d08ec33070fc039d9ee2b6dde033cc8
1 parent 4de6602 commit c29155b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

captum/_utils/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ def _format_tensor_into_tuples(
175175
if inputs is None:
176176
return None
177177
if not isinstance(inputs, tuple):
178-
assert isinstance(
179-
inputs, torch.Tensor
180-
), "`inputs` must have type " "torch.Tensor but {} found: ".format(type(inputs))
178+
assert isinstance(inputs, torch.Tensor), (
179+
"`inputs` must be a torch.Tensor or a tuple[torch.Tensor] "
180+
f"but found: {type(inputs)}"
181+
)
181182
inputs = (inputs,)
182183
return inputs
183184

0 commit comments

Comments
 (0)