Local AI: Leave Room for the Answer

Local AI: Leave Room for the Answer

Small Useful Worksheets

A local model shares its context window between the rendered prompt and the generated answer. If you place a total token-budget check around a chat API, leave room for both. A large output allowance does not create more context.

Count the rendered chat once

Apply the actual chat template to the system and user messages, then tokenize that complete rendered chat with the model’s tokenizer. This count already includes the input and template overhead. Do not add the overhead a second time, and do not substitute character counts for tokens.

safe_output_tokens = runtime_context_tokens - tokenized_rendered_chat_tokens

For example, 64 rendered prompt tokens plus a requested 2,048 output tokens needs room for 2,112 tokens. A 2,048-token runtime window cannot retain that entire prompt and answer together. An adapter enforcing a conservative fit check would reject that combination.

Check the runtime, not just the model card

SmolLM2-135M-Instruct’s model configuration sets max_position_embeddings to 8,192. A local server can still be configured with a smaller context. Check the runtime’s actual allowance before choosing max_tokens for a chat-completion request.

If the requested output will not fit, reduce max_tokens, shorten the prompt, or configure a larger context supported by the model and runtime. Do not assume every backend handles overflow identically: one may reject it, another may shorten the answer, and another may shift context and discard earlier text.

Test the result you intend to use

Try a known input and inspect the actual prompt and output usage. Check that the response keeps the relevant input and ends as expected. More context does not make a small model more accurate. Verify the meaning of its answer as well as the token counts.

For local-only experimentation, bind the server to a loopback address. A model’s context setting and its network exposure solve different problems.

References

SmolLM2-135M-Instruct model configuration

llama.cpp server documentation

Prepared with assistance from a local Olmo model, then checked and edited against the linked documentation. This reference is free to read.

Optional support

If this guide saved you time, voluntary Bitcoin support helps the publishing project. Reading and using the guide requires no payment.

bc1qmtuqaqnwsv2w7aencdrhm56lk9caw2j8l33guv

Report Page