Skip to Content
Recodocs

10 · Continued pretraining

On 1.5 million tokens of Swahili Wikipedia, Qwen2.5-0.5B's Swahili perplexity fell from 80.60 to 15.43 with LoRA and 13.84 with full fine-tuning; English perplexity rose about 0.1 nats unless English was replayed, and the greedy continuations still looped.

20 min read
Part 3
Beyond supervised
Model
Qwen/Qwen2.5-0.5B (base)
Data
Swahili Wikipedia, with English text as the control
Hardware
One T4, in Google Colab
Open in ColabSaved with the outputs of a GPU run

Lessons 4 to 9 taught a model a task: a question in, one SQL query out. Sometimes the problem is lower down. The model has never read enough of your domain's words, spellings and facts, and no amount of question-and-answer training fixes that cheaply. Continued pretraining keeps the original objective, predicting the next token, and runs it on raw text from the domain: no labels, no prompts, no answers.

Companies and labs have reported what that bought them. Each row is the source's own account:

SourceBase model and textWhat they report
eBay, e-Llama (paper)Llama 3.1 8B and 70B, 1 trillion tokens, half e-commerce and half generalEnglish e-commerce scores up about 25% on average and non-English about 30%; general English NLU 71.8 against 71.6 for the 8B model
NVIDIA, ChipNeMo (paper, research prototype)Llama 2 7B, 13B and 70B, 24B tokens of chip-design documents and code13B chip-design benchmark 47.1 to 57.7, MMLU 55.4 to 54.0; the adaptation used about 1.5% of the GPU hours of the original pretraining
Tokyo Institute of Technology, Swallow (research, models released)Llama 2, about 100B tokens, 90% JapaneseJapanese average 32.0 to 39.4 for the 7B model; English average 49.0 to 44.0
Rakuten, RakutenAI-7B (released models)Mistral-7B, about 175B filtered Japanese and English tokens, tokenizer extended from 32k to 48kJapanese average 62.83 against 59.12 for the closest of the comparison models in its table

All four are the authors' own measurements on their own benchmarks. Swallow and RakutenAI are the closest to this lesson, because their domain is a language the base model reads badly. This lesson builds that shape at a scale a free Colab T4 can hold: Qwen2.5-0.5B, the base model, and Swahili Wikipedia, with English Wikipedia as the control. It measures what the model gains, what it gives up and what each way of training costs. It leaves the SQL task, because that needs no raw text.

The result first, then how it was reached; the exact setup, time and cost are in How it was built at the end.

Swahili perplexity fell five- to six-fold; English perplexity rose for LoRA and plain full fine-tuning and fell with replay

Perplexity on 100 held-out blocks of 512 tokens (51,200 tokens per panel); lower is better. The hollow circle is the base model

1

Swahili (the domain)

log scale

a
102050100base 80.60LoRA r=64÷ 5.215.43full fine-tune÷ 5.813.84full + replay÷ 5.215.45

English (the control)

linear scale

b
1618202224base 20.07LoRA r=64+2.6922.76full fine-tune+2.3022.37full + replay−1.8518.22
Source: lesson notebook sections 2 and 5 to 8, Colab T4. Perplexity is one pass over one fixed set of blocks and has no interval. The factor ÷ and the differences are derived from the printed values.

1. When is it the right tool?

Domain adaptation and supervised fine-tuning answer different needs. If the model struggles to read a domain's language, more domain text may help; if it misformats a report, checked input-output examples are a closer match.

Task tuning teaches a behaviour from examples. Continued pretraining teaches what the text is about, and it is the right tool only when three conditions hold.

  • The base model reads the domain badly. If it already predicts the text well, there is little to gain. A screening of candidate domains for this lesson (small samples, run apart from the notebook) found biomedical English, legal case text and Verilog easier for this model than ordinary English, and Swahili far harder, so Swahili became the domain.
  • You hold a lot of raw text. eBay used its own listings and reviews plus a classifier-selected 20% of its e-commerce share from FineWeb; ChipNeMo used 24 billion tokens of internal documents and code. Without text of that kind, retrieval over the documents is cheaper than changing weights.
  • You can afford a base-model run and then a task step. ChipNeMo reports that adapting a chat-aligned model damaged its alignment, so the order is: continue pretraining the base model, then instruction-tune it (lessons 4 to 9).

