Post-Training, Long-Context Agents, and Deployment Practices
This article outlines practical considerations for post-training large language models, long-context inference, and long-running agents. It focuses on selecting parallelism strategies through measurement, managing both memory and scheduling for long-context workloads, and controlling agent risk with strict limits and permission boundaries. The guidance is intended for engineers and technical leaders working on large-model training or production deployment.
1. Audience and Key Takeaways
This article is intended for engineers and technical leaders responsible for large-model training or application deployment. Readers should be familiar with the basic concepts of distributed training and large-model inference. The discussion covers three areas: post-training, long-context inference, and long-running agents. It does not cover model pretraining, data governance, or specific cloud-provider selection.
There is no universally optimal solution. Actual results depend on model size, available hardware, and application latency requirements. The main conclusions are:
- Measure first, then choose a parallelism strategy.
- For long-context inference, consider memory capacity and scheduling together.
- For long-running agents, use hard limits and permission boundaries to control risk.
2. Post-Training: Turning Compute into Capability
Post-training is typically used to improve instruction following, alignment, and multi-step reasoning. Reinforcement learning is a key component of this process. Training efficiency is often constrained by two factors: gradient-synchronization communication across nodes and insufficient GPU memory on individual devices.
2.1 Parallelism Strategies and Memory Usage
A common approach is to combine multiple forms of parallelism. ZeRO-3 shards model parameters, gradients, and optimizer states across multiple GPUs, reducing memory usage on each device. Pipeline parallelism places different model layers on different devices, making it suitable for models with many layers that cannot fit on a single GPU. Combining the two increases communication and scheduling complexity.
Before production deployment, measure throughput on a small cluster to determine whether communication overhead offsets the memory savings. The following metrics provide a starting point and should be calibrated for the target cluster:
- Communication ratio: The proportion of each training step spent on gradient synchronization and cross-device transfers. If this ratio remains above 30%, first review the partitioning strategy and network topology.
- Throughput reduction: If tokens processed per second fall by more than 10% compared with the baseline after adding a new parallelism dimension, the change may have a negative overall impact. Consider reverting to a simpler configuration.
- Memory reduction target: Peak memory usage on each GPU should fall below the target, with an additional 10% to 15% buffer to accommodate fluctuations in sequence length.
2.2 Experience Replay Buffer Management
An experience replay buffer can reuse historical samples and improve sample efficiency. However, samples that are too old may cause the gradient direction to diverge from the current policy.
In practice, two measures are commonly used. First, set a maximum sample age and discard samples that exceed it. Second, record the corresponding policy version for every batch. Policy version information helps diagnose abnormal training metrics—for example, it can indicate whether a sudden metric change was caused by stale samples.
2.3 Detecting Reward Hacking
A model may learn to satisfy the preferences of a reward model without actually completing the task. This behavior is known as reward hacking.
Three measures can help detect it:
- Periodically sample outputs for review using human annotations or an independent evaluation set.
- Monitor the divergence between reward scores and real quality metrics.
- If the divergence exceeds a predefined range, reduce the reward weight or update the reward model.
The divergence threshold must be calibrated using a validation set. One possible approach is to use the 95th percentile of divergence on the validation set as the alert threshold, then confirm alert accuracy through human sampling. The sampling rate depends on business risk; high-risk applications require a higher review rate. Because the threshold is application-specific, values from another team should not be reused directly.
3. Long-Context Inference: Memory and Scheduling Must Be Considered Together
When supporting contexts of up to millions of tokens, KV-cache usage grows linearly with sequence length. A single long request may consume the available memory of an entire GPU. Optimization approaches can be divided into two categories.
3.1 Reducing the Memory Cost of Individual Attention Operations
FlashAttention uses tiled computation to avoid materializing the full attention matrix, reducing memory traffic and improving computational efficiency on a single GPU.
Ring Attention distributes a long sequence across multiple GPUs, with devices exchanging KV blocks in sequence. It addresses insufficient capacity on a single GPU.
The two techniques target different bottlenecks and can be combined. When choosing between them, first determine whether the primary limitation is single-GPU efficiency or cross-GPU capacity, then select the appropriate approach.
