Skip to content

Move LlamaLanguageModel to llama.cpp's extended batch API - #451

Open
james-333i wants to merge 1 commit into
huggingface:mainfrom
james-333i:fix/llama-batch-ext-api
Open

james-333i wants to merge 1 commit into
huggingface:mainfrom
james-333i:fix/llama-batch-ext-api

Conversation

@james-333i

Copy link
Copy Markdown
Contributor

llama.cpp v1.x deprecates llama_batch, llama_batch_init, llama_batch_free, llama_decode and llama_encode in favor of llama_batch_ext and llama_process. With llama.swift 3.x, LlamaLanguageModel.swift produces 12 deprecation warnings.

This moves the backend to the new API:

  • A fillBatch helper clears the batch, adds each token with its position, and requests logits for the last token when asked. It replaces the field writes that were repeated at each call site.
  • llama_batch_init / llama_batch_free become llama_batch_ext_init / llama_batch_ext_free.
  • llama_decode and llama_encode become llama_process with the matching process type.
  • The two reads that indexed logits with batch.n_tokens - 1 now pass -1, the last output. The backend only ever requests logits for the last token, so the value is the same.

One difference: llama_batch_ext_init takes its capacity from the context's n_batch and has no size argument. The prompt loop now chunks by the smaller of the requested batch size and llama_n_batch(context).

The reference decoder in LlamaLanguageModelTests used the same deprecated calls and is updated to match.

The new functions are present in b12359, the build llama.swift 3.0.0 ships, so this does not need a newer llama.swift than the current requirement.

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.

1 participant