BloombergGPT is the alternative at the other end. Bloomberg trained a 50B model from scratch on 363B tokens of financial text and 345B public tokens, a budget it puts at 1.3 million A100 GPU hours. Against that, ChipNeMo's adaptation of an existing model cost 2,620 GPU hours for the 7B model and 4,940 for the 13B, about 1.5% of the original pretraining compute (Table 1 of the ChipNeMo paper). Adapting an existing model is the cheaper route when its base is good enough.

2. Does the model read it badly?

A tokenizer cuts text into pieces from a fixed vocabulary. A common word is one piece; a word the vocabulary has not seen is cut into fragments. More pieces per word costs context and compute, and usually means the model has seen the word seldom.

def tokens_per_word(texts):
    words = sum(len(t.split()) for t in texts)
    pieces = sum(len(e) for e in tok(texts)["input_ids"])
    return pieces / words

LONG = re.compile(r"\b[a-z]{9,}\b")      # lower-case words of nine or more letters
def pieces(word):
    return len(tok(" " + word)["input_ids"])

The tokenizer cuts nearly every long Swahili word into three or more pieces; English words almost never

Qwen2.5-0.5B tokenizer on 300 held-out Swahili articles and 400 held-out English paragraphs; the six words are the most frequent long Swahili words cut in four

2
Tokens per wordwhole held-out documents1.372.50EnglishSwahiliTokens per long wordwords of nine or more letters1.324.16EnglishSwahiliCut in 3+ pieces, %of the same long words8.095.5EnglishSwahiliHow six long Swahili words are cuteach piece is one vocabulary entryWordPiecesCountmbalimbalimb · al · imb · ali4alizaliwaal · iz · ali · wa4kaskazinik · ask · az · ini4mwigizajim · wig · iz · aji4wanafunziwan · af · un · zi4mtakatifumt · ak · at · ifu4Pieces are shared with unrelated words, so the model hasseen these spellings only as fragments.
Source: lesson notebook section 1. Long words are lower-case ASCII words of nine or more letters: 6,977 Swahili and 3,874 English occurrences. Pieces are the tokenizer's vocabulary entries, shown without the leading space.

Swahili costs 2.50 tokens per word against 1.37 for English. For words of nine or more letters the gap is wider: 4.16 pieces against 1.32, and 95.5% of long Swahili words are cut into three or more pieces against 8.0% of English ones. Swahili builds long words from prefixes and stems (alizaliwa, "was born"), and the vocabulary holds fragments of them, not the stems. Rakuten met the same problem in Japanese: the Mistral tokenizer encoded kanji as byte sequences, below one character per token, so the company added 16,000 tokens and took the vocabulary from 32k to 48k before training. Swallow added 11,176 Japanese subwords for Llama 2 and reports the effect on benchmark scores as minor, with shorter sequences as the gain, and a drop of about 5 to 15% on summarisation tasks. This lab does not extend the vocabulary; section 4 prices the option.

Pieces are a symptom. The direct measure is how surprised the model is by held-out text, and that is the next section's job.

3. What is the objective?

For a text x1,…,xNx_1,\dots,x_N the model gives each token a probability given the tokens before it. Perplexity is the exponential of the average negative log-probability:

PPL=exp⁡(−1N∑t=1Nlog⁡p(xt∣x<t))\mathrm{PPL}=\exp\Big(-\frac1N\sum_{t=1}^{N}\log p(x_t\mid x_{<t})\Big)

The exponent is the mean next-token loss in nats, and the training loss is exactly that quantity. This lesson reports both: perplexity because it is what other papers quote, loss differences because they add and subtract cleanly. Two things differ from lesson 4. There is no prompt to mask, so the loss covers every token. And perplexity compares only models that share a tokenizer, which holds here because every system is the same model. Across tokenizers, loss per byte would be the comparable measure.

