Skip to content

Conversation

@cebtenzzre
Copy link
Member

@cebtenzzre cebtenzzre commented Jul 30, 2024

The main issue being fixed here is a CUDA crash with certain sizes of long inputs (ggml-org/llama.cpp#8798). For now there is just a workaround, but upstream is working on a proper fix. I cherry-picked the change from ggml-org/llama.cpp#8800 since it seems to work.

Other things I fixed while working on improving context "recalculation":

  • Removed unnecessary logic guarding BOS insertion now that llama.cpp is better at knowing when it's needed
  • Tried to make the token cache match n_past more often (there are still some issues involving interrupted recalculates)
  • Remove now-unused "logits" and "logits_size" from the python binding's prompt context
  • Fix cases where we started incorrectly inserting leading spaces again after backend: rebase llama.cpp submodule on latest upstream #2694

Since upstream commit 1b67731e1 ("BERT tokenizer fixes (#6498)"),
llama_tokenize will not add BOS for tokenizers that should not have it.

Since upstream commit 37bef8943 ("tokenizer : BPE fixes (#7530)"),
llama_add_bos_token can be used to confidently determine whether BOS
will be added by llama_tokenize.

The upstream logic to determine whether to add BOS has grown as
tokenizers have been added and improved, so this could fix problems with
a missing BOS, or context recalculation preserving the first token when
it shouldn't.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
The size of the token cache is expected to match n_past during the
decode phase of llmodel_prompt. We should make sure they match at entry,
and never do anything that could cause them to desync.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
`logits` does nothing now that GPT-J is removed, so remove the unused
fields.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
When llama.cpp was updated, I removed the space removal logic, but it
turns out it's still actually needed. This is now a proper parameter, as
we specifically only want to disable the *leading* space when we are
tokenizing input that comes after a normal token.

This fixes a regression in commit 290c629 ("backend: rebase llama.cpp
submodule on latest upstream (#2694)").

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
llama.cpp commit e3c337d87 ("llama : support negative ith in llama_get_
API (#6519)") added a simpler way to get the logits for the last token
in the batch, so use that instead. This also fixes potential issues with
not serializing this value with the rest of the prompt context, although
in practice we should always call evalTokens before
llama_sample_top_p_top_k.

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
@cebtenzzre cebtenzzre changed the title WIP: llamamodel fixes backend: fix extra spaces and work around CUDA bug Jul 31, 2024
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
@cebtenzzre cebtenzzre changed the title backend: fix extra spaces and work around CUDA bug backend: fix extra spaces in tokenization and a CUDA crash Jul 31, 2024
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
@cebtenzzre cebtenzzre marked this pull request as ready for review July 31, 2024 21:24
@cebtenzzre cebtenzzre requested a review from manyoso July 31, 2024 21:24
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