The usual recipe for specializing a language model to a niche field runs in stages. First comes continued pretraining, meaning the model keeps doing plain next-word or masked-word prediction on a large unlabeled corpus from the target field. Then comes supervised fine-tuning on labeled task examples. Sometimes a reinforcement-learning stage follows. The recipe works, and the evidence is strong: domain-then-task pretraining beats the base model across four domains in Don't Stop Pretraining, and a three-stage curriculum takes a 27B model to 87.3% on C-to-Rust translation in Fine-Tuning Qwen3-27B for C-to-Rust. The recipe also has costs. Each stage is a separate training run with its own data pass, checkpoints and hyperparameter grid. The early stage never sees the downstream loss. Later stages erode what earlier stages built: the Rust model's general coding score on SWE-bench Verified fell from 72.4% to 70.6%, and English clinical pretraining damaged Chinese medical reasoning in AnesSuite.
This note asks a sharp question. Is a stage boundary a real structural need, or is it just a crude, step-shaped schedule over how much each loss counts? If it is only a schedule, one training run can replace the pipeline. That run trains on domain text, task data and a little general replay data at the same time. A controller sets the mix at every step from two signals that come almost for free during training. The first is whether the domain loss and the task loss currently push the weights in compatible directions. The second is whether previously correct general-domain examples are starting to fail. The proposal stands or falls on one comparison: the learned schedule must beat the best hand-tuned smooth schedule at equal tuning budget, not only the step-shaped staged pipeline.
Core Claim
We claim three things. A single run with an agreement-driven mixture schedule can match staged domain-then-task adaptation on target accuracy. It can retain more general capability. It can use substantially less total compute, counting tuning sweeps. We also claim the learned schedule will be interpretable. It should start domain-heavy and hand weight to the task loss once the two gradients stop agreeing, which would rediscover the "domain first" ordering without hard-coding it.
The mechanism comes from Rethinking and Improving Multi-task Learning for End-to-end Speech Translation. That paper collapsed a two-stage speech translation pipeline into one run by tracking gradient cosine similarity between auxiliary and main tasks and phasing auxiliaries out as they began to interfere. It reached the prior best result in 20.8% of the training time, cutting English-to-German from over 96 to 12 GPU-days. That work covers auxiliary supervised tasks across modalities. It does not cover an unsupervised domain language-modeling loss paired with a supervised task loss, and it has no forgetting signal. This proposal moves the idea to that setting and adds the second signal.
The forgetting signal comes from An Efficient Rehearsal Scheme for Catastrophic Forgetting Mitigation during Multi-stage Fine-tuning. Its method, mix-cd, flags "collateral damage", meaning examples the original model got right that the updated model now gets wrong. It detects these using forward passes the training step already performs. mix-cd keeps the staged schedule fixed and only chooses what to replay. We use the same in-batch signal to set how much to replay and when to move toward the task.
Research Program
We train with a time-varying mixture
$$L(t) = w_{\text{dom}}(t)\,L_{\text{dom}} + w_{\text{task}}(t)\,L_{\text{task}} + w_{\text{rep}}(t)\,L_{\text{rep}},$$
The three terms are as follows. $L_{\text{dom}}$ is the language-modeling loss on unlabeled target-domain text. $L_{\text{task}}$ is the supervised or instruction loss. $L_{\text{rep}}$ is the original training loss on a small buffer of general-domain data. The weights $w(t)$ are nonnegative, sum to one, and decide what fraction of each batch comes from each source.
The domain weight follows a smoothed estimate of the cosine between the domain-loss gradient and the task-loss gradient. Domain text keeps its share while it still helps the task direction and loses share when the cosine turns negative. The replay weight rises with the collateral-damage rate measured on replay examples inside the batch.
Gradient cosines are not free. They need separate backward passes per loss. We will compute them on a fixed parameter subset, either the top layers or a low-rank adapter, every $N$ steps, and we will count this cost in every compute comparison. A staged pipeline is recovered as the special case where $w$ is a step function. Flat data mixing is the special case where $w$ is constant. So one implementation spans the whole design space.
Two analyses accompany the method. The first is a direct test of the claim in Neural Machine Translation Training in a Multi-Domain Scenario that ordering by domain similarity matters. We will check whether the learned schedules recover that ordering when several domain corpora of varying distance are offered at once. The second addresses an open tension. Domain Generalization via Gradient Surgery zeroes gradient components on which domains disagree. Enhancing Domain Adaptation through Prompt Gradient Alignment instead actively pushes source and target gradients toward alignment. We will add each as a per-step variant on top of the schedule. That tells us whether reweighting alone is enough or whether component-level editing of conflicting directions adds anything once losses run together.
Baselines
The naive reference is the base model fine-tuned directly on task data. It tells us how much any domain exposure matters at all.
The strongest existing method in the small-scale setting is domain-adaptive pretraining followed by task-adaptive pretraining and then fine-tuning, as in Don't Stop Pretraining. That paper reports this combination is typically the best configuration. The file gives no per-task F1 numbers, so we will reproduce the staged pipeline ourselves with its published corpora and budgets rather than quote a figure.
At 7B scale, the strongest staged pipeline is MoZi from MoZIP. It applies patent pretraining, then general instruction tuning, then IP-specific tuning to BLOOMZ-7B, and reports 39.4% on IPQuiz and 27.4% on PatentMatch against a 25% chance rate.
A second staged baseline adds mix-cd rehearsal to the staged pipeline. This is the strongest anti-forgetting variant that keeps stages. Its paper reports Pareto improvements over random replay and Maximal Interfered Retrieval but no scalar figure, so we will rerun it.
The fourth baseline is flat mixing with a tuned constant ratio, which is the "no stages" competitor.
The baseline that isolates our key ingredient is a hand-designed smooth schedule. It is a linear or cosine anneal from domain-heavy to task-heavy with a constant replay fraction, and its endpoints and anneal length are grid-searched.
Fairness rules apply to all of these. Every method sees identical data pools and an identical total token budget. Each gets the same number of tuning trials, and the staged pipeline's per-stage grids count against its trial budget. Total GPU-hours include our gradient-cosine overhead.
Beating a baseline means the following. We must match or exceed target-task accuracy within seed noise. We must also do one of two further things: dominate on the target-accuracy-versus-general-retention curve, or reach the same point with clearly fewer GPU-hours, at least 2x end to end including tuning.
Why not just…?
Why not just pool everything into one flat mixture? The file's evidence against flat mixing is real but dated. QCRI's Machine Translation Systems for IWSLT'16 found sequential out-of-domain-to-in-domain training beat a combined mixture. Plain pooled training also trailed gradient surgery on PACS (63.89% versus 65.80%) in Domain Generalization via Gradient Surgery. Neither result tuned the mixture ratio carefully for large pretrained language models, so we treat a tuned constant mixture as a serious baseline. If it matches the learned schedule, that is a finding: the time variation does not matter.
Why not just use a fixed annealed schedule? This is the biggest threat, and the proposal is built around it. If a well-tuned linear anneal matches the gradient-agreement controller, the honest conclusion is that staging is merely a schedule. Practitioners should then replace pipelines with a single annealed run, and the controller is unnecessary. We would report exactly that. The controller earns its place only if it holds up across domains with one setting, while the anneal's best endpoints shift from domain to domain. That would show adaptive control removes the per-domain tuning that is the real cost.
Why not just keep stages and add smarter replay? Staged training with mix-cd attacks forgetting directly and costs little. It does not address the two other costs: separate runs with separate grids, and an early stage that is blind to the task. If staged-plus-mix-cd matches us on retention and target accuracy at similar total GPU-hours, the single-run claim fails. The equal-budget comparison above settles it.
Why not just skip domain pretraining and use only the much cheaper task-adaptive stage? Don't Stop Pretraining reports task-adaptive pretraining is often about 60x cheaper and competitive, but says the combination typically wins. It also reports the domain stage helps most when the domain is far from the original training data. We include task-only adaptation as a baseline and expect it to close the gap on near domains such as news and reviews. Our claim is restricted to far domains such as biomedicine and computer science papers.
Proposed Experiments
The first tier uses RoBERTa on the four-domain suite from Don't Stop Pretraining, including ChemProt, RCT-20k, ACL-ARC and SciERC. It runs five seeds per configuration. General retention is measured by keeping MNLI and SQuADv2 as replay sources and following the mix-cd transitions MNLI to Scitail and SQuADv2 to BioASQ. Its outputs are target macro-F1 or accuracy, source-task retention, and wall-clock GPU-hours including tuning.
The second tier reproduces the MoZi setting at 7B on the MoZIP benchmarks IPQuiz, IPQA and PatentMatch. The aim is to beat the reported 39.4% IPQuiz while preserving general instruction following. PatentMatch is a hard check, because the staged model sits near chance there.
A stretch tier applies the method to the C2Rust benchmark. The reported staged baseline there is 87.3% success with SWE-bench Verified retention of 70.6% from a 72.4% base. The success criterion is matching 87.3% while recovering some of the 1.8-point retention loss. Given cost, this tier runs only if the first two succeed.
Three checks decide the outcome. The first is the controller-versus-tuned-anneal comparison at equal tuning budget across all four first-tier domains. A win in at least three domains with a single controller setting supports the claim. A tie means we publish the simpler anneal as the recommendation. The second is whether learned schedules, given several corpora of varying distance from the target, front-load the farther ones, as Neural Machine Translation Training in a Multi-Domain Scenario would predict. The third is whether sign-agreement masking or explicit gradient alignment improves on reweighting alone. That speaks to the contradiction between the two gradient papers in a setting where losses, not domains, conflict.
References
- Don't Stop Pretraining: Adapt Language Models to Domains and Tasks
- Fine-Tuning Qwen3-27B for C-to-Rust Code Translation: A Three-Stage Curriculum of Pretraining, Debugging-Aware SFT, and Task-Specific SFT
- AnesSuite: A Comprehensive Benchmark and Dataset Suite for Anesthesiology Reasoning in LLMs
- Rethinking and Improving Multi-task Learning for End-to-end Speech Translation
- An Efficient Rehearsal Scheme for Catastrophic Forgetting Mitigation during Multi-stage Fine-tuning
- Neural Machine Translation Training in a Multi-Domain Scenario
- Domain Generalization via Gradient Surgery
- Enhancing Domain Adaptation through Prompt Gradient Alignment
- MoZIP: A Multilingual Benchmark to Evaluate Large Language Models in Intellectual Property
- QCRI's Machine Translation Systems for IWSLT'16