Perplexity says the text got less surprising, not that the model knows more. So the notebook adds a second measure that a program can score. It takes a held-out sentence and one long word in it that the tokenizer cuts into three or more pieces (eight or more letters), and builds four versions: the real word and three other long words of similar length, within two letters, taken from the same article. The model picks the version it finds most likely, so chance is 25%. The same test is built from English: 500 items drawn from all 1,547 qualifying paragraphs of the WikiText test split (English words rarely split into three or more pieces, so a smaller pool gave too few), none of which is used for training or replay.

def cloze_accuracy(model, items):
    flat = [t for it in items for t in it["texts"]]
    lp = np.array(sentence_logprobs(model, flat)).reshape(len(items), 4)
    return float((lp.argmax(1) == 0).mean())      # version 0 holds the real word

It is not a Swahili exam. A sentence with fewer pieces tends to score higher, which the length matching limits but does not remove, so the score is a relative measure for comparing systems that face the same items.

The base model, measured on 100 held-out blocks of 512 tokens, scores a Swahili perplexity of 80.60 against 20.07 on English, and picks the real Swahili word on 29.0% of 500 items (chance is 25%) against 88.6% in English. It reads Swahili badly, so there is something to learn.

4. What does it cost, and LoRA or full?

Full fine-tuning trains every weight. With AdamW each trained weight needs its float32 value, a gradient and two moments, 16 bytes in all. LoRA freezes the base weights and trains two small matrices beside each linear layer, so the update is limited to rank rr:

W=W0+αr BAW = W_0 + \frac{\alpha}{r}\,BA

Here the adapter is rank 64 with α=128\alpha = 128 on every linear layer. That is a higher rank than lesson 4's, with α\alpha at twice the rank, following Biderman et al. (2024), who found that high ranks and α=2r\alpha = 2r matter for continued pretraining. The model has 494,032,768 parameters; the adapter has 35,192,832, or 7.1%. The embedding matrix, 136,134,656 weights, is 27.6% of the model and is tied: input embeddings and output layer are one matrix. That matters for a new language, because new spellings live in it, and it is the one matrix LoRA does not train here. Training it as well would add 16 bytes per embedding weight, about 2.2 GB.

n_all = sum(p.numel() for p in base.parameters())
n_emb = base.get_input_embeddings().weight.numel()
est = {"full (16 bytes per weight)":       16 * n_all / GB,
       "LoRA (4 per base + 16 per adapter)": (4 * n_all + 16 * n_lora) / GB,
       "LoRA + trained embedding matrix":   (4 * n_all + 16 * (n_lora + n_emb)) / GB}

All three runs use the same 3,000 blocks of 512 tokens, 1.54 million tokens, about 610,000 Swahili words at 2.5 tokens per word (derived). They run 187 optimizer steps of 16 blocks each in fp16 mixed precision with gradient checkpointing, and take a single pass. LoRA uses a learning rate of 2e-4 and full fine-tuning 2e-5, each chosen once and not tuned. That is a limit on any comparison between them, and the company papers show why it matters: eBay's learning-rate table at 1 trillion tokens gave a general-domain benchmark of 42.0 at 3.0e-5 and 34.5 at 3.0e-3, and ChipNeMo reports that a learning rate of 3e-4 reached a lower training loss but degraded its natural-language benchmarks.

All three runs took about nine minutes; full fine-tuning needed 12.8 GB, nearly twice LoRA's 7.3 GB, and LoRA trained 7% of the weights

Each run: 3,000 blocks of 512 tokens (1.54M tokens), 187 optimizer steps, 16 blocks per step, fp16 mixed precision, one T4

