Large Models for Reading, Small Models for Writing: How to Implement Dual-Model Inference
Deploying ultra-large models for long-context tasks faces significant hardware and bandwidth bottlenecks. This article explores a dual-model inference architecture where a large model reads long inputs and generates a brief summary, while a smaller model handles the generation of the final long-form answer. We analyze the resource constraints of inference phases, detail the architecture and implementation with sample code, evaluate latent space bridging approaches, and provide a pre-launch checklist for production deployment.
1. Why Large Models are Difficult to Deploy Directly
Open-source models with over 700 billion parameters represent the current limit of open-source reasoning capabilities and knowledge capacity. Estimating at 1 byte per weight (FP8 or INT8 quantization), the main weight matrix of a ~753 billion parameter model requires about 753 GB of storage. Official checkpoints also include auxiliary parameters like quantization scale factors, normalization layers, and multi-token prediction modules, bringing the total file size to about 755.6 GB. Even with 4-bit quantization, the weights still require about 380 GB, far exceeding the VRAM capacity of a single consumer GPU.
Therefore, deploying such models typically requires multi-GPU servers or multi-node clusters. Deployment must account for three types of resources simultaneously: weight storage, KV cache consumption, and inference bandwidth and compute.
2. Two Phases of Inference and Their Resource Bottlenecks
Large model inference is divided into two phases: prefill and decode, each with different bottlenecks.
Prefill: The model reads all input tokens at once and computes attention for each token. This phase is primarily compute-bound. The computation can be roughly estimated as:
FLOPs ≈ 2 × Activated Parameters × Input Token Count + Attention Term
For MoE models, “Activated Parameters” refers to the parameters actually involved in the computation for each token, not the total parameters. The attention term grows with context length, roughly correlating with the square of the sequence length in standard full-attention implementations. Expanding the context from a few thousand to 128K tokens significantly increases prefill time and extends the Time To First Token (TTFT).
Decode: For each token generated, the model must read the activated weights and historical KV cache from VRAM. This phase is primarily memory bandwidth-bound. The theoretical limit can be estimated as:
Theoretical Decode Speed ≈ Effective Memory Bandwidth ÷ Bytes Read Per Token
For example, assuming a single request, batch size of 1, each token requires reading about 40 GB of data (including activated weights and KV cache), and the system’s effective bandwidth is 8 TB/s, the theoretical limit is about 200 token/s. Actual speed will decrease due to scheduling, communication, and kernel efficiency. This figure is only for scale illustration and does not represent any specific product’s performance.
KV Cache: The KV cache size can be estimated as:
KV Cache Bytes ≈ 2 × Number of Layers × Number of KV Heads × Head Dimension × Sequence Length × Bytes Per Element
A 128K context consumes a massive amount of VRAM. Even if the weights fit, long-context requests will squeeze the batch processing space, reducing overall throughput.
Weight Loading: Reading weights from storage into VRAM is also time-consuming. For example, reading 755 GB at a sequential storage read speed of 7 GB/s takes about 108 seconds. Therefore, models should reside permanently in VRAM to avoid frequent cold starts.
3. Time Allocation of a Single Request
The latency of a complete request consists roughly of three parts:
| Phase | Primary Bottleneck | Impact on Latency |
|---|---|---|
| Long input prefill | Compute and attention calculation | Determines Time To First Token (TTFT) |
| Large model generating intermediate summary | Compute and memory bandwidth | Shorter summary means less time |
| Small model outputting tokens one by one | Memory bandwidth | Determines generation speed of the final answer |
The costs of long-context understanding and long-text output stem from different sources, so they can be decoupled. Having the large model output only a short summary and letting a small model handle the long answer minimizes the costly large model decoding.
The benefit of this handoff depends on two ratios: the ratio of summary tokens to final answer tokens, and the ratio of bytes read per token between the large model and the small model. The shorter the summary and the smaller the small model, the more obvious the decoding gains. However, prefill still must be done by the large model; the TTFT for a 128K input will not disappear due to the handoff.
4. Division of Labor: Architecture and Implementation
The core assumption of this architecture is that understanding long inputs requires the knowledge and reasoning capabilities of a large model, while generating fluent long text mainly consumes bandwidth, a task a small model can fully handle. The typical workflow is as follows:
- Receive the request, perform long text segmentation and basic cleaning.
- The large model reads the complete context and outputs structured key points. Each point includes a conclusion, evidence source, and confidence level.
- Validate the large model’s output against a JSON schema, and locate the evidence spans in the original text.
- The small model takes the key points and evidence spans as input to generate the final user-facing answer.
- Output the result, and record the latency and token usage of both stages.
Below is a sample implementation. The clients are generic interfaces, and helper functions like parse_and_validate_brief and fallback_brief_from_retrieval need to be implemented by yourself:
def answer_with_handoff(query: str, documents: list[str]) -> str:# Phase 1: The large model reads the long context and outputs structured key points with evidencebrief_prompt = build_brief_prompt(query, documents)try:raw = large_model_client.generate(prompt=brief_prompt,max_new_tokens=512,response_format="json",timeout_s=30,)brief = parse_and_validate_brief(raw, schema=BRIEF_SCHEMA)except (TimeoutError, SchemaError):# Fallback: If the large model times out or produces invalid output, use retrieved chunks directly for the small modelbrief = fallback_brief_from_retrieval(query, documents)# Phase 2: The small model generates the final answer based on key points and original evidence spansevidence_spans = collect_evidence_spans(brief, documents)answer_prompt = build_answer_prompt(query, brief, evidence_spans)answer = small_model_client.generate(prompt=answer_prompt,max_new_tokens=2048,stream=True,)return answer
Three things to note in this code. First, the output length of the large model must be controlled; max_new_tokens should have an upper limit, otherwise the handoff will consume most of the gains. Second, each key point must carry the source ID and original text span of the evidence, and pass the span to the small model, so the small model can accurately cite the original text in its answer, and it is easier to troubleshoot errors afterwards. Third, timeouts and schema validation failures must have a fallback path, otherwise the entire pipeline will halt if the large model encounters an issue.
5. Latent Space Bridging: Feasible Paths and Boundaries
“Latent space bridging” refers to passing information directly between internal model representations without going through natural language. By engineering difficulty, it can be divided into four levels.
Level 1: Text Handoff. The large model outputs a natural language summary, and the small model reads it directly. It is compatible with any model, and the intermediate results are readable and auditable, making it the most universal approach today.
Level 2: Structured Handoff. The large model outputs JSON according to a fixed schema, such as entities, conclusions, evidence, and confidence levels. The fields are explicit, facilitating validation and caching, but it still requires text encoding and decoding.
Level 3: KV Cache Reuse. The computation results of the same model for the same prefix can be cached and reused to reduce repetitive prefill. Its boundary is clear: caching can only be reused when using the same model, the same tokenizer, the same positional encoding conventions, and when the prefix tokens are completely identical. Before cross-request reuse, prefix matching validation must be performed to ensure the cache matches the current input. The cache must also be bound to the model version; it needs to be invalidated after model updates. KV caches cannot be directly shared between different models.
Level 4: Hidden State Projection. Mapping the hidden states of one model to the representation space of another requires training an additional alignment layer and relies on paired training data. This direction has made progress in research, but its effectiveness is highly task-dependent and lacks stable engineering standards.
Direct latent space communication across heterogeneous models is still primarily research-focused. The mainstream engineering solutions remain Level 1 and Level 2.
6. Will Latent Space Communication Replace Text Interfaces?
The advantages of latent space communication are clear. It has a high information density, eliminates the overhead of decoding and re-encoding, and theoretically offers lower latency and potentially stronger expressive power.
Its problems are equally clear:
- Unreadable: Intermediate tensors cannot be directly verified, making it difficult to locate causes when errors occur.
- Hard to audit: In security and compliance scenarios, it cannot leave traceable records like text.
- Fragile: After model upgrades or fine-tuning, the alignment layer may fail and require retraining.
- High alignment cost: Models from different sources are difficult to share in the same representation space.
Overall judgment: Internal state exchange will become more common within the same training system and among modules maintained by the same party, such as shared KV caches or jointly trained projection layers. Cross-team, cross-model agent collaboration will continue to use text or structured protocols as interfaces in the short term. Latent space communication is more likely to appear as an internal optimization method within a system rather than becoming a universal language between agents.
7. Pre-Launch Checklist
- Monitor metrics for both stages separately: Record the large model’s TTFT, the small model’s decode speed, VRAM usage, and queue length.
- Separate queue scheduling: Route long-context requests to an independent queue to avoid squeezing the batch processing space of short requests.
- Design fallback paths: When the large model times out or produces invalid output, the small model should directly generate an answer based on retrieved chunks.
