-
Notifications
You must be signed in to change notification settings - Fork 55
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 inference_step #38
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,7 +241,26 @@ def forward( | |
captions: Optional[TensorType["b", "seq"]] = None, | ||
output_hidden_states: bool = False, | ||
input_embeddings: TensorType["b", "s", "d"] = None, | ||
inference = False | ||
) -> ModelOutput: | ||
if inference is True: | ||
input_embeddings = self.image_prefix(images) | ||
asks = [self.tokenizer.encode('Describe the painting:')] * len(images) | ||
word_embeddings = self.word_embedding(torch.LongTensor(asks).to(self.device)) | ||
input_embeddings = torch.cat( | ||
( | ||
input_embeddings, | ||
word_embeddings[:, : -input_embeddings.shape[1], :], | ||
), # remove padding in the word embedding before concatenating | ||
dim=1, | ||
) | ||
return self.generate( | ||
embeddings = input_embeddings, | ||
max_steps = 6, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 6 sampling steps might be a bit short in general. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest putting hardcoded asks, max_steps, temperature, and top_k into config.py as a dictionary. |
||
temperature = 0.7, | ||
top_k = 0, | ||
) | ||
|
||
assert captions is not None, "Must provide captions in training" | ||
assert any([i is not None for i in [images, input_embeddings]]) and not all( | ||
[i is not None for i in [images, input_embeddings]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the hardcoded instruction here, since not all images are paintings. For the purpose of this codepath I would prefer not to use any instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I write this just because the example :)