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

Increment start_pos by encoded size in generate #1462

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nlpfollower
Copy link

Hi, seems like the size of encoded should contribute to start_pos on each turn. Without this change, I'm getting inconsistent generations, as the model looks up kv from the middle of the cache, rather than the end. This also feels like a natural place to increment start_pos, since right after we also increment by the size of generated token_tensor.

Copy link

pytorch-bot bot commented Jan 16, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/1462

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit e238a46 with merge base 654bb03 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link

Hi @nlpfollower!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@Jack-Khuu
Copy link
Contributor

I'd love to look into this a bit more

Can you share a repro?

@nlpfollower
Copy link
Author

Certainly. I run the chat feature for Llama3.1-8B-Instruct with a command looking like this:
python3 torchchat.py chat --checkpoint-path path/to/Llama3.1-8B-Instruct/consolidated.0.pth --tokenizer-path path/to/Llama3.1-8B-Instruct/tokenizer.model --params-path torchchat/model_params/Meta-Llama-3.1-8B.json

And I've tried the following prompting [main branch]:

Do you want to enter a system prompt? Enter y for yes and anything else for no. 
y
What is your system prompt? 
You are a helpful assistant.
User: Can you remember this word for me: "berryjuice"? Reply briefly.
Model: Berryjuice
User: What word did I ask you to remember? 
Model: This is the beginning of our conversation, so I haven't received any previous requests or information to remember. What would you like to ask me to remember?
User: 

With the suggested change, it appears the model starts to reply accurately [fork branch]:

Do you want to enter a system prompt? Enter y for yes and anything else for no. 
y
What is your system prompt? 
You are a helpful assistant.
User: Can you remember this word for me: "berryjuice"? Reply briefly.
Model: Here is the word: berryjuice.
User: What word did I ask you to remember? 
Model: The word you asked me to remember is "berryjuice".

For convenience, I've made a separate branch on my fork with logs that show how we're referencing the kv cache through the input_pos in the Transformer (nlpfollower#1). From what I understand we should retrieve contents of the whole cache, rather than the initial chunk.

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