Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tensor Dimension Mismatch in Padding Operation for Batch Processing #254

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions examples/batch_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
img_paths = ['examples/image1.webp',
'examples/image1.webp']
questions = ['Please describe this image in detail.',
'What is the text in this images?']
'What is the text in this images? Please describe it in detail.']

assert len(img_paths) == len(questions)

Expand Down Expand Up @@ -66,7 +66,8 @@
batch_inputs, batch_masks, batch_atten_masks = [], [], []
for inputs, im_mask in zip(inputs_list, masks_list):
if im_mask.shape[1] < max_len:
pad_embeds = torch.cat([pad_embed]*(max_len - im_mask.shape[1]))
pad_length = max_len - im_mask.shape[1]
pad_embeds = pad_embed.repeat(1, pad_length, 1)
pad_masks = torch.tensor([0]*(max_len - im_mask.shape[1])).unsqueeze(0).cuda()
inputs = torch.cat([pad_embeds, inputs['inputs_embeds']], dim=1)
atten_masks = torch.cat([pad_masks, torch.ones_like(im_mask)], dim=1)
Expand Down