Low-Cost Reinforcement Learning for Vertical-Domain LLMs: A Practical Guide

    This article explains how vertical-domain large language models differ from general-purpose models, and why reinforcement learning (RL) can deliver a step change in performance on narrow tasks at low cost. It covers a production-grade training architecture that separates inference from training, how GRPO removes the critic model to save memory, the five-step training loop, and a practical reproduction checklist covering data preparation, sampling configuration, reward design, memory and throughput tuning, training stability, and evaluation. Engineering teams will find guidance on combining these pieces on the cloud to move smoothly from single-GPU experiments to multi-node training.

    1. Vertical-Domain LLMs vs. General-Purpose LLMs: Division of Labor, Not Replacement

    A common mistake when comparing vertical-domain LLMs with general-purpose LLMs is to put them on the same track and compete on parameter counts or benchmark rankings. A more accurate view is this: general-purpose LLMs pursue breadth and generalization, covering long-tail needs such as open-domain question answering, writing, and multi-turn dialogue. Vertical-domain models pursue depth and stability on specific tasks, such as mathematical reasoning, code generation, structured extraction, and understanding industry terminology.

    From a cost-structure perspective, the capabilities of general-purpose LLMs come from massive data and enormous parameter counts, so the fixed investment in training and inference is extremely high. Vertical scenarios, by contrast, usually have clear data boundaries and well-defined evaluation criteria, which is exactly where reinforcement learning (RL) performs best. RL does not require a model to “know everything”; it only requires the model to keep pushing the policy for a specific task toward better outcomes under a clear reward signal.

    So the conclusion is not that “small models replace large models.” Instead: general capabilities can rely on mature foundation models or general-purpose model services on the cloud, while vertical capabilities can be built in-house with a “small-parameter base model + targeted post-training.” This balances effectiveness, latency, and cost.

    2. Why RL Can Produce a Qualitative Leap for Small Models on Specific Tasks

    Supervised fine-tuning (SFT) teaches a model to imitate reference answers, which is essentially distribution fitting. Reinforcement learning optimizes expected return, allowing the model to explore multiple paths for the same question and adjust its policy based on how good the results are. This difference brings three benefits:

    1. Layered rewards: a correct answer earns a high reward, while format compliance and reasonable steps earn partial rewards, which significantly mitigates the sparse-reward problem.
    2. More thorough exploration: sampling multiple answers for the same prompt lets the model discover solution paths better than those in the labeled data.
    3. Controllable cost: a small parameter count means low memory usage, so a single GPU can host the closed loop of “inference generation + parameter updates.”

    It is worth stressing that the leap in effectiveness is not “magic” from RL. It comes from three things working together: the base model already has foundational capabilities, the task reward can be judged automatically, and training throughput is high enough. If any one of these is missing, the gains drop sharply.

    3. Production-Grade Training Framework: Why Inference and Training Should Be Separated

    An early approach packed both generation and training into the same deep learning framework. The generation stage consumed the majority of total time, yet could not fully utilize the hardware because of batching and memory limits. A common production-grade approach in the industry is a disaggregated architecture:

    • The training side uses a mainstream deep learning framework, with Fully Sharded Data Parallel (FSDP) to reduce peak memory for parameters, gradients, and optimizer states.
    • The inference side uses a high-throughput inference engine that supports continuous batching and efficient KV cache management.
    • The scheduling layer uses a distributed task orchestration framework responsible for node orchestration, resource allocation, and failure restarts.

    The four-layer architecture and data flow can be summarized as:

    1. Data engine (Parquet) → Inference engine (high-throughput generation) → Reward module (rules/model) → Training engine (FSDP) → Distributed coordination (resource scheduling)

    Simplified data flow: read samples → generate multiple answers for the same prompt → score them to obtain rewards → compute advantages and update the policy → evaluate on the validation set and save checkpoints. This “decoupling of generation and updates” is the key to a several-fold improvement in overall throughput, and it keeps the path consistent from single-GPU experiments to multi-node scaling.

    4. How GRPO Saves Memory

    Traditional Proximal Policy Optimization (PPO) requires additionally training a value model (Critic) to estimate the baseline, so memory and compute overhead rise together. The core idea of Group Relative Policy Optimization (GRPO) is: sample a group of answers for the same question, use the group’s average reward as the baseline, and directly obtain the relative advantage, thereby removing the Critic. In practice, this can save 30–40% of memory and eliminate the loading and synchronization cost of one model.

    Five training steps: Rollout (sampled generation) → Reward (scoring) → Advantage (in-group normalization) → Policy Update (clipped-objective update) → Validation (evaluation and saving).

    Illustrative code (expressing the computation logic only):

    1. import torch
    2. def group_advantages(rewards, eps=1e-6):
    3. # rewards: [group_size], multiple answers for the same question
    4. mean = rewards.mean()
    5. std = rewards.std()
    6. return (rewards - mean) / (std + eps)
    7. def grpo_loss(new_logprobs, old_logprobs, advantages, clip=0.2):
    8. ratio = torch.exp(new_logprobs - old_logprobs)
    9. surr = ratio * advantages
    10. clipped = torch.clamp(ratio, 1 - clip, 1 + clip) * advantages
    11. return -torch.min(surr, clipped).mean()

    Reward extraction must also be “automatically judgeable.” For example, for a math problem, take only the number after the final answer marker and normalize it:

    1. import re
    2. def extract_answer(text):
    3. m = re.search(r"####\s*(-?[0-9.,]+)", text)
    4. return m.group(1).replace(",", "") if m else None

    5. Reproduction Workflow and Key Pitfalls to Avoid

    1. Data preparation: convert everything into a structured columnar file with fields that include at least the prompt, the reference answer, and an automatically judgeable answer-extraction rule; strictly isolate the training set from the validation set to avoid prompt leakage.
    2. Sampling configuration: too small a group size makes the advantage estimate noisy, while too large a group reduces throughput; too low a temperature loses exploration, while too high a temperature breaks the format, so a small-step grid search is needed.
    3. Reward design: first get the loop working end to end with a single “answer correctness” reward, then add format and step scores; keep the reward scale stable to avoid drift across batches.
    4. Memory and throughput: prioritize enabling parameter and optimizer-state sharding, gradient checkpointing, and mixed precision; use continuous batching to fill compute during generation, and control the number of samples per step during training to prevent overflow.
    5. Training stability: clip the importance sampling ratio and add a snapshot of the old policy’s log probabilities; keep the learning rate small and the number of update steps controlled to avoid policy collapse.
    6. Evaluation criteria: do not look only at the training reward; report accuracy and format compliance on a fixed validation set, and save multiple checkpoints for retrospective comparison.

    6. Engineering Deployment Recommendations

    If a team wants to build quickly on the cloud, it can assemble general-purpose capabilities: use a container platform to host training and inference images, use object storage to store datasets and checkpoints, use a message queue to decouple sampling and scoring tasks, and use logging services with monitoring and alerting to track throughput, memory, and reward curves. This avoids reinventing the wheel and makes it easy to migrate smoothly from single-GPU experiments to multi-node training.

    Overall judgment: general-purpose LLMs handle breadth, and vertical small models handle depth. With the combination of “small base model + reinforcement learning + automatically judgeable rewards + high-throughput generation,” vertical scenarios can achieve usable, or even better-than-general, results at very low cost. The key lies in the engineering details of reward design and training stability.