First-Generation Open-Source LLMs: Architecture, Training Data, Alignment, and Bilingual Evaluation

    This article walks through the general technical roadmap for building a first-generation open-source large language model. It covers architecture choices (dense Transformers, MHA vs. GQA), training data construction (deduplication, filtering, shuffling), post-training alignment (SFT and DPO), and fair bilingual evaluation practices, plus engineering tips and common pitfalls for teams with limited resources.

    First-Generation LLM Architecture and Training Data Construction: A Practical Guide

    1. Why Focus on First-Generation Base Models

    The base model is the starting point for all downstream capabilities. It determines parameter scale, attention structure, training corpus quality, and the alignment strategy. First-generation models typically face two challenges: a lack of mature engineering experience, and limited resources that make it hard to explore multiple architectures in parallel. The common industry approach is therefore to first replicate a proven dense Transformer design, and then concentrate effort on training data quality.

    The core judgment behind this approach is that, given similar architectures, data quality and cleaning strategy usually yield more stable gains than structural tweaks.

    2. Architecture Choices: Dense Structures and Attention Mechanisms

    2.1 Dense Transformer Architecture

    Most first-generation open-source models adopt a dense architecture, where every token is processed by all parameters. Compared with Mixture-of-Experts (MoE), dense models have simpler training and inference pipelines and lower debugging costs, making them a good baseline.

    2.2 Multi-Head Attention vs. Grouped-Query Attention

    The main inference cost of the attention layer comes from the key-value cache (KV cache). In multi-head attention (MHA), each query head has its own key and value heads, so the cache size scales with the number of heads. Grouped-query attention (GQA) lets multiple query heads share one set of key-value heads, compressing the cache.

    1. # H: number of query heads G: number of key-value head groups
    2. # d: per-head dimension L: sequence length b: bytes per element
    3. kv_cache_bytes = 2 * L * G * d * b # 2 accounts for one copy each of keys and values
    4. # In MHA, G = H
    5. # In GQA, G < H, and the cache size is roughly G / H of MHA

    Practical trade-offs:

    • For smaller models, MHA’s inference overhead is manageable, so full head independence can be kept.
    • For larger models serving many concurrent requests, GQA significantly reduces memory usage and improves throughput.
    • With 64 query heads and 8 key-value groups, the cache shrinks to 1/8 of the original size—an especially large win in long-context scenarios.

    3. Building the Training Corpus: Deduplication, Filtering, and Shuffling

    Data quality is the key variable for first-generation model performance. A complete data pipeline typically has three stages.

    3.1 Deduplication

    Duplicate documents cause the model to over-memorize certain content and distort the training distribution. Deduplication usually has two layers:

    • Exact deduplication: hash document content and remove identical documents.
    • Near deduplication: use methods like MinHash to estimate document similarity and remove highly similar copies.

    Web corpora often contain a high duplication rate, so the dataset may shrink substantially after deduplication. This is normal and does not mean useful information is lost.

    3.2 Filtering

    Filtering rules remove low-quality content. Common dimensions include:

    • Language identification, ensuring the ratio of Chinese to English text matches the design target;
    • Text length, removing documents that are too short or abnormally long;
    • Character quality, such as the ratio of garbled characters, repeated characters, or symbols;
    • Detection and removal of sensitive or policy-violating content.

    Rule thresholds should be tuned through manual spot-checks to avoid accidentally deleting valuable professional text.

    3.3 Shuffling

    Shuffling randomizes document order so the model is not exposed to long runs of data from the same source during training. A simplified pipeline looks like this:

    1. def build_corpus(raw_docs):
    2. docs = [d for d in raw_docs if not is_empty(d)]
    3. docs = exact_dedup(docs) # remove identical documents via hashing
    4. docs = near_dedup(docs, threshold=0.8) # remove highly similar documents via MinHash
    5. docs = [d for d in docs if passes_quality(d)] # language, length, character quality, etc.
    6. random.shuffle(docs) # shuffle order to reduce distribution shift
    7. return docs

    4. Post-Training Alignment: Supervised Fine-Tuning and Preference Optimization

    A pretrained model is good at continuation but does not necessarily follow instructions. Post-training alignment usually happens in two steps.

    4.1 Supervised Fine-Tuning (SFT)

    SFT trains the model on instruction-response pairs so it learns to understand task formats. Data quality matters more than quantity. In practice, the data should cover question answering, summarization, rewriting, code, reasoning, and other task types, with consistent answer formatting and tone.

    4.2 Direct Preference Optimization (DPO)

    DPO uses preferred and rejected responses to the same prompt to directly optimize the model’s relative probability between them, without training a separate reward model. Its simpler pipeline suits teams with limited resources. Points to watch:

    • Preference annotation standards must be consistent, or the model learns contradictory signals;
    • With too large a learning rate or too many epochs, the model can drift from the base distribution, producing shorter, repetitive, or overly conservative answers;
    • General capabilities should be re-checked after each round to prevent alignment from degrading base abilities.

    4.3 Base Model vs. Chat Model

    The base model retains full continuation capability and suits further training, evaluation, and research. The chat model, after SFT and preference optimization, is ready for direct end-user interaction. Both should be released together with their intended uses clearly labeled, so users do not misjudge the appropriate scenario for each.

    5. Evaluation: Bilingual Chinese-English Benchmarking

    Evaluation determines whether a team can judge the model’s true level. For a bilingual model, keep these points in mind:

    • Benchmark coverage: both Chinese and English need test sets covering knowledge QA, reading comprehension, math reasoning, code, and common sense.
    • Unified evaluation protocol: question format, prompts, and answer extraction rules must be fixed and publicly documented, or results are not comparable.
    • Fair comparison: when comparing with other models, use the same benchmark versions and decoding parameters.
    • Result interpretation: a single score is not enough—break results down by task category and look for common patterns in error cases.

    6. Engineering Recommendations and Common Pitfalls

    In real projects, the following practices reduce rework:

    1. Build a small-scale baseline first—validate the data pipeline and training scripts on a smaller model before scaling up.
    2. Record the data version, hyperparameters, and evaluation results for every experiment to enable traceability.
    3. Continuously spot-check the training data; when problems appear, trace them to specific cleaning rules rather than only adjusting the model.
    4. Budget for inference costs in advance, and weigh both training and deployment when choosing the attention structure.

    Common pitfalls include:

    • Assuming more data is always better, while ignoring the impact of duplicates and low-quality content;
    • Focusing only on a single leaderboard score while neglecting how task distributions differ from real usage;
    • Over-optimizing for response style during alignment, which degrades base capabilities.

    7. Summary

    Building a first-generation LLM comes down to three things: choosing a reliable dense architecture and weighing attention designs against inference cost, establishing a rigorous data cleaning and shuffling pipeline, and verifying results with unified, fair bilingual evaluation. With these general methods, a resource-constrained team can reliably complete the full workflow from base training to aligned delivery.