Resources/Model training/Training methods

Method

Continued pre-training

Continued pre-training trains a model on your raw text the way it was first trained: by predicting the next word. It adds knowledge of your domain, not new behaviour, so it is usually followed by a supervised run.

Chapter 74 min read5 references

What it is

A base model learned what it knows in pre-training: predicting the next word across a vast amount of public text. Continued pre-training runs that same process a second time, on your text. There are no prompts, no replies and no grader; the model reads your documentation and becomes better at predicting how it continues, which means it absorbs its vocabulary, its entities and its facts.

The idea is well established. Gururangan et al. (2020) showed across four domains (biomedical and computer-science papers, news and reviews) and eight tasks that a second phase of pre-training on in-domain text improved results, and that pre-training on the task's own unlabelled text helped even after that.

How the text is prepared

  • Passages of about 700 words, cut at paragraph breaks so no passage ends mid-thought. Very short documents may be skipped.
  • Personal data is redacted, as in any data prep.
  • About 5% of passages are held out, so the loss can be measured on text the model never trains on.
1 · CUT AT PARAGRAPH BREAKSABCDEFheld out (~5%)one passage ≈ 700 words ≈ 900 tokens2 · PACK INTO 2,048-TOKEN SEQUENCESsequence 1ABsequence 2CDEfullfullthe loss covers every token: there is no question and answer, only text
How documents become continued pre-training data. Text is cut into passages of about 700 words at paragraph breaks, so no passage ends mid-thought, and about 5% are held out to measure the loss on text the model never trains on. On Hugging Face, short passages are then packed side by side into full-length sequences, so no compute is spent on padding. Lengths are illustrative.

How each provider trains it

Hugging Face: each passage is one text line. The loss covers every token, unlike supervised training, where only the reply counts. Short passages are packed together into full-length sequences, so no compute is spent on padding.

One passage for Hugging Face
{"text": "Sharing reports\n\nAny report can be shared with a client from the Share menu. The client receives an email with a link that opens without an account…"}

Vertex AI open models (Gemma, Llama, Qwen): there is no plain-text mode, so each passage goes in as a prompt and a completion, with the document's title as the prompt. Vertex learns the completion, which is the passage. Vertex may not show a loss curve for this kind of job.

The same passage for Vertex AI open models
{"prompt": "Sharing reports",
 "completion": "Any report can be shared with a client from the Share menu. The client receives an email with a link that opens without an account…"}
Hugging Face · plain text
passage→textone line per passage→learns every token
Vertex AI open models · prompt and completion
promptthe document's title+completionthe passage→learns the passage
The same passage, written the way each provider can train on it. Hugging Face takes plain text. Vertex AI open models have no plain-text mode, so the document title stands in as the prompt and the passage is the part that is learned.

Not available elsewhere. Gemini, Azure, Fireworks and current Bedrock models don't offer continued pre-training; Bedrock only ever did for Titan Text, which is retired. On those providers, documents become generated Q&A instead.

Knowledge, not behaviour

After continued pre-training the model knows more but doesn't necessarily answer better: it was trained to continue text, not to reply to a question. Allen-Zhu & Li (2023) found that knowledge a model has memorised is not always extractable by questions, and that varied phrasings of the same fact are what make it retrievable. So the usual recipe is continued pre-training first, then a supervised run, on chats or generated Q&A, that continues from the trained model.

Base modelgeneral knowledge
→reads your textContinued pre-trainingnow knows your documents
→continue fromSupervised runchats or generated Q&A: uses that knowledge to answer
Continued pre-training adds knowledge, not behaviour. A model that has only read your documents continues text; it doesn't yet answer questions about it. A supervised run that continues from it teaches it to use what it read.
Sizing a run (illustrative)
  1. A help center of 120,000 words is cut into about 170 passages of roughly 700 words.
  2. About 5% (9 passages) are held out; 161 are trained on, about 113,000 words.
  3. At about 1.3 tokens per word that is roughly 150,000 tokens per epoch. Two epochs train on about 300,000 tokens.
  4. Packed into 2,048-token sequences, one epoch is about 72 sequences. With LoRA rank 32 on a small open model, that is a short, inexpensive job.
  5. A supervised run on the support chats plus generated Q&A then continues from it, and is evaluated against it.
  6. By contrast, a pilot on a 2,000-word document gives three passages: it proves the pipeline works, but it is far too little text to change the model.

When to choose it

  • Choose it when you have a large body of documentation (tens of thousands of words or more), train an open model, and plan a supervised run afterwards.
  • Choose generated Q&A when you want better answers soon, have fewer documents, or train on a provider without continued pre-training.
  • Consider both: continued pre-training to absorb the documentation, then generated Q&A and chats to teach the model to answer from it.

Settings

Passage lengthTypical About 700 words#

How long each training passage is. About 700 words, cut at paragraph breaks, so each passage is a coherent piece of text and fits comfortably in one training sequence. Very short documents may be skipped as too short to teach anything.

EpochsTypical 1–3#

How many times the model reads all the passages. Keep it low: many passes make the model recite passages word for word instead of using the knowledge. Each epoch also adds roughly one more epoch of cost.

LoRA rankTypical 32 (16 for other methods)#

The size of the adapter that holds what the model learns. New knowledge needs a bigger adapter than a change of style, so Scalata uses rank 32 for continued pre-training and 16 for the other methods. Biderman et al. (2024) found, on code and maths, that full fine-tuning learns changes of a rank 10–100× greater than typical LoRA settings, one likely reason low ranks fall short when the goal is new knowledge.

Common mistakes

  • Running it on a few pages and expecting a change. It needs tens of thousands of words or more.
  • Stopping after continued pre-training. The model knows more but still needs a supervised run to answer well.
  • Using many epochs. The model starts reciting passages instead of using what they say.
  • Keeping a small LoRA rank. Knowledge needs more adapter capacity than style.
  • Looking for it on Gemini, Azure, Fireworks or Bedrock. Use generated Q&A there.

References and further reading

External sources open in a new tab.

  1. 01Don't Stop Pretraining: Adapt Language Models to Domains and TasksGururangan et al., 2020 · arXiv · arxiv.orgThe classic study of domain- and task-adaptive pre-training.
  2. 02LoRA Learns Less and Forgets LessBiderman et al., 2024 · arXiv · arxiv.orgLoRA versus full fine-tuning for continued pre-training, and why rank matters.
  3. 03Synthetic continued pretrainingYang et al., 2024 · arXiv · arxiv.orgWhy a small corpus teaches little on its own, and how synthetic variations help.
  4. 04SFT TrainerHugging Face TRL docs · huggingface.coTraining on plain text and packing sequences with Hugging Face TRL.
  5. 05Supervised and distillation fine-tuning for open modelsGoogle Cloud docs · cloud.google.comTuning open models such as Gemma, Llama and Qwen on Vertex AI.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.