Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions captum/attr/_core/llm_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,10 @@ def attribute(
if not gen_args:
gen_args = DEFAULT_GEN_ARGS

model_inp = self._format_model_input(inp.to_model_input())
output_tokens = self.model.generate(model_inp, **gen_args)
target_tokens = output_tokens[0][model_inp.size(1) :]
with torch.no_grad():
model_inp = self._format_model_input(inp.to_model_input())
output_tokens = self.model.generate(model_inp, **gen_args)
target_tokens = output_tokens[0][model_inp.size(1) :]
else:
assert gen_args is None, "gen_args must be None when target is given"

Expand Down Expand Up @@ -605,7 +606,7 @@ def attribute(
cur_target_idx,
),
**kwargs,
)
).detach()
attr = cast(Tensor, attr)

# will have the attr for previous output tokens
Expand Down