Full-Stack Open-Source LLM Training: Core Techniques Across the Complete Pipeline
This article examines the shift in open-source LLM development from simply releasing model weights to openly publishing the entire production pipeline. It walks through the core techniques at each stage—data engineering during pretraining (quality-aware upsampling, token-constrained data mixing, and document parsing), midtraining for capability reshaping, the three-stage post-training recipe (SFT, DPO, and RLVR), long-context extension, and engineering practices for reproduction on the cloud. Readers will gain an understanding of how data ratios and algorithmic decisions shape a model's final capabilities, and how a transparent, reproducible pipeline lowers the cost of trial and error for fine-tuning and adaptation.
Introduction: From “Shipping Weights” to “Shipping the Whole Pipeline”
Over the past few years, the competition around open-source LLMs has largely centered on a single question: are the weights open? Yet what truly determines whether a model can be reproduced, trusted, and built upon is rarely the final binary file itself, but the complete production chain behind it. Some frontier open-source projects have recently begun championing the idea of a “Model Flow”: instead of releasing only the final weights, they publish the pretraining corpus, midtraining data, post-training preference data, training framework code, intermediate checkpoints, and even training logs. This kind of “full-stack openness” is pushing large models from a black-box delivery model toward an engineering paradigm that is auditable and reproducible.
For development teams and enterprises, this represents a fundamental transfer of capability: you no longer just “use a model someone else trained,” but can stand on top of a fully disclosed pipeline and understand how every data ratio and algorithmic decision affects the final capabilities. This article follows that pipeline and breaks down the core technical points stage by stage.
1. What “Model Flow” Actually Opens Up
Traditional open-source models usually deliver only the “finish line”—a set of trained weights—while the data recipe, hyperparameter schedules, and training-stability tricks in between are all hidden. This is hard to reproduce academically and hard to optimize for specific purposes in industry. A full-stack “Model Flow” release, by contrast, breaks the entire chain into deliverables, typically including at least the following layers:
- Data assets: the pretraining mixed corpus, midtraining corpus, long-context corpus, and post-training preference/instruction data;
- Code assets: pretraining kernels, the reinforcement learning training framework, the data processing pipeline, and evaluation scripts;
- Process assets: intermediate checkpoints, learning-rate curves, and loss and gradient-norm logs.
Its value lies in attribution: when a downstream capability falls short, the team can trace back whether the problem lies in the data mixture, the number of training steps, or the post-training recipe, rather than facing an inseparable black box. For enterprises doing private fine-tuning or industry adaptation, this transparency directly lowers the cost of trial and error.
2. The Base Model: Data Engineering in Pretraining
The base model sets the ceiling for the model’s entire capability, and the data strategy all but determines the base. One conclusion repeatedly validated in the industry is that, given the relative scarcity of high-quality data, how well you use the data matters more than simply piling on more of it.
2.1 Quality-Aware Upsampling Beats Flat Filtering
A common intuitive approach is “set a quality threshold and discard everything below it”—flat filtering. The problem is that thresholding crudely cuts the distribution: some medium-quality but information-dense data gets mistakenly removed, while the volume of samples near the threshold easily gets out of control.
A better alternative is quality-aware upsampling: first score the corpus for quality, then build an “upsampling curve” based on those scores—higher-quality data is repeated at a higher multiplier, while lower-quality data is retained but down-weighted. This neither wastes the overall data volume nor, within a limited token budget, tilts the model’s attention toward higher-quality content. The key in practice is not whether to use it, but to design the curve as a tunable parameter and use ablation experiments to determine the best shape.
2.2 Token-Constrained Mixing of Multi-Source Corpora
The pretraining corpus is usually a blend of web pages, code, math, academic papers, books, and other sources. The mixing ratio directly shapes the model’s capability profile. A common engineering approach is token-constrained mixing: rather than allocating by document count, control the budget by the actual proportion of training tokens each data source contributes, and adjust it dynamically during training. For example, to improve code and reasoning ability, you can moderately raise the token allocation for code and high-quality text while constraining the excessive growth of low-quality web data.
2.3 Parsing and Enriching High-Quality Documents
Long documents that exist as PDFs—scientific papers, technical manuals, and the like—are high-value corpora that web crawling struggles to cover. Converting these documents into structured text through OCR and layout reconstruction can substantially enrich specialized knowledge in fields such as mathematics, chemistry, and engineering. The difficulty here lies in parsing quality: tables, formulas, and multi-column layouts all break the semantic continuity of the text, so a dedicated processing pipeline is needed, along with a second round of quality filtering on the parsing output to avoid feeding parsing noise in as high-quality data.
3. Midtraining: The Key Lever for Reshaping Capability
Before formal post-training, there is a stage that is often overlooked but delivers significant returns—midtraining. It typically consumes only a small fraction of the total pretraining budget (for example, on the order of tens of billions of tokens), yet it can deliberately nudge the base toward target capabilities.
3.1 Domain Tradeoffs Are the Core Question of Midtraining
The essence of midtraining is re-allocating the data mixture. And adjusting that mixture always comes at the cost of a tradeoff: when you sharply increase the weight of math and code data, the model’s performance on math and code benchmarks climbs quickly, but general capabilities such as general QA (GenQA) and multiple-choice QA (MCQA) tend to decline at the same time—and vice versa. Therefore, the corpus mixture in midtraining should not pursue optimality on a single dimension but seek a balance point across multiple capability dimensions—which is also why the final recipe is often a compromise reached after multiple rounds of ablation and repeated tuning.
One transferable lesson: turn midtraining ratio experiments into a “capability radar chart,” monitoring multiple curves simultaneously—math, code, general QA, instruction following, and so on—and use the Pareto frontier to guide tradeoffs rather than chasing a single metric.
3.2 Moving Post-Training Data “Forward” into a Low-Risk Zone
A counterintuitive but valuable finding is this: if you introduce instruction-following and thinking-format data early, during midtraining, the base model’s overall performance across benchmarks improves across the board—even before any formal SFT is done. The mechanism is that this structured data instills in the model, in advance, a prior for “how to organize an answer and how to reason step by step,” laying the groundwork for subsequent post-training. This is a low-cost, high-certainty “front-loaded investment.”
4. Reasoning Models: A Three-Stage Post-Training Recipe
What actually makes a model “think” is the post-training stage. A relatively mature approach in the industry is a three-stage recipe: SFT → DPO → RLVR.
- Stage 1, SFT (supervised fine-tuning): use high-quality demonstration data with chains of thought to teach the model the basic format of “answering through step-by-step reasoning”;
- Stage 2, DPO (direct preference optimization): use preference-pair data (“good answer vs. bad answer”) to align the model with human preferences and correct the biases introduced by SFT;
- Stage 3, RLVR (reinforcement learning with verifiable rewards): for tasks with objective answers such as math and code, use verifiable correctness as the reward signal so the model can improve itself through exploration.
4.1 Building Preference Data: The Delta Learning Approach
Collecting preference data is costly and noisy. An efficient approach is “Delta Learning”: rather than annotating from scratch, have the model generate multiple candidates under the same prompt and construct preference pairs by comparing the relative differences among them. This produces structured preference data in bulk at low cost and focuses the preference signal on the “direction of improvement” rather than absolute good or bad.
4.2 Two Key Improvements to the RL Framework
In the RLVR stage, the design of the training framework directly affects stability and efficiency. Two improvements are commonly adopted in practice:
First, remove the KL divergence penalty. Traditional RLHF uses a KL divergence constraint to keep the policy model from drifting too far from the initial model, but in a verifiable-reward setting the reward itself is sufficiently sparse and clear, so removing the KL constraint actually lets the model explore more fully and reach a higher capability ceiling (at the cost of needing to monitor training stability).
Second, introduce token-level loss. Compared with computing the loss only at the sequence level, token-level loss normalizes each generated position individually, handling answers of varying lengths more fairly and avoiding long answers dominating the gradient simply because of their length—thereby improving the balance of the training signal.
# Illustration: policy-gradient update with token-level loss and no KL term (pseudocode)for batch in dataloader:logps = policy.log_prob(batch.tokens) # log-probabilities under the current policyrewards = verifier.score(batch) # verifiable reward (e.g., answer correctness)# Advantage estimation (simplified for illustration)advantage = rewards - rewards.mean()# Token-level loss: computed and normalized per position with an effective-token maskper_token_loss = -advantage * logpsloss = (per_token_loss * batch.mask).sum() / batch.mask.sum()# Note: no KL penalty term here; rely on the reward signal and stability monitoring to prevent divergenceloss.backward()optimizer.step()
5. Supplementing Long-Context Capability
Beyond the main line of pretraining and post-training, long-context capability is a hard requirement for many deployment scenarios. The common industry practice is a “two-stage” window extension: first do regular training at a medium length (e.g., a few thousand tokens), then in the final stage continue training with a small amount of long-sequence corpus to gradually expand the context window to the target length (e.g., tens of thousands or even hundreds of thousands of tokens). This stage requires dedicated design for the data mixture, position-encoding strategy, and memory management (such as sequence parallelism and attention optimization), and it consumes far more memory and compute than regular training—often requiring mature distributed training frameworks.
6. Engineering Reproduction and Cloud Practice Recommendations
If a team wants to reproduce or adapt such a full-stack pipeline, there are several directions to start from:
- Data governance first: make the data processing pipeline a versionable, auditable asset so that any ratio adjustment can be traced back; the logic for scoring and filtering data quality should be accumulated as a separate module.
- Elastic compute scheduling: pretraining and RLVR have spiky compute demands; you can leverage elastic container platforms in the cloud and object storage to persist checkpoints, enabling on-demand scaling and resumable training.
- Full-pipeline observability: feed loss, gradient norm, learning rate, and evaluation metrics into a unified logging service and monitoring/alerting system to detect training divergence or capability regression as early as possible.
- Multi-dimensional evaluation: build a multi-dimensional evaluation matrix covering math, code, general QA, and instruction following, and use a radar chart rather than a single score to guide data-mixture decisions.
Conclusion
The real value of full-stack openness is not “getting a model for free,” but turning LLM training from a handcrafted workshop into an engineering system that can be disassembled, reproduced, and optimized. From quality-aware upsampling to capability tradeoffs in midtraining, from the three-stage post-training recipe to the RL framework improvements, every stage can be understood, reused, and improved. For developers, understanding this complete pipeline holds more long-term value than memorizing any single technique—because the real moat has never been a particular model, but the ability to string data, algorithms, and engineering into a closed loop.
