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

a initial version of executor #61

Merged
merged 29 commits into from
May 17, 2023
Merged

a initial version of executor #61

merged 29 commits into from
May 17, 2023

Conversation

zhaochenyang20
Copy link
Collaborator

Description

Following the document string, I implement the initial version of ModelExcuctor. However, I have some quick question:

  1. How can we get the "confidence", and where will we use it? Currently, I am just using this as the confidence:
            logits = output[0].float()
            probs = torch.softmax(logits, dim=-1)
            confidence = probs.mean().item()

I think the calculation probs.mean().item() does provide a measure that can be loosely interpreted as the model's confidence in generating the output, but not enough.

The softmax probabilities obtained from the model's output can be seen as an indication of the model's belief or preference for each token in the generated sequence. By taking the average of these probabilities, probs.mean().item() provides a rough estimate of the overall confidence or likelihood of the generated output sequence.

  1. What is auxiliary_info, where will we use it, and how to get it?

References

  • NA

Blocked by

@zhaochenyang20 zhaochenyang20 changed the base branch from main to Eren_debug_tokenizer May 17, 2023 02:34
Base automatically changed from Eren_debug_tokenizer to main May 17, 2023 06:08
Copy link
Collaborator

@viswavi viswavi left a comment

Choose a reason for hiding this comment

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

Seems like we should support batch execution? This can be done in a separate PR if you like

Copy link
Collaborator

@viswavi viswavi left a comment

Choose a reason for hiding this comment

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

Looks good! Only have a few small points for revisino

Comment on lines 42 to 43
else:
output = model.generate(input_ids=encoded_input["input_ids"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we verify that the model in the else case is a transformers.AutoModelForCausalLM?

Suggested change
else:
output = model.generate(input_ids=encoded_input["input_ids"])
elif issubclass(model.__class__, transformers.AutoModelForCausalLM):
output = model.generate(input_ids=encoded_input["input_ids"])
else:
raise ValueError(f"Model class {model.__class__} not supported")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm. I agree with you and actually tried this before. But issubclass(model.__class__, transformers.AutoModelForCausalLM) would fail even for gpt2. 🤔

Copy link
Collaborator Author

@zhaochenyang20 zhaochenyang20 May 17, 2023

Choose a reason for hiding this comment

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

In [3]:     gpt2_model_name = "gpt2"
   ...:     gpt2_model = AutoModelForCausalLM.from_pretrained(gpt2_model_name)
   ...:     gpt2_tokenizer = AutoTokenizer.from_pretrained(gpt2_model_name)

In [4]: model = gpt2_model

In [5]: issubclass(model.__class__, transformers.AutoModelForCausalLM)
Out[5]: False

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, the inherited tree of GPT-2 is:

nn.Module -> PreTrainedModel -> GPT2PreTrainedModel -> GPT2LMHeadModel.

So issubclass(model.__class__, transformers.AutoModelForCausalLM) would fail.

But do we have better methods of type check? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see....if there's no general type that can cover all autoregressive LM models then I think it's fine how you have it now

prompt2model/model_executor/generate.py Outdated Show resolved Hide resolved
tests/model_executor_test.py Show resolved Hide resolved
Comment on lines 69 to 72
if gpt2_tokenizer.pad_token is None:
gpt2_tokenizer.add_special_tokens({"pad_token": "[PAD]"})
gpt2_model.config.pad_token_id = gpt2_model.config.eos_token_id
gpt2_model.config.attention_mask_fn = lambda input_ids: (
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit weird to have this setup done in the test. Can you explain this a little more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just as what happens in #60. Directly use gpt2_tokenizer is not enough.

Using pad_token, but it is not set yet.
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.

prompt2model/model_executor/generate.py Outdated Show resolved Hide resolved
Comment on lines 42 to 43
else:
output = model.generate(input_ids=encoded_input["input_ids"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see....if there's no general type that can cover all autoregressive LM models then I think it's fine how you have it now

@zhaochenyang20 zhaochenyang20 merged commit 3eb208c into main May 17, 2023
@zhaochenyang20 zhaochenyang20 deleted the Eren_executor branch May 17, 2023 17:02
@zhaochenyang20 zhaochenyang20 mentioned this pull request May 18, 2023
11 tasks
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.

3 participants