How to Count Tokens With Tiktoken Before an API Call So the Request Fits the Limit
Encode the exact request text with the model encoding, compare the count with the context limit, and trim the prompt before sending…
THE FIELD GUIDE
Understand model formats, context windows, quantization, embeddings, and sampling before choosing settings for a real task.
Encode the exact request text with the model encoding, compare the count with the context limit, and trim the prompt before sending…
Work out the image token count from the size and detail level, add it to the text tokens, and resize the image…
Run the same long-document task on both attention types, score the answers at increasing lengths, and note where the sliding window starts…
Pick a cache type that matches the conversation length, know when older tokens are evicted, and check the answers stay correct as…
Measure prefill and decode tokens per second before and after quantizing on the same prompts, and check peak memory too.
List the layers that break when quantized, keep them at full precision, quantize the rest, and check the mixed model on your…
Multiply parameters by bytes per weight at the target precision, add room for the KV cache and activations, and compare the total…
Check whether a few activation outliers dominate the error, and use an activation-aware method when plain rounding destroys those weights.
Check the hardware table for your target device first, pick a format that runs there, and only then compare quality and speed.
Measure perplexity on held-out text before and after quantizing, compare the two numbers, and reject a quantized model whose perplexity jumped.