Skip to content

fix(examples): update low-level text generation to the current C API - #2428

Open
emme1t wants to merge 1 commit into
abetlen:mainfrom
emme1t:fix/low-level-generation-example-1803
Open

emme1t wants to merge 1 commit into
abetlen:mainfrom
emme1t:fix/low-level-generation-example-1803

Conversation

@emme1t

@emme1t emme1t commented Nov 21, 2026

Copy link
Copy Markdown

Addresses the basic text-generation example in #1803.

The example fails on a real GGUF at the first call to the removed llama_eval API. It now loads the model vocabulary, decodes the prompt in batches, and samples from the last token's logits using the public sampler chain. Output is decoded incrementally so a UTF-8 character can span several tokens. The example's README includes the installation command and the MODEL environment variable. The interactive chat example is tracked separately in #1817.

Tested on Windows with the CPU backend and two GGUF models. The default prompt produced 20 new tokens with stories15M. A Chinese prompt produced 8 new tokens with Qwen3.5-0.8B. A 510-token prompt filled 22 batches and generated the two tokens that still fit in the context. I also checked rejection of full and oversized prompts, a four-piece UTF-8 character, a 128-byte token piece, EOG handling, and resource release. Black, Ruff and git diff --check passed for the changed files.

This branch has not been deployed

No deployments
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