Skip to content

server : add n_discard parameter to specify the number of tokens to discard when context is shifted #6300

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

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

kaetemi
Copy link
Collaborator

@kaetemi kaetemi commented Mar 25, 2024

Currently the context shift just shifts by half of what's not kept. A side effect is that sentences (and sometimes weird Unicode token sequences) get cut halfway. I found that whenever odd sentences got cut in half this had a noticeable negative effect on the model output. By adding n_discard as a parameter we can specify at application level where the natural or safe boundary of the context is (e.g. on newlines), so the context can be shifted more sanely in a more controlled manner.

@ngxson
Copy link
Collaborator

ngxson commented Mar 25, 2024

We don't have this option in main.cpp so it's quite strange to only implement it in server.cpp

I found that whenever odd sentences got cut in half this had a noticeable negative effect on the model output.

In this such case, can we set the n_keep to an odd value, so that the number of remaining tokens become even?

Could you also provide an example?

@kaetemi
Copy link
Collaborator Author

kaetemi commented Mar 25, 2024

@ngxson Sorry, I might not have been clear there. I meant odd as in having a meaning that would be significantly changed if the sentence ends up getting cut in half. I don't think it inherently makes sense in main, because the value needs to be changed on the fly to whatever the natural boundary is based on the whatever is getting added to the prompt.

As an example.
Keep: John likes apples.
Context: He tries to sell them. Mary buys them and eats them all. John is happy now.

After context shift could become:
Keep: John likes apples.
Context: and eats them all. John is happy now.

Which changes the whole meaning of the context. Adjusting keep size does not stop sentences from getting cut in half.

By having the application specify where it's safe to context shift, this is largely avoided.

@ggerganov ggerganov merged commit 3d032ec into ggml-org:master Mar 26, 2024
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 3, 2024
tybalex pushed a commit to rubra-ai/tools.cpp that referenced this pull request Apr 17, 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.

3 participants