Skip to content
Merged
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
2 changes: 1 addition & 1 deletion llmc/compression/token_reduction/divprune.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def wrapper(self, *args, **kwargs):
token_indices = input_ids[0][attention_mask[0]] == IMAGE_TOKEN_INDEX
pruning_paras['image_token_start_index'] = torch.where(token_indices)[
0
].item()
][0].item()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If token_indices contains no True values, torch.where(token_indices)[0] will be an empty tensor. Accessing [0] on this empty tensor will raise an IndexError. Consider checking for this case and raising a more informative ValueError.

found_indices = torch.where(token_indices)[0]
if not found_indices.numel():
    raise ValueError("IMAGE_TOKEN_INDEX not found in input_ids, cannot perform DivPrune.")
pruning_paras['image_token_start_index'] = found_indices[0].item()


outputs = fn(*args, **kwargs)

Expand Down