Long-Context Inference on Two GPUs: KV Cache Quantization and Prefill Speed Measurements
This article reports a long-context inference test on a dual-GPU setup, using an open-source model with about 27 billion parameters. It compares 4-bit and 8-bit KV Cache quantization, shows how prefill throughput drops as input length grows, and examines the trade-offs between tensor split and layer split. The results come from a single experiment log, so they serve as a starting point for model selection rather than performance guarantees.
Introduction
As a model’s context window grows, the trade-offs between VRAM usage, speed, and accuracy become harder to balance. This article documents a long-context inference test on a dual-GPU setup, using an open-source model with about 27 billion parameters. The test addresses three questions: whether to use Q4 or Q8 for the KV Cache, how prefill speed changes with input length, and what each of two split modes costs. The data comes from a single experiment log. Treat it as a reference point for model selection, not as a performance guarantee.
1. Test Environment and Limitations
The model version supports a 256K context window. Its weights use the IQ4_XS quantization format and include a vision projection module and multi-token prediction (MTP) heads. The inference framework is a common local high-performance tool that supports CUDA acceleration and multi-GPU parallelism.
The experiment log shows that model weights, KV Cache, the vision projection, and the MTP heads together used about 25 GB of VRAM, lower than the theoretical estimate made beforehand. The main reason is thought to be the 4-bit KV Cache quantization. However, the log does not specify the tool used to measure VRAM or the sampling time, so treat this figure as a reference value.
The log also does not record the GPU model, driver and CUDA versions, or the framework version. It does not state how many times each test was repeated. Without this information, readers cannot reproduce the results exactly. The conclusions below carry this limitation.
2. Effects of KV Cache Quantization
2.1 Instruction Following
The test compared instruction-following performance with the KV Cache at Q4 and at Q8. On common instruction-understanding tasks, no clear difference appeared. The model understood the intent of the instructions and produced outputs that met the requirements in both cases. For most conversational and task-oriented scenarios, Q4 was already stable enough.
2.2 Complex Reasoning
On complex logic and multi-step reasoning tasks, Q4 performed slightly worse. Some intermediate steps jumped or broke off, and final answer accuracy was lower than with Q8. The author suspects that low-bit quantization disrupts attention allocation, especially in reasoning that requires recalling details from far back in the context. In those cases, errors may accumulate step by step. This hypothesis has not been verified through ablation experiments or error analysis. The original record describes the drop as acceptable. For less demanding reasoning tasks, Q4 remains useful.
2.3 Long-Context Retrieval
The test embedded a probe in a text of about 200K tokens, placing it at 1/5, 2/5, 3/5, and 4/5 of the full length. The model was asked to find the target content. It found the correct content at all four positions, which suggests that Q4 did not noticeably impair information location in very long texts. The log does not state how many probes were used at each position, so this result is better read as a directional indication.
3. Prefill Speed Declines with Context Length
3.1 Measured Data
Prefill is the slowest stage of long-context inference. The test recorded throughput at three lengths:
- 10K context: about 700 to 800 tokens/s
- 100K context: about 480 tokens/s
- 200K context: about 300 tokens/s, with a recorded total time of 14 minutes
The downward trend across the three sampling points is clear. Three points are not enough, however, to tell whether the decline is linear, quadratic, or follows some other form. Attention computation grows with the square of sequence length, which is one of the main reasons throughput drops. As input grows, memory bandwidth pressure also rises.
3.2 Data Interpretation
The data needs a caveat. At an average of 300 tokens/s, 200K tokens would take about 11 minutes, but the log records 14 minutes. The gap could come from either of two causes. The actual average speed may have been below 300 tokens/s, or the timing may have included extra overhead such as queuing or VRAM scheduling. The log gives no evidence to decide between these. Similarly, at 750 tokens/s, a 10K context would take about 13 seconds, while the log records about 10 seconds. That figure also could not be verified. When citing these numbers, rely on your own measurements.
3.3 Waiting for Automatic Compression
When input reaches the context limit, inference frameworks usually compress automatically. For example, they may discard the oldest history or recompute the KV Cache. Because prefill is slow, the wait before compression finishes can last several minutes. This is most noticeable in the 200K scenario, where it directly affects interactive experience and batch throughput.
4. Split Modes and Batch Parameters
4.1 Tensor Split and Layer Split
Tensor split divides weight matrices along their dimensions across GPUs. It offers high computational efficiency but requires frequent cross-GPU communication. Layer split assigns different layers to different GPUs. It requires less communication but may produce unbalanced loads.
In the test, layer split prefilled faster because it reduced cross-GPU communication. Decoding was slower, because each generated token must pass through the layers in sequence. Pipeline latency between layers offset part of the gain. The right choice depends on the task. For one-time analysis of long documents, layer split is preferred. For real-time multi-turn interaction, tensor split is more suitable, though it comes with slower prefill.
4.2 Batch Size and Micro-Batch Size
The test used a batch size of 1024 and a micro-batch size of 512. Combined with dynamic batch assembly, GPU utilization improved. An oversized batch may cause insufficient VRAM or higher queuing delay. These parameters depend on the GPU’s VRAM capacity. They should be tuned with a grid search that accounts for VRAM headroom and KV Cache precision, rather than copied directly.
5. Deployment Parameter Reference
The inference launch script controls key parameters through environment variables, which makes it easy to switch between experiment configurations. The main parameters are:
CTX_SIZE: context length, tested at 256000CACHE_TYPE_K,CACHE_TYPE_V: KV Cache types, tested asq4_0BATCH_SIZE,UBATCH_SIZE: batch size and micro-batch size, tested at 1024 and 512SPLIT_MODE: split mode, recorded astensororlayerTENSOR_SPLIT: allocation ratio across GPUs, tested as2,1.5
