Vertical Domain vs. General-Purpose LLMs: How to Choose

    This article breaks down how to choose between vertical domain models and general-purpose large language models based on three practical constraints: task boundaries, data availability, and inference cost. It includes a single-GPU case study where a 1.5B model improved math accuracy from about 49% to 80%, the four common pain points of building production RL pipelines, a five-stage architecture and data flow, memory-saving techniques, reward function examples, and a pitfall checklist. The conclusion explains which scenarios fit each model type and how to build a cost-controlled "small model + reinforcement learning" iteration loop.

    1. The Real Question: Not “Which Is Stronger,” but “Which Fits the Constraints”

    Most debates about vertical domain models versus general-purpose models stay stuck on parameter counts and benchmark scores, which offers almost no guidance in engineering practice. What actually determines the outcome are three constraints: whether the task boundary is clear, whether data and annotations are available, and whether the per-inference cost is acceptable.

    The value of a general-purpose model lies in breadth and emergent capability. It has clear advantages in open-domain conversation, cross-domain knowledge Q&A, and long-tail common-sense understanding. The cost is a large parameter count, high memory usage, high cost per token, and a tendency in strongly specialized scenarios to produce output that “looks reasonable but is actually wrong.”

    The value of a vertical domain model lies in depth and determinism. When a task can be formalized as a clear input-output mapping—such as math problem solving, structured extraction, classification, or domain Q&A—model capability can be measured automatically or semi-automatically. In that case, continued training on domain data can often approach or even exceed a general-purpose model on that specific task with a much smaller parameter count.

    An easily overlooked criterion: if you cannot write a reliable automatic scoring function for your task, the payoff from vertical training drops sharply. Conversely, if the scoring function is clear, reinforcement learning on a small model is extremely cost-effective.

    2. A Practical Reference: A Vertical Capability Leap on a Single GPU

    To validate the above, you can run continued training on a math reasoning dataset for a small model in the 1.5B range, using a group relative policy optimization style algorithm, on a single high-memory accelerator card. Accuracy rose from roughly 49% to roughly 80%.

    The key point is not the numbers themselves but the engineering fact they reveal: acquiring vertical capability does not require a thousand-GPU cluster. The bottleneck is usually memory orchestration and data flow design, not total compute.

    3. Four Pain Points of Production-Grade RL Frameworks

    Building your own unified training-inference pipeline usually means hitting four walls:

    • Slow inference: autoregressive generation takes up the majority of total training time, and if the inference backend is inefficient, overall throughput is locked.
    • Tight memory: the policy model, reference model, value model, and optimizer states all reside simultaneously, making overflow easy.
    • Complex scheduling: multiple roles, multiple stages, and heterogeneous workloads need unified orchestration, and hand-written scripts are hard to maintain.
    • Difficult reward design: reward functions are coupled with data formats, and there is no reusable scoring and validation layer.

    Mature solutions typically follow a “training framework + high-throughput inference engine + distributed scheduling layer” pattern, decoupling generation from updates to avoid reinventing the wheel.

    4. Architecture and Data Flow: A Five-Stage Loop

    The typical layering has four layers: data engine, inference engine, training engine, and distributed coordination layer. The data flow forms a closed loop:

    1. Read data (columnar format, suitable for streaming and sharding)
    2. Inference nodes batch-generate multiple candidate responses
    3. The reward layer scores them (rule matching or model review)
    4. Training nodes update policy parameters (data parallelism + parameter sharding)
    5. Validation, evaluation, and checkpoint saving

    The engineering key is that strict sample alignment and masking must happen between step 3 and step 4: compute loss only on the generated portion, and mask the prompt portion, otherwise gradients get polluted.

    5. How Memory Is Saved

    The core idea of group relative algorithms is to sample multiple responses for the same question and use the group average as a baseline instead of a separate value network estimate. This removes one model to maintain, and memory usage typically drops by 30% to 40%. Example code:

    1. def group_relative_advantage(rewards, eps=1e-6):
    2. # rewards: [batch, group_size]
    3. mean = rewards.mean(dim=1, keepdim=True)
    4. std = rewards.std(dim=1, keepdim=True)
    5. return (rewards - mean) / (std + eps)
    6. def policy_loss(new_logp, old_logp, adv, clip=0.2):
    7. ratio = (new_logp - old_logp).exp()
    8. return -torch.min(ratio * adv,
    9. ratio.clamp(1 - clip, 1 + clip) * adv).mean()

    Further memory savings include: sharing low-precision weights between the reference model and the policy model, enabling gradient checkpointing, using sharded optimizer states, and fully offloading the generation stage to a separate inference process.

    6. Reward Functions: The Real Barrier to Vertical Deployment

    Take math reasoning as an example: you need to extract the final answer from the model output and compare it with the ground truth:

    1. import re
    2. def extract_answer(text):
    3. m = re.search(r"####\s*(-?[\d,\.]+)", text)
    4. return m.group(1).replace(",", "") if m else None
    5. def rule_reward(text, gold):
    6. pred = extract_answer(text)
    7. return 1.0 if pred is not None and pred == gold else 0.0

    The practical recommendation is layered rewards: a small score for format validity, the main score for answer correctness, and an adjustment score for process consistency. Pure sparse rewards cause no gradient signal early on, so you can first do small-scale rejection sampling fine-tuning as a cold start.

    7. Pitfall Checklist

    • Sampling temperature and group size must match; too small a group means a noisy baseline.
    • Length inflation is a common degradation and needs a length penalty.
    • Inconsistent precision between training and inference causes importance ratio drift, so unify numerical precision.
    • The validation set must be decoupled from the training reward to avoid “score goes up, capability does not.”
    • Checkpoints must retain optimizer states, otherwise resumed training oscillates.

    8. Selection Conclusion

    General-purpose models fit scenarios with fuzzy boundaries and changing requirements; vertical small models fit scenarios with clear tasks, automatic evaluation, and high call volume. If an enterprise wants to deepen vertical capability under controllable cost, it can rely on a container platform for elastic scheduling, object storage for data, and logging and monitoring services for training metrics, and build a continuous “small model + reinforcement learning” iteration loop in a cloud environment such as Baidu AI Cloud—trading engineering effort rather than simply stacking parameters for capability growth.