Post-Training Optimization for Large Models: A Practical Guide to Long-Horizon Agents
As pretraining returns diminish, teams are shifting compute toward post-training—supervised fine-tuning, reinforcement learning, and RLHF. This guide examines RL training frameworks and scheduling, the memory cost of long-context inference via KV Cache, sandbox infrastructure for agents, the real capabilities and limits of code and long-horizon agents, and how to interpret benchmark results responsibly.
1. Why Post-Training Has Become the Priority
Scaling parameters during pretraining still works, but the return on investment is declining. More and more teams are redirecting compute toward post-training—supervised fine-tuning (SFT), reinforcement learning (RL), and reinforcement learning from human feedback (RLHF) applied on top of a base model. The goal is to make models more reliable in vertical scenarios such as coding, financial research, and long, multi-step workflows.
For developers and enterprises, three questions matter most: how do these models perform on real-world tasks, what changes are needed in the underlying systems, and how do you deploy them in the cloud while controlling costs. This article addresses these three questions in order, and flags the basis and limitations of each conclusion.
2. RL Frameworks and Scheduling
The main challenges of large-scale RL training are a vast exploration space and sparse rewards. The model must generate large numbers of candidate trajectories, but only a few receive meaningful reward. Training frameworks therefore need to sample from the policy efficiently and manage sampled results, rewards, and training data in a unified way.
The scheduling layer must also handle heterogeneous workloads. A single cluster may simultaneously train policies for hundreds of domains, each with different task lengths, environment response times, and resource requirements. If the scheduler cannot dynamically allocate GPU memory and compute per task, two kinds of waste appear: GPUs idling while waiting for data, and long tasks monopolizing resources while short tasks queue up. I/O latency also drags down utilization, so data prefetching and caching are part of the training system as well.
Note that experience replay primarily serves off-policy algorithms. Many RLHF pipelines for large models use on-policy optimization, where training data typically comes from recent samples of the current policy. The two approaches manage data differently, so confirm the algorithm type before making architectural choices.
3. Long-Context Inference: The KV Cache Memory Bill
Models supporting million-token contexts now exist, but this is not a universal feature across frontier models. Whether a model supports a million tokens depends on its architecture, training methods, and inference system. Even when supported, memory, latency, and cost remain practical constraints.
KV Cache is the dominant memory overhead. Each token requires storing a Key and a Value for every layer. As a rough estimate, consider a hypothetical configuration: 80 layers, 8 KV heads, 128 dimensions per head, in BF16 (2 bytes per value).
Per token, the KV Cache is roughly 2 × 80 × 8 × 128 × 2 bytes = 327,680 bytes, about 320 KB. A single 1-million-token request would require around 328 GB of memory—before accounting for model weights and activations.
Common approaches to reduce this overhead include:
- Paged memory management (ideas such as PagedAttention) to reduce memory fragmentation.
- KV Cache quantization with low-precision formats such as FP8 or INT8, though output quality must be validated.
- Sparse attention, which computes attention over only part of the history—suitable for certain long-text tasks, but potentially losing accuracy on long-range dependencies.
- Sequence parallelism methods such as Ring Attention, which split long sequences across multiple GPUs at the cost of cross-device communication.
All of these involve trade-offs among quality, latency, and throughput. Throughput gains reported in papers or benchmarks are usually tied to specific hardware, input/output lengths, and batch sizes, and cannot be directly applied to other environments.
4. Sandbox Infrastructure and Environment Verification
When agents execute code and call tools, they need an isolated runtime. Sandboxes should restrict network, file, and process permissions to prevent malicious code or accidental operations from affecting the host system. Snapshot and rollback capabilities are equally important—they allow every attempt to restart from a known state.
Environment verification can inspect files, processes, test results, and service states after the agent has run, converting them into verifiable reward signals. For example, passing test cases, files conforming to specifications, and APIs returning the correct structure can all serve as objective metrics. Verification metrics must be designed together with failure handling—including timeout detection, error classification, and automatic rollback conditions—otherwise a broken environment will contaminate subsequent training data.
5. Code and Long-Horizon Agents: Capabilities and Boundaries
Code tasks have expanded from single-function generation to engineering-level work. Three common forms stand out.
The first is bug fixing: the model locates issues in a large codebase and generates patches. Results depend on codebase size, programming language, test coverage, and issue description quality. Generated patches should pass tests and be reviewed by engineers before merging.
The second is project scaffolding: the model generates frontends, backends, databases, and interface definitions from requirements. It can produce a basic skeleton, but business rules, security configuration, and performance targets still require human design.
The third is frontend and interactive development: the model can call UI component libraries or rendering engines to generate visually polished pages. Visual quality depends on design specifications and human review—working code alone is not enough.
Long-horizon agents require the model to maintain state across multi-step tasks. Take financial research as an example: an agent may need to retrieve reports, extract metrics, clean data, cross-check numbers, and then generate an analysis report. Common failure modes include forgetting earlier constraints mid-task, mixing figures from different sources, or repeatedly retrying the same request after an API timeout.
When evaluating such systems, focus on three things: contextual consistency across multi-step execution, the ability to adjust strategy after tool errors, and whether final results can be traced to their sources. For financial analysis, data usage authorization, report copyright, and disclaimers must also be handled. The output is research assistance and does not constitute investment advice.
6. How to Read Benchmark Results
Benchmark scores are only meaningful when the test conditions are clearly stated. Readers should confirm the following:
- Benchmark name and version, e.g., a specific terminal-task suite or engineering-task suite version number.
- Test environment, including resource limits, tool permissions, and network conditions.
- Metric definitions, such as whether the pass rate is a single-attempt success rate or the best result across multiple samples.
- Comparison targets, i.e., whether the baseline model’s version and settings are consistent.
