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

Integrate Updates to BeamSearchScorer #617

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

sramshetty
Copy link
Contributor

CoCa generate() fails on transformers>=4.31.0 due to fixes in BeamSearchScorer.

Specifically, the following snippet:

model, _, transform = open_clip.create_model_and_transforms(
  model_name="coca_ViT-L-14",
  pretrained="mscoco_finetuned_laion2B-s13B-b90k"
)
PIL_image = Image.open(im_path).convert("RGB")

im = transform(PIL_image).unsqueeze(0)
with torch.no_grad(), torch.cuda.amp.autocast():
  generated = model.generate(im)

results in:

in _generate_beamsearch(self, image_inputs, pad_token_id, eos_token_id, sot_token_id, num_beams, num_beam_groups, min_seq_len, stopping_criteria, logit_processor, logit_warper)
    329 
    330         if num_beams * batch_size != batch_beam_size:
--> 331             raise ValueError(
    332                 f"Batch dimension of `input_ids` should be {num_beams * batch_size}, but is {batch_beam_size}."
    333             )

ValueError: Batch dimension of `input_ids` should be 18, but is 6.

This PR just ports over their changes in generation utils.

@rwightman
Copy link
Collaborator

@sramshetty will previous releases (but still somewhat recent) ver of transformers fail with this?

@sramshetty
Copy link
Contributor Author

@rwightman I was able to get it working by downgrading to transformers==4.30.0. The changes were introduced in 4.31.0, so I suspect any version before that would also work, but haven't verified that.

@rwightman rwightman merged commit 91b7b51 into mlfoundations:main Sep 23, 2023
5 checks passed
Interpause pushed a commit to Interpause/open_clip that referenced this pull request May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants