20B–30B Open-Source LLMs: A Post-Training and Base Model Selection Guide

    This article provides a practical guide for teams working with 20B–30B open-source LLMs. It explains how post-training affects reasoning depth and output length, how to compare capabilities using controlled evaluations, and what criteria to use when selecting a base model. It also covers fine-tuning resource planning, data preparation, a LoRA training example, and a decision checklist for model selection.

    Open-source LLMs in the 20B–30B range offer a relatively balanced trade-off between inference cost and quality, and many teams use them as a starting point for production models. However, many observations about these models currently come from initial experience rather than unified evaluation. This article therefore focuses on how to validate those observations and how to make choices based on business conditions. It does not provide unverified rankings.

    1. Conclusions First

    • Post-training significantly changes how a model organizes its answers. Common effects include more multi-step reasoning and longer outputs.
    • A longer chain of thought does not equal higher accuracy. Whether there is a benefit must be measured on the same evaluation set by comparing both accuracy and response latency.
    • Differences between models in the same tier need to be measured with the same tokenizer, prompt template, and evaluation script. Until then, any judgment that one model is “stronger” or “weaker” is only a hypothesis to be validated.

    2. Post-Training and Reasoning Depth: Phenomena and Boundaries

    Post-training usually includes supervised fine-tuning (SFT), preference alignment (DPO, RLHF), and reasoning-oriented reinforcement learning. These methods play different roles. Preference alignment mainly improves answer style and consistency with human preferences. Improvements in reasoning ability usually depend on specially constructed reasoning data and reward signals. The two may occur together, but alignment training should not be assumed to be the cause of reasoning improvements.

    When a model “self-reflects” in its output, it shows that it has learned an output pattern; it does not automatically mean that it can correct errors. To judge whether self-reflection is useful, count two cases: answers that were originally wrong and became correct after reflection, and answers that were originally correct and became wrong. Looking only at the first category will overestimate the effect.

    3. Capability Comparison: How to Tell Whether a Gap Is Real

    Each dimension below is organized as “conclusion, evidence, applicable boundary.” A conclusion holds only when the corresponding evidence exists.

    3.1 Cross-Generation Model Comparison

    Conclusion: A reduction in parameter count does not necessarily lead to a capability drop, but this depends on the task.
    Evidence: With the same tokenizer, the same prompt template, and the same evaluation script, run the old and new models on the same set of questions, and record accuracy and average output length.
    Applicable boundary: The conclusion applies only to the task types that were tested and cannot be generalized to all scenarios.

    3.2 Out-of-Distribution Generalization

    Conclusion: On long-tail questions outside the training distribution, model performance may be weaker, and there is currently no reliable general conclusion.
    Evidence: Construct a set of questions whose style differs significantly from the training data, with at least 100 questions per category, so that real differences can be distinguished from random fluctuation. Record accuracy, refusal rate, and typical failure samples.
    Applicable boundary: If failures are concentrated in one category of questions, the conclusion should be limited to that category.

    3.3 Constraint Following for Complex Instructions

    Conclusion: When a prompt contains multiple constraints, the model may omit some conditions.
    Evidence: Design prompts containing 3 to 6 constraints, judge whether each constraint is satisfied, and calculate the follow rate for each constraint.
    Applicable boundary: The wording and number of constraints significantly affect results, and this should be noted in the report.

    3.4 Long-Text Consistency

    Conclusion: In long-text generation, the probability of contradictions may increase with length.
    Evidence: Use long-document question answering, extract facts given by the model in different passages, check whether they contradict one another, and count the number of contradictions.
    Applicable boundary: Human review is required; automatic judgment may miss semantic contradictions.

    The table below summarizes how to execute the evaluations above.

    Dimension Test method Metrics to record Decision criterion
    Cross-generation comparison Run old and new models on the same question set with the same script Accuracy, output length Treat as a difference only if the gap exceeds statistical noise
    Out-of-distribution generalization Out-of-distribution question set with at least 100 questions per category Accuracy, refusal rate, failure samples Report separately by category
    Constraint following Composite prompts with 3 to 6 constraints Follow rate for each constraint Per-constraint judgment by manual review or rules
    Long-text consistency Long-document question answering and fact extraction Number of contradictions Manual review of samples

    4. Criteria for Choosing a Base Model

    A model suitable as a base model should meet at least three criteria.

    First, it needs a solid reasoning foundation. Simple reasoning and math questions can be used to check for basic errors and to calculate the rate of obvious logical errors.

    Second, it needs high adaptability. After fine-tuning, the model should improve on the target task while not dropping substantially on general capabilities. After each fine-tuning run, a general regression set should be run, and scores before and after fine-tuning should be compared to detect catastrophic forgetting.

    Third, the hallucination rate should be controllable. On questions without answers, the model should admit that it does not know. A batch of unanswerable questions can be mixed in, and the proportion of fabricated answers and the proportion of reasonable refusals can be counted.

    5. Fine-Tuning Practice

    5.1 Environment and Resource Estimation

    The code below is based on the following version combination. In actual use, lock the versions and test them in the target environment:

    • Python 3.10 or later
    • torch 2.x (matching the CUDA version in use)
    • transformers 4.x, peft 0.x, accelerate, datasets

    For GPU memory, a 27B-parameter model requires about 54GB for weights alone in bf16 precision. A single GPU therefore usually needs to be an 80GB-class card, or multi-GPU sharding must be used. Using 4-bit quantization can significantly reduce the weight footprint, but it requires additional quantization-related dependencies and affects accuracy. LoRA training also needs space reserved for activations and optimizer states, so enabling gradient checkpointing is recommended.

    When running on a cloud platform, confirm three things: the GPU container image contains the correct CUDA version; the runtime account has permission to read training data from object storage; and multi-GPU training is launched with torchrun or a similar method. Note that device_map="auto" is used to shard a single model across multiple GPUs (model parallelism). When combined with data parallelism via torchrun, it requires separate design and cannot be mixed directly.

    5.2 Data Preparation

    Training data should be saved in JSONL format, with one sample per line. Before launch, deduplication, cleaning, and de-identification should be completed, removing personal information such as ID card numbers and phone numbers. Evaluation questions should also be removed from the training set; otherwise, evaluation results will be inflated.

    5.3 Code Example

    1. # Dependency example (lock versions for your actual environment):
    2. # pip install torch transformers peft accelerate datasets
    3. import torch
    4. from datasets import Dataset
    5. from transformers import (
    6. AutoModelForCausalLM,
    7. AutoTokenizer,
    8. DataCollatorForLanguageModeling,
    9. Trainer,
    10. TrainingArguments,
    11. )
    12. from peft import LoraConfig, get_peft_model
    13. # 1. Load tokenizer and base model (path is a local directory or an authorized model repository)
    14. base_model_path = "path/to/base_model"
    15. tokenizer = AutoTokenizer.from_pretrained(base_model_path)
    16. if tokenizer.pad_token is None:
    17. tokenizer.pad_token = tokenizer.eos_token
    18. use_cuda = torch.cuda.is_available()
    19. use_bf16 = use_cuda and torch.cuda.is_bf16_supported()
    20. model = AutoModelForCausalLM.from_pretrained(
    21. base_model_path,
    22. torch_dtype=torch.bfloat16 if use_bf16 else torch.float16,
    23. device_map="auto",
    24. )
    25. model.config.use_cache = False
    26. # 2. Configure LoRA. target_modules covers attention projections; add MLP layers if memory is insufficient or results are not good enough
    27. lora_config = LoraConfig(
    28. r=16,
    29. lora_alpha=32,
    30. target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
    31. lora_dropout=0.05,
    32. task_type="CAUSAL_LM",
    33. )
    34. model.gradient_checkpointing_enable()
    35. model.enable_input_require_grads()
    36. model = get_peft_model(model, lora_config)
    37. model.print_trainable_parameters()
    38. # 3. Build dataset. In real training, read from JSONL files; this is only a structural example
    39. raw_samples = [
    40. {"text": "User: How do I request a refund?\nAssistant: Please submit a refund request on the order page and include your order number."},
    41. ]
    42. dataset = Dataset.from_list(raw_samples)
    43. def tokenize(batch):
    44. return tokenizer(batch["text"], truncation=True, max_length=1024)
    45. tokenized = dataset.map(tokenize, batched=True, remove_columns=["text"])
    46. collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)
    47. # 4. Training parameters. Learning rate 1e-4 to 2e-4 is a common starting point for LoRA and should be adjusted based on the validation set
    48. training_args = TrainingArguments(
    49. output_dir="./output_model",
    50. per_device_train_batch_size=1,
    51. gradient_accumulation_steps=16,
    52. learning_rate=1e-4,
    53. num_train_epochs=2,
    54. logging_steps=10,
    55. save_steps=200,
    56. bf16=use_bf16,
    57. fp16=use_cuda and not use_bf16,
    58. report_to="none",
    59. )
    60. trainer = Trainer(
    61. model=model,
    62. args=training_args,
    63. train_dataset=tokenized,
    64. data_collator=collator,
    65. )
    66. trainer.train()
    67. model.save_pretrained("./output_model/lora_adapter")

    Before running, confirm three things: the data samples have been replaced with real data; base_model_path points to an authorized model; and GPU memory has been estimated before trainer.train(). After training, check whether the loss decreases stably, and evaluate separately on the general regression set and the business validation set.

    6. Model Selection Decision Checklist

    During model selection, fill in the conditions in the table below item by item, and then decide whether to adopt a given model.

    Condition Decision direction Suggested action
    Business scenario General QA, customer service, code, legal, and other scenarios have different requirements for factual accuracy For scenarios with high factual requirements, run hallucination-rate tests first
    Reasoning ceiling High requirements for complex reasoning and sufficient budget Compare directly with peer benchmark models on the same evaluation set
    Latency Whether first-token latency and throughput meet business requirements Evaluate on the target hardware