3
RunMinutesTokens/sPeak GPU memory, GBTrained weightsSaved (adapter, fp16)LoRA r=649.52,6817.3335.2M (7.1%)141 MBfull fine-tune9.22,76912.80494.0M (100%)988 MBfull + replay9.22,76912.80494.0M (100%)988 MBLoRA + embeddingsnot run4.72 (state, estimated)weights, gradients and AdamW moments (estimate: 2.54 and 7.90)the rest of the measured peak: 4.79 (LoRA) and 4.90 (full), derived
Source: lesson notebook sections 3 and 4, Colab T4. Minutes, tokens per second and peak GB are measured. Optimizer state is arithmetic: 16 bytes per trained weight in float32, 4 bytes per frozen weight; the embedding row is not run. The whole notebook took 32 minutes.

LoRA took 9.5 minutes and full fine-tuning 9.2, both at about 2,700 tokens per second: on this model the cost is not time. It is memory. Full fine-tuning peaked at 12.80 GB, LoRA at 7.33 GB. The optimizer-state arithmetic gives 7.90 GB and 2.54 GB, and the rest of each peak, 4.79 and 4.90 GB, is the same for both: activations and everything else the state estimate leaves out. On a 15 GB T4 both fit. The same arithmetic at 7.6 billion parameters, the size of lesson 9's teacher, gives about 120 GB of state for full fine-tuning (16 bytes times 7.6 billion, derived), which is why lesson 5 quantised.

Does LoRA give up quality for that saving? Biderman et al. report that on Python code, Llama-2-7B trained for 20 billion tokens reached HumanEval 0.263 with full fine-tuning and 0.224 with LoRA at rank 256, and that LoRA forgot less: 0.617 against 0.545 on the mean of three English benchmarks (the figure in section 6 sets this beside our result). NVIDIA's ChipNeMo, on a 13B model, found the same gap on its domain: a LoRA adapter of 211.2M weights reached 49.6 on the chip-design benchmark against 57.7 for full fine-tuning and 47.1 for no adaptation, and the authors write that both LoRA models underperform full training on in-domain tasks. Both studies ran at text volumes thousands of times ours; the next section shows what happens at 1.5 million tokens.

5. Did it learn the domain?

trainer, runs_info["LoRA r=64"] = train(lora_model, train_domain, "lora", LR_LORA)
trainer, runs_info["full fine-tune"] = train(full_model, train_domain, "full", LR_FULL)

Figure 1, at the top of the page, shows the result. Swahili perplexity fell from 80.60 to 15.43 with LoRA and 13.84 with full fine-tuning. In loss, that is 1.653 and 1.762 nats per token. Full fine-tuning is 0.109 nats better than LoRA on the same blocks. Perplexity here is one pass over one fixed set of held-out blocks from one run per system, so it carries no interval, and I cannot say whether that gap would survive another seed.

The three trained models roughly doubled the Swahili fill-in score and cannot be ranked against each other; English did not move

Share of 500 items where the model picks the real long word from four versions of a held-out sentence, with the 95% interval

4
a Swahili fill-in, %the domainb English fill-in, %the control (axis from 82)20304050607082869094chance 25%base model29.088.6LoRA r=6458.488.6full fine-tune56.888.8full + replay53.489.8
Source: lesson notebook sections 2 and 8, Colab T4. Interval 1.96·√(p(1−p)/500). Chance is 25%. Swahili items come from 300 held-out articles; English items from the 1,547 qualifying paragraphs of the WikiText test split. The English panel's axis starts at 82%, so chance is off it.

On the fill-in test, the base model scored 29.0% (±4.0), LoRA 58.4% (±4.3) and full fine-tuning 56.8% (±4.3). Both gains, about 28 to 29 points, are far outside the intervals. The 1.6 points between LoRA and full are well inside them, and so are the differences from the replay run's 53.4%: the interval on a difference between two of these is about ±6 points (derived from the two intervals). Perplexity ranks full fine-tuning ahead of LoRA; this test cannot confirm it.

The score is far from perfect, and the generated text does not look like a fluent Swahili writer's. The notebook continues the same three held-out article openings greedily for 40 tokens. Two of the three, each shown after its 35-word prompt:

Kambi ya Wachawi ya Gambaga ni jamii iliyotengwa ndani ya kitongoji cha Gambaga katika Mkoa wa Kaskazini wa Ghana iliyoanzishwa katika karne ya 18 ili kushughul...

Base
kwa 18 ili kushughulikia madai ya wachawi na wachawi ambao wamefukuzwa kutoka kwenye kwa 18
LoRA
kikosi cha kwanza cha kijamii cha kwanza cha kijamii cha kwanza cha kijamii cha kwanza cha kijamii cha
Full
mkoa wa Kaskazini. Kwa kawaida, kwa kawaida, kwa kawaida, kwa kawaida, kwa kawaida, k
Full + replay
kusini kwa kusini kwa kusini. Kwa kawaida, kwa kusini kwa kusini, kwa kusini kwa k

The article is about a witch camp in Ghana. Every system repeats a phrase; none continues the article.

Nyumba ya wageni (pia "gesti" kutoka Kiing. guest house) ni jengo penye nafasi za kukodi kwa kulala wageni. Ndani yake kuna sehemu ya mapokezi, vyumba vya kulal...

Base
"gesti" kutoka Kiing. Guest house is a guest house. It is a guest house. It is a guest house. It is a guest house. It is a guest house.
LoRA
na kufanya kazi kwa kufanya kazi kwa kufanya kazi kwa kufanya kazi kwa kufanya kazi kwa kufanya k
Full
kwenye kusini kwa kusini kwa kusini kwa kusini. Kuna sehemu ya kusini kwa kusini kwa k
Full + replay
kwa kawaida kwa kawaida kwa kawaida kwa kawaida kwa kawaida kwa kawaida kwa kawaida kwa kawaida

The base model slides into English; the trained models stay in Swahili words but loop.

All four loop, the base model included. The trained models stay in Swahili words, but the text repeats phrases and does not continue the article. I have not had these outputs read by a Swahili speaker, so I make no claim about grammar. The repetition is visible without one. Greedy decoding from a model this small, after about 190 steps, is the likely setting for it. The lesson is that a perplexity of 15 is not fluent text: perplexity is an average over every token of held-out prose, and a continuation is one path chosen greedily through it.

6. What did it forget?

Every run bought 1.65 to 1.76 nats of Swahili loss; plain full and LoRA each gave back about 0.1 nats of English, and only replay did not

a: change in mean next-token loss against the base model, nats per token. b: the same trade in a published study at 13,000 times this lab's token count

5
a This lab, 0.5B model, Swahiligeneral loss added (up = forgot more), nats per token−0.10+0.1+0.200.511.52Swahili loss gained, nats per token (right = learned more)base modelLoRA r=641.653, +0.126full fine-tune1.762, +0.109full + replay1.652, −0.097b Biderman et al. (2024), 7B, codefull fine-tuning against LoRA r=256, paper-reportedLearns the domainHumanEval, Python code (higher is better)0.263full fine-tuning0.224LoRA r=256Keeps general skillsmean of three English benchmarks (higher is better)0.545full fine-tuning0.617LoRA r=256Different tasks, models and scale from panel a: the direction of thetrade-off is shown for comparison, not as a like-for-like test.
Source: a, lesson notebook section 8, Colab T4; one run per system, no interval on perplexity. b, Biderman et al. (2024), Sec. 4.1 and 4.2, Llama-2-7B, 20B tokens of Python code, forgetting score = mean of HellaSwag, WinoGrande and ARC-Challenge; paper-reported. 20B ÷ 1.54M = about 13,000 (derived).

Panel a plots what each system gained against what it gave back. Both plain runs moved English perplexity up: 20.07 to 22.76 for LoRA and 22.37 for full fine-tuning, losses of 0.126 and 0.109 nats per token, 13% and 12% higher perplexity (derived). On the English fill-in test, nothing moved: 88.6% for the base and for LoRA, 88.8% for full (±2.8). That test sits near its ceiling, so it can only show a large drop. Perplexity is the sensitive meter, and it says the cost was real but modest.

The size of the loss and of the gain are close: LoRA learned slightly less (1.653 against 1.762) and forgot slightly more (0.126 against 0.109). Biderman's study found that LoRA learned less and forgot less. Here the first holds and the second does not, but with one run each and no interval on perplexity this lab cannot say that either difference is real. It does not contradict the paper; it is a different regime (0.5B, a language, 1.5 million tokens against 7B, code, 20 billion).

The same pattern shows up in the Japanese case. Swallow, with 10% of its mix in English, lost 5 points of English average at 7B (49.0 to 44.0), and the drop shrank with model size (13B: 54.0 to 49.2; 70B: 62.7 to 60.4). Per task at 7B, English TriviaQA fell from 62.7 to 48.4 while Japanese QA on NIILC rose from 34.1 to 59.7. Learning a language has a price in the old one, and the authors measured it.

7. Does replaying general text help?

Forgetting is the cost of moving the weights toward one distribution. Replay keeps showing the model some of the old one. If ρ\rho is the share of general blocks, the training loss is a mixture of the two:

L=(1−ρ) Ldomain+ρ LgeneralL = (1-\rho)\,L_{\text{domain}} + \rho\,L_{\text{general}}

Here ρ=0.25\rho = 0.25: 2,250 Swahili blocks and 750 English blocks, shuffled together, with the same steps and settings as the plain full run.

Replaying English took general loss below the base model; at eBay a larger domain share also raised general perplexity, with no change in its general benchmark

a: general (English) loss added against the base model, nats per token; b: eBay's 8B model after 30B tokens at four domain shares

6
a This lab: English loss addednats per token; left of zero = better than the base model−0.10+0.1LoRA r=64Swahili gained 1.653+0.126full fine-tuneSwahili gained 1.762+0.109full + replaySwahili gained 1.652−0.097Replay gave up 0.110 nats of Swahili against plain full(1.652 against 1.762), after seeing a quarter fewer Swahiliblocks, and gained 0.206 nats of English.b eBay, 30B tokens, by e-commerce shareeach row has its own scale; company-reportedE-commerce perplexityfalls2.752.592.472.40General perplexityrises6.876.927.007.15E-commerce benchmarkrises55.656.757.557.6General benchmarkflat43.243.143.343.210%25%50%75%share of e-commerce data in the mix
Source: a, lesson notebook section 8, Colab T4; the replay text and the English control are both Wikipedia, so this is the friendliest case. b, eBay (2025), Table 3, Llama 3.0 8B, 30B tokens; company-reported, e-commerce share of the training mix on the x axis.

The replay run's English loss was 0.097 nats below the base model's: perplexity 18.22 against 20.07, a better score than the model started with. Its Swahili perplexity was 15.45, which is 0.110 nats short of plain full (13.84) and about equal to LoRA's 15.43. The replay run saw a quarter fewer Swahili blocks, and it cost that much Swahili. Its Swahili fill-in, 53.4% (±4.4), is within noise of the other two trained systems.

The caveat is the control. The replay text and the English control are both Wikipedia, and both English sets went through the same formatting repair. Replay protects the kind of text it replays, and an English control built from the same source is the friendliest test it could face. It does not show that code, other languages or other registers would survive.

The company evidence is about the same mechanism at scale. eBay ran 30-billion-token trials at four shares of e-commerce data: 10%, 25%, 50% and 75%. As the share rose, e-commerce perplexity fell from 2.75 to 2.40 and general perplexity rose from 6.87 to 7.15, while the general benchmark stayed between 43.1 and 43.3 and the e-commerce benchmark rose from 55.6 to 57.6. The authors chose 50%. ChipNeMo mixed in public data (Wikipedia and GitHub, about 9.2% of its tokens) and its Table 10 shows the chip benchmark 56.9 without it and 57.8 with it, which the authors call a slight improvement. Both teams replay, and both measure the control.

8. Domain text or task text?

Gururangan et al. (2020) named the two options for RoBERTa-base. Domain-adaptive pretraining (DAPT) continues on a large unlabelled corpus from the domain. Task-adaptive pretraining (TAPT) continues on the task's own unlabelled text. Their results, in F1 on the test sets:

TaskRoBERTaDAPTTAPTDAPT then TAPT
ACL-ARC (computer science)63.075.467.475.6
CHEMPROT (biomedical)81.984.282.684.4
HYPERPARTISAN (news)86.688.290.490.0
IMDB (reviews)95.095.495.595.6

Domain text helped most where the domain was far from RoBERTa's original text (ACL-ARC). Their masked-language-model loss on held-out biomedical text fell from 1.32 to 0.99, but on news it rose slightly, from 1.08 to 1.16. And the wrong domain hurts: continuing on an irrelevant domain took HYPERPARTISAN from 86.6 to 76.4. This lab is a DAPT-shaped experiment with no downstream task, so it can show the loss falling and the fill-in score rising but cannot show a task improvement. The measurement that decides whether continued pretraining pays is a task score on your domain before and after, which lesson 11 covers.

9. What do companies run?

The companies trained on thousands to hundreds of thousands of times as many tokens as this lab's 1.5 million

Tokens in the continued-pretraining or training run, log scale; multiple is tokens divided by this lab's 1.536 million, rounded

7
RunMultiple of this lab1M10M100M1B10B100B1TThis labQwen2.5-0.5B, Swahili1.54M1Gururangan et al. 2020RoBERTa, biomedical papers, one pass7.55B4,900×ChipNeMo, NVIDIALlama 2, chip-design text and code24B16,000×Swallow, Tokyo TechLlama 2, Japanese, about 90% of the mixabout 100B65,000×RakutenAI-7BMistral-7B, Japanese and Englishabout 175B110,000×BloombergGPTtrained from scratch, not continued569B370,000×e-Llama, eBayLlama 3.1, e-commerce and general1T650,000×
Sources: lesson notebook (3,000 × 512 tokens); Gururangan et al. (2020) Table 1, corpus size; ChipNeMo paper (2023) Table 3, about 24B; Swallow paper (2024) Sec. 3.2, about 100B sampled; RakutenAI-7B report Sec. 2.2, about 175B filtered; BloombergGPT paper (2023), 569B trained; eBay (2025), 1T. All paper- or company-reported; multiples are derived.

eBay trained e-Llama on 1 trillion tokens on 480 H100 GPUs (60 nodes of 8) with a learning rate set to 10% of the original pretraining value, and reports that the 8B model's general English NLU score stayed at 71.6 against 71.8 for Llama 3.1. ChipNeMo's run was 24 billion tokens in about one epoch on 128 A100 GPUs. Swallow reports that its Japanese average rose steadily up to 100 billion tokens, with the largest gain in the first 20 billion. This lab is the same mechanism thousands to hundreds of thousands of times smaller: it shows the shape, the cost and the trade, not what a production run reaches.

What to keep

SystemSwahili perplexityEnglish perplexitySwahili fill-inEnglish fill-inMinutesPeak GB
Base80.6020.0729.0% (±4.0)88.6% (±2.8)n/an/a
LoRA r=6415.4322.7658.4% (±4.3)88.6% (±2.8)9.57.33
Full13.8422.3756.8% (±4.3)88.8% (±2.8)9.212.80
Full + replay15.4518.2253.4% (±4.4)89.8% (±2.7)9.212.80

If you have a task like this one:

  • Measure how badly the model reads your text before training. Tokens per long word and held-out perplexity say whether there is anything to gain; if the model already reads your text well, stop.
  • Start from the base model, not the chat model, and tune the task afterwards.
  • Hold a control and replay general text. Measure English (or whatever you must keep) before and after: here the control cost 0.1 nats without replay, and a 25% English share took English perplexity to 18.22, below the base model's 20.07. eBay and ChipNeMo report replaying too.
  • Read the text the model writes, not only perplexity: a Swahili perplexity of 15 still looped.
  • Choose LoRA when memory is the limit. It reached 15.43 against 13.84 for full fine-tuning at 7.33 GB against 12.80 GB, and the fill-in scores are within noise; time was the same.
  • Check one downstream task on your own data before calling it a success (lesson 11).

