Mitigating Catastrophic Forgetting in LLM Continual Pre-Training: A Practical Guide
This article explains why continual pre-training and domain fine-tuning often cause large language models to lose general capabilities, and presents four mainstream mitigation approaches: general corpus replay, parameter expansion, parameter-efficient fine-tuning with regularization, and training strategy tuning. It focuses on identity block expansion, covering its structure design, zero-linear initialization, parameter freezing, and weight merging back into the base model, along with practical evaluation and common pitfalls. Readers will learn how to balance domain capability gains with general capability retention.
1. The Problem: Why Learning a New Domain Often Means Forgetting Old Capabilities
In real-world LLM deployments, general open-source base models usually already perform well on language understanding, commonsense reasoning, and instruction following. Once they are applied to vertical domains such as healthcare, legal, finance, industrial operations, or biopharmaceuticals, however, they tend to show insufficient coverage of domain terminology, sparse industry corpora, and missing domain-specific expressions and business conventions. Two common engineering approaches are used to close this gap. The first is continual pre-training (CPT) on domain corpora, which lets the model absorb new linguistic statistical patterns on top of the original distribution. The second is supervised fine-tuning on domain instruction data, which teaches the model the output formats and decision preferences of specific tasks.
The problem is that both approaches substantially perturb model weights. When the training data distribution differs significantly from the original pre-training distribution, when there are too many training steps, or when the learning rate is too high, the model quickly converges toward the new distribution, and the general knowledge and language capabilities encoded in the parameters are overwritten. This is catastrophic forgetting. Typical symptoms include clear degradation in general question answering and commonsense reasoning, reduced multilingual and coding ability, stiffer instruction following, broken long-context and complex logical reasoning, and even a degraded state where the model “only answers according to domain templates.”
From an optimization perspective, forgetting is not an occasional bug but an inevitable side effect of continual training. Neural network parameters are highly shared, and general knowledge and domain knowledge are not physically isolated. Gradient updates modify how both types of capability are carried within the same shared parameters. Therefore, there are only two core strategies for mitigating forgetting: either restrict changes to the parameters that carry old knowledge, or explicitly remind the model during training that “old knowledge still matters.”
2. The Full Landscape: Four Mainstream Technical Approaches
2.1 Data Side: General Corpus Replay and Mixing Ratios
The simplest and often most effective approach is to mix a certain proportion of general corpus into the domain data, so the model keeps reviewing old knowledge while learning new knowledge. In practice, the general corpus proportion is usually kept between a few percent and twenty percent, depending on the size of the domain data and the number of training steps. Too low a ratio fails to provide review, while too high a ratio dilutes domain capability gains. The replay corpus does not have to be the original pre-training data itself. Filtered high-quality general instruction data, public encyclopedia-style text, and general dialogue samples can all serve the review purpose.
2.2 Parameter Side: Training Only New Parameters (Block Expansion)
This is the main approach detailed in this article. The core idea is to leave all original model parameters unchanged and insert new Transformer blocks, initialized as identity mappings, into the network. During training, the original parameters are frozen and only the new blocks are updated. Because each new block initially produces output identical to its input, the expanded model is bit-for-bit equivalent to the original model at the start of training. As training progresses, the new blocks gradually take over the responsibility of carrying domain knowledge, while the general capabilities encoded in the original parameters are fully preserved.
2.3 Optimization Side: Parameter-Efficient Fine-Tuning and Regularization
Parameter-efficient fine-tuning methods, represented by low-rank adaptation, adapters, and prefix/prompt vectors, naturally update only a small number of new parameters and therefore structurally suppress forgetting. Complementary to these are regularization methods, such as applying a quadratic penalty to important parameters and constraining the update magnitude weighted by parameter importance, so the model “stays as close as possible to the original solution” while fitting domain data. These methods are simple to implement but sensitive to hyperparameters, and need to be tuned jointly with the learning rate and training steps.
2.4 Training Strategy Side: Learning Rate, Steps, and Curriculum Scheduling
A lower learning rate, fewer training steps, warmup with cosine decay, and a “general first, domain later” curriculum-style data schedule can all significantly reduce forgetting. Empirically, the learning rate for continual pre-training should generally be at least an order of magnitude lower than that for pre-training from scratch, and it should be paired with a sufficiently long warmup to avoid washing away old knowledge at the start.
3. The Focus Approach: Complete Implementation Logic of Identity Block Expansion
3.1 Structure Design of Block Expansion
Suppose the original model contains L Transformer blocks. Divide these L blocks evenly into N groups, each containing M = L / N original blocks, and insert P new blocks after each group. The expanded model has a total of L + N × P blocks. Inserting blocks in groups rather than stacking them all at the end allows the new parameters to participate in feature transformation at multiple positions across the deep network. This preserves general representations in the shallow layers while enabling domain-specific adjustment of mid- and high-level semantics.
A schematic structure is shown below:
Original: [B1..BM] [B(M+1)..B2M] ... [B(L-M+1)..BL]Expanded: [B1..BM] [N1..NP] [B(M+1)..B2M] [N1..NP] ... [BL] [N1..NP]
3.2 Constructing the Identity Block: Zero-Linear
To make each new block an identity mapping at initialization, the key is to set the weights of the “last linear layer” in both the multi-head attention sublayer and the position-wise feed-forward sublayer entirely to zero, while keeping their biases at zero. As a result, the attention sublayer always outputs a zero vector, and after the residual addition the main information passes through unchanged. The feed-forward sublayer works the same way. Since the structure of LayerNorm/RMSNorm and the residual connections remains unchanged, the input and output of the entire block are strictly identical.
The following code is illustrative and only expresses the construction idea:
def build_identity_block(block):# Zero out the last linear layer of the attention sublayerblock.attn.out_proj.weight.data.zero_()if block.attn.out_proj.bias is not None:block.attn.out_proj.bias.data.zero_()# Zero out the last linear layer of the feed-forward sublayerblock.ffn.down_proj.weight.data.zero_()if block.ffn.down_proj.bias is not None:block.ffn.down_proj.bias.data.zero_()return block
It is important to emphasize that zeroing happens only at the initialization stage. Once training starts, these linear layers receive gradients normally and gradually become non-zero, so the new blocks gain real expressive power. If zeroing is understood as “permanent masking,” the domain adaptation effect is completely lost.
3.3 Parameter Freezing Strategy During Training
After expansion, freeze all parameters of the original L blocks (including the embedding layer and the output head), and unfreeze only the N × P new blocks. The number of trainable parameters is usually only a small fraction of the original model, so the memory and communication overhead on a single GPU or a small number of GPUs drops significantly and training throughput improves noticeably. Because the original parameters do not participate in updates, general capabilities are “physically protected” at the parameter level. This is also the most direct reason this approach suppresses forgetting.
for p in base_model.parameters():p.requires_grad = Falsefor p in new_blocks.parameters():p.requires_grad = True
3.4 Capability Transfer: Merging New Blocks Back into the Main Model
Training only the new blocks introduces a new problem: if the expanded structure is always kept during inference, both model size and inference cost increase. To address this, after training converges, perform a parameter merge (combine the increments of the new blocks into the original blocks), then prune the new blocks. This yields a model with the same scale as the original but with domain capabilities. The merge usually requires a search over the scaling coefficients of the new blocks, using a weighted metric of general and domain capabilities on the validation set as the objective to select the optimal values. This step converts “structural isolation” into “parameter-level fusion.” It is the key step in engineering deployment that is most easily overlooked yet has a large impact on final results.
4. Supporting Practices
- Set data ratios first: use small-scale experiments to determine the general replay ratio and domain data purity before scaling up training, avoiding rework after large-scale training reveals an imbalanced ratio.
- Layered evaluation: maintain both a general capability set (commonsense QA, multilingual, coding, long-context) and a domain capability set (terminology understanding, industry QA, structured extraction), evaluate them at a fixed cadence, and plot the trade-off curve between the two.
- Training monitoring: track changes in the weight norms of the new blocks’ linear layers. If they stay close to zero for a long time, the learning signal is insufficient; if general metrics decline rapidly, the learning rate or number of steps is too large.
- Combine with parameter-efficient fine-tuning: adding low-rank adaptation inside the new blocks can further compress trainable parameters, which suits compute-constrained scenarios.
- Engineering support: data version management, experiment tracking, distributed training, and monitoring and alerting are best built on general-purpose container platforms, object storage, logging services, and monitoring and alerting capabilities, ensuring reproducible experiments and elastic resource scaling.
5. Selection Guidance and Common Pitfalls
If the domain data volume is large (over one billion tokens) and there is an extremely high requirement to preserve general capabilities, prioritize the “train only new parameters” route represented by identity block expansion. If the domain data volume is limited and the task boundary is clear, parameter-efficient fine-tuning plus general replay usually offers better cost-effectiveness. If compute is abundant and the cost of full evaluation can be afforded, regularization methods can be added as a supplementary measure.
There are three common pitfalls. The first is treating identity block initialization as permanent masking, which prevents the model from learning domain knowledge. The second is neglecting parameter merging and scaling coefficient search, which makes the expanded model unusable in production. The third is looking only at domain metrics and not general metrics, only to discover late in training that general capabilities have clearly degraded. Avoiding these three points allows continual pre-training and fine-tuning to achieve a controllable balance between domain capability gains and general capability retention.
