Training a Terminal Agent on 64 GPUs in 5 Days: A Low-Cost, High-Performance Recipe

    This article examines how to train a terminal and software engineering agent that can complete multi-step tasks in real environments without letting per-task cost spiral. Using a public training recipe as a reference, it covers five key areas: selecting a mid-sized sparse base model for full-parameter reinforcement learning, filtering tasks into a learnable pass-rate range, adapting RL to long and stale rollouts, physically separating training and inference resources, isolating runs in disposable microVMs, and sharing one agent harness across training and evaluation. It also explains what a Pareto frontier means for capability versus cost, and offers a practical checklist for teams with limited compute. The reference run used 64 high-end accelerators for under 5 days.

    1. The Problem: Capability and Cost Are Pulling Apart

    Industry observation over the past two years points to the same conclusion: the ceiling for terminal and software engineering agents is increasingly set by whether they can complete multi-step interactions in a real environment, not by how fluent a single-turn answer sounds. Evaluation has shifted accordingly, from static question answering to executable tasks: given a repository, an error message, and an empty machine, the agent must read files, install dependencies, run tests, and modify code until verification passes.

    This creates two new tensions.

    First, capability and cost are tightly coupled. To make an agent “think longer,” inference effort keeps being pushed higher, token consumption grows non-linearly, and per-task cost quickly spirals. A common pattern on public leaderboards: Pass@1 differs by only a few percentage points, while cost differs by one or two orders of magnitude.

    Second, the efficiency bottleneck on the training side is underestimated. Sampling cycles for terminal tasks are extremely long (a single rollout may involve dozens of tool calls), and environments are unstable with high failure rates. As a result, the “effective sample rate” during reinforcement learning is low, and much of the compute is spent on invalid or partially invalid trajectories.

    So the technical question worth studying is not “how to make the model a bit bigger,” but: within a budget of a hundred-GPU-class cluster and a few days, how do you push capability into the frontier range while cutting per-task cost by an order of magnitude? This article uses a public training recipe as a reference and abstracts a transferable methodology from it.

    2. Starting Point: A Mid-Sized Base Model Plus Full-Parameter Reinforcement Learning

    A key decision in this practice: instead of pre-training from scratch or doing only lightweight output-layer fine-tuning, it starts from a sparse base model (a mixture-of-experts architecture with multi-token prediction layers and a sparse attention index structure) with roughly 300 billion total parameters and about 17 billion activated parameters per token. Full-parameter reinforcement learning is applied to all language parameters, with only the vision encoder and the attention indexer frozen.

    There are three reasons this makes sense:

    • Why full-parameter updates are necessary. A terminal agent needs “long-range consistency”: the directory structure read earlier, the dependency versions installed, and the hypotheses already ruled out must still hold dozens of steps later. Adjusting only a small number of parameters is unlikely to reshape this kind of long-range behavior.
    • The benefit of freezing some modules. The vision and index modules handle perception and retrieval, which are weakly related to task policy. Freezing them significantly reduces memory and communication overhead, and avoids small-sample policy gradients damaging existing representations.
    • The cost advantage of a sparse architecture. Activated parameters are far fewer than total parameters, keeping per-token cost during inference (the rollout phase) under control. This is the physical basis for “low per-task cost.”

    This logic does not depend on any specific vendor product. Any base model with “sparse activation + long context + tool calling” can apply it.

    3. Systematic Optimization Across Five Key Areas

    3.1 Environment Filtering: Keep Every Task in the “Learnable Range”

    The value of an RL sample depends on whether the reward is discriminative. Tasks that are always solved or always failed contribute almost no gradient. Practical filtering criteria include:

    1. Sample multiple times with the current policy and keep tasks whose pass rate falls in a middle range (for example, 0.1 to 0.7);
    2. Remove tasks that depend on external networks, require manual accounts, or suffer from version drift;
    3. Grade tasks by “auto-verifiability” and prioritize those with unit tests or explicit validation scripts;
    4. Re-sample periodically, because tasks that were “appropriately difficult” degrade into uninformative samples as the policy gets stronger.

    Illustrative filtering logic:

    1. def keep(task, policy, k=8, low=0.1, high=0.7):
    2. results = [run_in_microvm(task, policy) for _ in range(k)]
    3. p = sum(results) / k
    4. return low <= p <= high and task.auto_verifiable

    3.2 An RL Recipe for “Long, Stale, Low-Precision” Sampling

    Terminal task rollouts have three natural weaknesses: trajectories are long, data is stale, and numerical precision is low (inference often uses low precision for throughput). Keeping the assumptions of synchronous, exact, short-trajectory training leads to clear instability. Viable responses:

    • Allow policy lag: let samples produced by weights a few versions behind the current ones participate in updates, with importance sampling correction and clipping, turning higher throughput into effective throughput;
    • Trajectory-level credit assignment: for multi-step tasks, rely mainly on outcome rewards with process rewards as a supplement, avoiding intermediate-step noise dominating the gradient;
    • Length normalization and group baselines: within-group comparison (multiple trajectories of the same task serving as baselines for each other) is more stable than a global mean and suppresses variance amplification from long trajectories;
    • Decouple decoding acceleration from training: use the multi-token prediction layer for speculative decoding, which measured about 1.3x decoding speedup and directly shortens sampling wall-clock time.

    3.3 Physically Separate Training and Inference Resources

    Putting sampling and optimization on the same set of cards makes them compete for memory and bandwidth, causing sharp utilization swings. A more stable approach is two resource pools: one dedicated to rollout (focused on throughput and concurrency) and one dedicated to parameter updates (focused on communication and memory). The two connect asynchronously via weight version numbers, forming a pipeline. The direct effect: sampling no longer waits for optimization, and optimization does not have to match the sampling pace.

    3.4 Sandbox Isolation: Strip Infrastructure Noise From the Reward Signal

    The biggest hidden cost in long tasks is environment failure. If a container crash or network jitter is misread as “the model did something wrong,” the policy gets penalized incorrectly. Running each attempt in a separate disposable microVM and explicitly distinguishing “environment error” from “task failure” cut the share of sampling groups lost to infrastructure problems from double-digit percentages to under 1%. Engineering points:

    • Environment-error samples do not count toward the gradient, only toward monitoring metrics;
    • Prepare snapshot images for each task type to shorten cold starts;
    • Apply least-privilege constraints to the file system, processes, and network egress.

    3.5 Share One Agent Framework Across Training, Optimization, and Evaluation

    If the tool protocol used in training differs from the one used in evaluation, offline gains often fail to transfer. A unified harness (agent runtime framework) means the same tool definitions, the same context assembly, and the same result validation, making “training is evaluation.” This is also the key prerequisite for capability to transfer from terminal benchmarks to software engineering benchmarks (such as repository-level defect repair evaluations).

    4. Reading the Results: What the Pareto Frontier Means

    Public data shows that this 300B-class terminal agent reaches a Pass@1 of around 46% on mainstream terminal benchmarks, in the same range as the strongest closed-source options, while per-task cost is more than an order of magnitude lower than the highest-inference-effort option. The same recipe also shows consistent positive transfer on two repository-level software engineering benchmarks. Total training cost: 64 high-end accelerators for under 5 days.

    The technical implications are threefold:

    1. The frontier is a line, not a single point. The real engineering goal is to extrapolate this line on the capability-cost plane, not to chase scores at one fixed cost.
    2. The cost basis must be transparent. If the model is self-deployed by the team, converting cost at public API prices is a conservative estimate that excludes cluster depreciation and engineering labor.
    3. Reproducibility comes from the recipe, not from compute. Environment filtering, asynchronous sampling, sandbox isolation, and a unified framework are weakly correlated with cluster size, so smaller teams can reproduce them at a reduced scale.

    5. A Practical Checklist

    • Build evaluation and validation before training: without automatic verification there is no reliable reward;
    • Turn sampling success rate into a dashboard, monitor it in buckets by task difficulty, and retire degraded samples promptly;
    • Strictly separate environment errors from task failures to avoid polluting the gradient;
    • Split sampling and optimization into separate pools, with a multi-version weight asynchronous pipeline;
    • Fix one tool protocol across training and evaluation to prevent definition drift;
    • Report token counts, wall-clock time, and retry counts together when assessing cost.

    When compute constraints are the norm, spending the budget on “signal quality” and “system efficiency” is often more cost-effective than continuing to scale parameters. The five areas above can be built on general infrastructure such as container platforms, object storage, logging services, and monitoring and alerting, with no proprietary interfaces required. For teams that want to reproduce a similar workflow on a general cloud environment such as Baidu AI Cloud, the key is to turn verifiable tasks, isolated sandboxes, and a unified evaluation standard into standard components first.