Data Engineering Practices for Large Autoregressive Language Models

    This article explains why data engineering sets the performance ceiling of autoregressive language models and walks through a practical pipeline: compliant corpus sourcing, layered cleaning and deduplication, pre-tokenization and storage layout, mixture ratios and curriculum scheduling, training orchestration with compute estimation, and observability tied to dataset versions. It also lists common pitfalls such as data leakage, duplication amplification, and mixture drift, along with concrete configuration and code examples.

    1. Why Data Engineering Sets the Model Ceiling

    In autoregressive language model training, model architecture, optimizers, and hyperparameters get most of the discussion, yet the real ceiling on capability is usually set by data. The reason is straightforward: the autoregressive objective only models the conditional probability of the next token, so the distribution a model can learn comes entirely from the corpus distribution. Knowledge missing from the corpus will not be “reasoned out,” while repetition and noise in the corpus get amplified into memorization and degradation.

    Data engineering should therefore be treated as a first-class citizen, not as preparation work done before training. A mature data pipeline needs to satisfy at least three properties: traceability (every batch can be traced back to its source and processing version), reproducibility (the same configuration produces the same dataset fingerprint), and observability (throughput, discard rate, and mixture drift all have metrics).

    2. Corpus Acquisition and Compliance Boundaries

    The first step is defining the source structure of the corpus. A common approach splits the corpus into several broad categories, for example general web text, encyclopedic and knowledge text, books and long-form text, code, math and reasoning text, dialogue and instruction text, and in-house business data. The point of categorizing is controllable mixture ratios later: sources differ enormously in quality and noise characteristics, and pooling them together for statistics hides problems.

    Acquisition must be compliance-first: use only licensed, openly permitted, or self-built data; keep a source inventory with license information; detect and redact personal information and sensitive fields; and respect robots protocols and access rates. In engineering terms, make “source registration” a mandatory field so that data without a recorded source cannot enter downstream stages.

    1. raw_record = {
    2. "source_id": "...", # source registration, required
    3. "license": "...", # license information, required
    4. "lang": "zh", # language detection result
    5. "text": "...", # raw body text
    6. "ingest_ts": 1700000000 # ingestion timestamp
    7. }

    3. Layered Cleaning and Deduplication

    Cleaning should not be one large one-off script. It should run in layers, where each layer does one thing and emits statistics.

    The first layer is format and structure extraction: strip templates, navigation, ads, and scripts from web pages, keeping the body text and necessary heading hierarchy. The second layer is quality filtering: score documents by rules such as length, symbol ratio, repeated-line ratio, and language confidence; low-scoring samples go to a quarantine area instead of being discarded outright, which makes them traceable. The third layer is privacy and safety checks: detect ID numbers, contact details, and key-like strings, then replace them. The fourth layer is deduplication.

    Deduplication usually has two levels. At the document level, use hash-based exact deduplication plus near-duplicate detection (for example, split by paragraph and compute set similarity). At the token level, run substring-level duplicate detection after pre-tokenization to surface hidden duplication such as “the same paragraph concatenated over and over.” In practice, the gains from deduplication for training stability and evaluation fidelity often outweigh simply adding more data.

    1. def quality_score(doc):
    2. n = len(doc)
    3. if n < 64:
    4. return 0.0
    5. sym_ratio = sum(c in ",。!?、;:" for c in doc) / n
    6. line_repeat = 1.0 - len(set(doc.splitlines())) / max(1, len(doc.splitlines()))
    7. return max(0.0, 1.0 - 0.5 * line_repeat - 0.3 * abs(sym_ratio - 0.05) * 10)

    4. Pre-Tokenization and Storage Format

    Pre-tokenization converts text into token sequences once and writes them to disk, so tokenization is not repeated every training epoch. There are three benefits: data loading costs almost no CPU during training; it becomes easy to count total tokens and track mixture ratios; and it enables token-level deduplication.

    For storage, use binary shards plus an index file. Each shard holds a fixed-length array of tokens, and the index records sample boundaries and source labels for each shard. This supports high-throughput sequential reads while still allowing sub-sampling by source.

    1. shard_00042.bin -> [token, token, token, ...]
    2. index.json -> {"shard": "shard_00042.bin", "source": "code", "tokens": 1048576}

    5. Mixture Ratios and Curriculum Scheduling

    The mixture ratio is the most underrated parameter in data engineering. If one category takes up too large a share, the model drifts in style; if knowledge-heavy text is underrepresented, factual question answering clearly falls behind. In practice, start from a balanced baseline, then make small adjustments based on evaluation results, changing only one ratio dimension at a time and fixing the random seed to keep runs comparable.

    Curriculum scheduling means changing the data distribution across training stages: early on, favor general and long-form text to build language and structure capability; in the middle, raise the share of code and reasoning text; later, introduce high-quality instruction and dialogue data to align output format. The schedule should live in configuration, not as constants in code.

    1. curriculum:
    2. - stage: general
    3. steps: 0
    4. mix: {web: 0.5, book: 0.2, code: 0.2, math: 0.1}
    5. - stage: reasoning
    6. steps: 0
    7. mix: {web: 0.3, book: 0.15, code: 0.35, math: 0.2}

    6. Training Orchestration and Compute Estimation

    For training, use a mature open-source training framework (any common industry option works). Core settings include the parallelism strategy (a combination of data, tensor, and pipeline parallelism), gradient accumulation, mixed precision, and checkpoint frequency. On the data side, ensure enough prefetch threads so compute never waits on I/O.

    Estimate resources roughly from parameter count and total tokens first: the floating-point operations required for training are approximately 6 times the parameter count times the token count. Divide by the effective compute of a single GPU to get theoretical GPU hours, then multiply by an empirical redundancy factor (typically 1.3 to 2.0) to cover communication, restarts, and tuning overhead.

    1. def estimate(params, tokens, flops_per_gpu_s, redundancy=1.5):
    2. total_flops = 6 * params * tokens
    3. gpu_hours = total_flops / flops_per_gpu_s / 3600
    4. return gpu_hours * redundancy

    7. Observability, Evaluation, and Reproducibility

    The pipeline must have built-in metrics: discard rate per source, deduplication hit rate, drift in total token count, shard read throughput, and training loss and gradient norm curves. When a loss spike appears, suspect a sudden mixture change or contaminated data first, rather than adjusting the learning rate.

    Evaluation must be bound to the data version: the same checkpoint is not directly comparable across different data versions. Keep a fixed evaluation set and a fixed version of the evaluation scripts, and record the dataset fingerprint (a combination of shard hashes and mixture ratios). If you rely on general-purpose cloud capabilities, you can put raw data in object storage, drive processing jobs with a message queue, run distributed cleaning on a container platform, and track metrics with logging and monitoring services, turning the whole chain into a replayable job.

    8. Common Pitfalls Checklist

    • Data leakage: evaluation text leaks into the training set and inflates metrics, so cross-check training and evaluation sets during deduplication.
    • Duplication amplification: without substring-level deduplication after pre-tokenization, the model tends to recite verbatim.
    • Mixture drift: after repeated adjustments with no version records, changes in results cannot be attributed.
    • Insufficient long-form text: crude truncation weakens long-range dependency capability, so preserve complete document boundaries.
    • Wasted resources: skipping pre-tokenization means re-tokenizing every epoch, which slows throughput.

    Turn these stages into a configuration-driven pipeline and iterate with metrics, and you can reliably produce high-quality training data under limited compute, laying a reproducible foundation for later capability gains.