Lazy loaded image2.4 Continued Pre-training (CPT)

2.4 Continued Pre-training (CPT)

To obtain a large language model with outstanding capabilities in a specific vertical domain, it may be necessary to perform continued pre-training on data from that domain. Code and mathematics LLMs are two typical examples, such as Codex, Code LLaMA, DeepSeekMath, etc.

2.4.1 Fine-tuning or Continued Pre-training?

In papers such as Codex, Code Llama, and others, the process of further training a pre-trained model on code data is often fine-tuning rather than continued pre-training. These earlier works tended to adopt the paradigm from the BERT era, i.e., pre-training + fine-tuning, and thus chose to use the term fine-tuning. However, as time has passed, more and more work has opted for pre-training + continued pre-training + fine-tuning, especially when considering factors such as the volume of data used, the training objectives, and the optimization setup.
As mentioned in [3.1.1 Difference Between SFT and Pre-training], both the goal and training data format of pre-training are different from the SFT, where the former aims for knowledge injection. Here, adapting the model to another domain, like coding, is referred to as continued pre-training because we want the model first to absorb enough knowledge from that domain and then fine-tune it for instruction following.
📌
When is it necessary to continue pre-training?
It is necessary to continue pre-training when there is a significant difference in data distribution between the pre-training corpus and the downstream task corpus, such as general corpus v.s. code corpus. Note that the essence of such difference is token distribution difference because specific domains like legal, medical, coding, etc. usually have their own terminology.
For example: Suppose your current task is to perform Named Entity Recognition (NER) on legal documents, but the BERT model you're using is a general-purpose bert-base-cased. To achieve better performance on the downstream task, it's best to continue pre-training the model on a large amount of legal-domain text to obtain a pre-trained model that is better adapted to the legal field.

2.4.2 Continuing Pre-training at Vertical Domain

This usually refers to training a base model on domain-specific data to create a domain-specialized model, injecting domain knowledge — for example, models for code, legal texts, etc. The training process is the same as pre-training, but the data used and the amount of data are different. Generally, approximately general-domain data : domain-specific data : instruction data = 7:2:1.
  • General-domain data can come from parts of the base model's data.
  • Domain-specific data typically needs to be additionally collected, filtered, and selected. You can reuse the base model’s data preprocessing pipeline for cleaning and deduplication.
As we mentioned in [the Pretraining Tricks from 2.3.3 Pre-training Strategy], it’s common to add certrain ratio of instruction data during pre-training to boost its performance on later SFT stage. This is why in this CPT stage we add 10% of instruction data.
<ins/>

2.4.3 Long-text Continuing Pre-training

🌟
Example
Sample a 20B dataset for continued pretraining data, using the CodeLlama method for long-text continued pretraining and extrapolation method could be NTK-Aware.
  • Parameter Settings: Based on CodeLlama’s long context fine-tuning strategy, continuing from a previously trained language model base, long-text data is used for continued pretraining
    • Continue pretraining with a sequence length extended from 4096 to 16384
    • Adjust the RoPE parameter so that the increases from 10,000 to 1,000,000. This reduces the attenuation effect of RoPE on distant tokens, thereby helping mitigate the decay of attention scores and allowing the model to focus more on long-range dependencies.
  • Pretraining Acceleration
    • For long-text input, apply context parallel parallel training. Sequence input is segmented according to model input length, similar to the principle of ring attention/flash attention, significantly improving model throughput (by 50%+ on 32k/128k training), speeding up long-text training.
Prev
2.3 Pre-training Workflow
Next
2.5 Pre-training Evaluation
Loading...
Article List
LLM Learning Roadmap
✨ Awesome-Anything
🖼️ Digital Image Processing
🍃 LLM Components
🌱 LLM Pre-training
☘️ LLM Post-Training
🍀 LLM Popular Models
🪴 LLM Applications
🌿 LLM Optimization
🌾 LLM Compression
🌵 LLM Hands-on Practice
🌴 LLM Must-read Papers
🌳 LLM Q&A
🐝 VLM Image Encoders
📝 MISC.