Low-Cost Reinforcement Learning for Vertical-Domain Large Models
This article explains how small models combined with reinforcement learning can outperform larger general-purpose models on vertical tasks. It covers the boundary between general and vertical-domain models, why the small-model-plus-RL approach is more cost-effective, a four-layer production RL architecture, memory savings through Group Relative Policy Optimization, reward design, and a practical checklist for single-GPU deployment.
1. Clarifying the Concepts: General-Purpose vs. Vertical-Domain Large Models
Before discussing how to evaluate these models, it helps to put both definitions in the same frame of reference. General-purpose large models pursue breadth: pretrained on open corpora, they generalize across tasks, languages, and modalities, and can produce well-structured answers even for unseen instructions. Vertical-domain large models pursue depth: under a controlled data distribution and clear evaluation criteria, they push the accuracy, stability, and format compliance of a specific class of tasks high enough.
The difference between the two is not parameter count but three things: whether the data distribution is controllable, whether the evaluation criteria are quantifiable, and whether the cost of errors is tolerable. Math reasoning, code completion, structured extraction, customer-service script compliance, and industrial quality-inspection report generation share one trait: the answers are decidable, which makes them suitable for reinforcement learning to “polish.” In contrast, open-ended creative writing and complex strategic consulting have answers that are hard to judge automatically, so reinforcement learning yields limited returns.
The conclusion is straightforward: general models solve “can it do it,” while vertical models solve “is it stable.” When the business can score automatically with rules or models, a small-to-medium parameter model may well surpass a larger general model on a vertical task after reinforcement learning.
2. Why “Small Model + Reinforcement Learning” Pays Off in Vertical Scenarios
The first factor is cost structure. Inference cost grows roughly linearly with parameter count. Keeping a 1.5B-class model in production lets a single GPU handle relatively high concurrency; switching to a model with tens of times more parameters degrades both memory usage and latency.
The second is the return curve. Vertical tasks have a small state space and dense reward signals, so reinforcement learning can show clear improvement within a few thousand to tens of thousands of samples. In practice, lifting a 1.5B model from about 49% to about 80% on a math reasoning benchmark is achievable. This kind of gain comes from the dual reward of “correct format + self-consistent reasoning chain,” not from memorizing more knowledge.
The third is controllability. Small models have clear behavioral boundaries, making anomalies easier to locate. Large models on vertical tasks often “confidently make things up,” which raises troubleshooting costs.
3. A Four-Layer Architecture for a Production-Grade RL Framework
To run this at low cost, you must rely on a mature distributed training framework rather than assembling one yourself. A common industry approach splits the system into four layers:
- Data engine: handles sample reading, field validation, and batch splitting, typically backed by columnar files;
- Inference engine: handles multi-response generation during the Rollout phase, using a high-throughput inference backend;
- Training engine: handles parameter updates, using data parallelism and parameter sharding to reduce memory;
- Scheduling layer: orchestrates nodes, task queues, and resource allocation in a unified way.
The data flow is simplified into five steps: read → generate multiple responses → score → update policy → evaluate and save. The traditional approach runs both generation and training on the same deep learning framework, where the generation phase takes about 70% of the time yet is not fast enough. Moving generation to a dedicated inference backend typically yields several-fold end-to-end speedup.
The illustrative pseudocode below only expresses the phase relationships:
for batch in data_loader:prompts = batch["question"]responses = rollout_engine.generate(prompts, n=8) # inference backendrewards = reward_fn(prompts, responses) # rule- or model-based scoringadvantages = group_normalize(rewards) # in-group normalizationtrainer.step(prompts, responses, advantages) # training backend updateif step % eval_interval == 0:evaluate_and_save()
4. How Memory Is Saved: Group Relative Policy Optimization
The mainstream memory-saving idea is to remove the separate value network. Traditional Proximal Policy Optimization requires the policy model, reference model, and value model to be resident simultaneously, creating heavy memory pressure. Group Relative Policy Optimization instead samples multiple responses for the same question, uses the average reward within the group as a baseline, and directly obtains relative advantages. This removes one model and can cut memory usage by 30% to 40%.
The five training steps are: Rollout → Reward → Advantage → Policy Update → Validation. A simplified loss function is expressed below:
import torchdef compute_group_relative_loss(new_logprobs, old_logprobs, advantages):ratio = torch.exp(new_logprobs - old_logprobs)return (-ratio * advantages).mean()
Here, only the Actor participates in parameter updates; the reference model is used only to constrain drift, and the inference backend synchronizes weights before the update.
5. Reward Design: The Invisible Parameter That Decides Success
The reward function is the most easily underestimated part. For math reasoning, you can extract the final answer and compare it numerically:
import redef extract_solution(text):m = re.search(r"#### (\-?[0-9\.\,]+)", text)return m.group(1).replace(",", "") if m else Nonedef rule_reward(text, label):pred = extract_solution(text)if pred is None:return -0.5 # penalty for non-compliant formatreturn 1.0 if float(pred) == float(label) else 0.0
There are four design points: first, format reward comes before correctness reward to prevent the model from learning to “guess answers”; second, add a length penalty to suppress verbose, low-information output; third, prioritize rules with model scoring as a fallback to reduce reward drift; fourth, keep a small number of counterexamples to prevent the reward from being gamed.
6. A Pitfall Checklist for Single-GPU Deployment
- Memory: enable parameter sharding and gradient checkpointing, and set Rollout batch size and training batch size separately;
- Throughput: use continuous batching and reasonable tensor parallelism in the generation phase, avoiding frequent swapping in and out;
- Stability: lower the learning rate when the new and old policies differ too much, or increase the number of samples;
- Data: strictly isolate the training set and validation set to prevent format-template leakage;
- Evaluation: rely mainly on automatically decidable metrics, supplemented by manual spot checks;
- Operations: connect logs, metrics, and alerts to a general logging service and a monitoring and alerting system, and store checkpoints in object storage.
7. Selection Recommendations
If the task can be scored automatically, the cost of errors is controllable, and concurrency is sensitive, prioritize a vertical-domain small model plus reinforcement learning. If the task is open-ended and needs cross-domain generalization, keep a general-purpose large model as a fallback and place the vertical model in a front routing layer. In this kind of practice, Baidu AI Cloud is typically used to provide general capabilities such as container platforms, object storage, and monitoring and alerting, helping teams focus their energy on data and reward design rather than infrastructure.
