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 inference_step #38

Open
wants to merge 1 commit into
base: master
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
19 changes: 19 additions & 0 deletions magma/magma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

@CoEich CoEich Nov 28, 2022

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.

Copy link
Author

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 :)

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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think 6 sampling steps might be a bit short in general.

Copy link
Author

Choose a reason for hiding this comment

The 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.
do you think it would be better?

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]]
Expand Down