Next to try, not tested here: A second seed for each system, to see whether full fine-tuning's 0.109 nats of Swahili perplexity advantage over LoRA is real. Sampling or a repetition penalty instead of greedy decoding, to see whether the loops are the decoding or the model. Extending the vocabulary, since common long Swahili words are cut into four pieces (Rakuten and Swallow did this for Japanese), and training the embedding matrix, which LoRA left frozen and which would add about 2.2 GB of state. A larger text volume, on the first change under Run it yourself.

How it was built

ItemSetting
Base modelQwen/Qwen2.5-0.5B (494,032,768 parameters, tied embeddings), Apache 2.0
DataSwahili Wikipedia (wikimedia/wikipedia, 20231101.sw, pinned commit): 17,824 articles of at least 800 characters, shuffled with seed 42, the first 4,000 characters of each. 300 articles held out; 4,000 read for training, cut into 3,000 blocks of 512 tokens (1.54M tokens). Replay run: 2,250 Swahili and 750 English blocks, the English from WikiText-103 train (6,000 paragraphs of at least 60 words)
TestPerplexity on 100 held-out blocks of 512 tokens (51,200 tokens) for Swahili and for English (WikiText-103 test, 400 paragraphs); fill-in test of 500 items per language, 95% interval 1.96·√(p(1−p)/500)
MethodLoRA: rank 64, alpha 128, dropout 0, every linear layer (35,192,832 trainable, 7.1%), embedding matrix frozen. Full: all 494,032,768 weights. Replay: full, with a replay share of 0.25
TrainingOne epoch, 187 optimizer steps; micro-batch 4 blocks with 4 accumulation steps (16 blocks, 8,192 tokens per step); AdamW; learning rate 2e-4 (LoRA) and 2e-5 (full and replay), cosine with 3% warmup; weight decay 0; gradient clipping at 1.0; fp16 mixed precision with float32 weights; gradient checkpointing; loss on every token; seed 42
DecodingGreedy, 40 new tokens, from the first 35 words of three held-out Swahili articles
HardwareOne Colab T4 (Tesla T4); transformers 4.51.3, peft 0.15.2, accelerate 1.6.0, datasets 3.6.0

Time and cost. LoRA trained for 9.5 minutes at 2,681 tokens per second with a peak of 7.33 GB; full fine-tuning and the replay run each took 9.2 minutes at 2,769 tokens per second with a peak of 12.80 GB. Each evaluation (perplexity, both fill-in tests, three continuations) took 38 to 57 seconds. The LoRA adapter is 140.8 MB in float32; the full model is about 988 MB in float16. The whole notebook took 32 minutes. Perplexity and the fill-in test each use two sets: Swahili from the 300 held-out Swahili articles, English from WikiText-103 test, and the English fill-in items from all 1,547 qualifying paragraphs of that split rather than the 400 used for perplexity.

Run it yourself

The notebook runs on a free Colab T4 and took 32 minutes end to end: about 9.5, 9.2 and 9.2 minutes of training for the three runs, and under a minute for each of the four evaluations. Every size is a constant in the second code cell. Its sections map to the page: section 0 loads the data, section 1 is Does the model read it badly?, section 2 is the objective and its two measures, sections 3 and 4 are the cost, sections 5, 6 and 8 are what it learned and what it forgot, section 7 is replay and section 9 is the table under What to keep. Three changes to try:

  1. Double N_TRAIN_DOCS and N_TRAIN_BLOCKS together (the second cell asserts there are enough blocks). Does Swahili perplexity keep falling, and does the fill-in score leave the ±4.3 band around LoRA's 58.4%?
  2. Set REPLAY_FRAC = 0.5 and compare with eBay's four shares. How much Swahili does the English share cost, and how far below 20.07 does English perplexity go?
  3. Change LR_FULL to 2e-4, the LoRA value. Does English perplexity rise much further than 0.109 nats, as the eBay and ChipNeMo learning-rate tables suggest?

Lesson 11, Evaluate, turns to measuring whether any of this worked.

How is this page?

Last updated on