Paper · 2021-11-18 · cs.CL, cs.LG
DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing
Replaces DeBERTa's masked language modeling with ELECTRA-style replaced token detection and shares embeddings between generator and discriminator with stop-gradient on the generator side (GDES), avoiding the conflicting "tug-of-war" updates. DeBERTaV3-Large reaches 91.37 GLUE average (author-reported, dev set).
Replaced token detectionMasked language modelingLanguage model pretrainingRelative positional encodingpretrainingreplaced-token-detectionembedding-sharingnlutransformer
arXivPDFCodeMarkdown10 min read
AI-compiled by claude-haiku-5-5 on 2026-10-24, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Large language models learn by hiding words and guessing them back. This paper keeps that general setup but changes the guessing game. A small helper model fills the hidden slots with plausible but sometimes wrong words, and the main model has to point at each word and say whether it was original or swapped in. Every word gets a verdict, not just the hidden ones, so the main model learns from more of each text.
The helper and the main model normally share one table of word vectors. The paper finds that the two training goals pull those shared vectors in opposite directions, which slows learning. The fix is to let the main model read the shared table but never send its own learning signal back into it, so only the helper shapes those vectors. The authors report that the resulting model does better on language-understanding tests than comparable models.
TL;DR
- DeBERTaV3 is DeBERTa with its masked-token objective replaced by replaced token detection (RTD) from ELECTRA.
- Generator and discriminator share token embeddings, but the discriminator's copy receives no gradient into the generator's embeddings (gradient-disentangled embedding sharing, GDES).
- Author-reported: DeBERTaV3-Large averages 91.37 on the GLUE development set, and the multilingual mDeBERTaV3-Base reaches 79.8 zero-shot XNLI accuracy.
- Pre-training settings differ between Section 3 (small ablation runs) and Section 4 (full runs), and the paper's own text and tables disagree on several values. Check the Pitfalls section before reproducing.
- Code is MIT-licensed and the released RTD scripts use different hyperparameters from the paper.
Problem
Masked language modeling (MLM) trains only on the masked fraction of each input, which is about 15% of tokens §2.3.1. RTD trains the discriminator on every token, so it is more sample-efficient, but ELECTRA shares its token embeddings between generator and discriminator, and the paper argues that this sharing hurts the discriminator. The MLM loss wants semantically similar tokens close together, while the RTD loss wants them separable §3.2. The paper measures this with slower convergence and lower average cosine similarity in the discriminator's embeddings §3.2, tab. 1, fig. 2. Separate embeddings (no sharing) avoid the conflict but lose the benefit of sharing, so the discriminator fine-tunes worse §3.2, tab. 2.
Method
Overview. The model is DeBERTa's architecture (disentangled attention and relative positions) pre-trained with ELECTRA's generator and discriminator §3.1. The paper's contribution is the embedding-sharing rule, GDES §3.3.
- Backbone. Use DeBERTa's disentangled attention and enhanced mask decoder; the RTD objective replaces DeBERTa's MLM §2.2, §3.1.
- Generator. Same width as the discriminator, half its depth. It is trained with MLM on about 15% of input tokens replaced by
[MASK]§3.1, §6.4. - Replacement. Each masked position receives a token sampled from the generator's output distribution, not its argmax eq. 3.
- Discriminator. Predicts, for each position, whether the token is the original one. Trained with binary cross-entropy over all positions eq. 4.
- Joint objective. The generator's MLM loss and the discriminator's RTD loss are combined with weight λ; the paper uses λ = 50, as in ELECTRA §2.3.2, §3.1.
- GDES. The discriminator's token embedding is the generator's embedding with its gradient stopped, plus a separate residual matrix that is zero at initialisation and is the only part the discriminator trains §3.3:
E_D = \mathrm{sg}(E_G) + E_\Delta, \qquad E_\Delta \leftarrow 0 \text{ at init} \qquad [\S 3.3]
- Schedule. In each iteration, generate the discriminator inputs, update the generator and its embeddings with the MLM loss, then update the discriminator with the RTD loss, where gradients reach the shared embeddings only through
E_Δ§3.3.
Figure 1 shows the three gradient paths: ES (a), NES (b) and GDES (c) fig. 1. In the paper's words, GDES lets the generator's embedding be learned from MLM only, and the discriminator's embedding builds on it §3.3.
# One GDES iteration [§3.3] [eq. 2] [eq. 3] [eq. 4]
# Input: masked batch, original ids, generator G, discriminator D
# E_G (generator embedding), E_delta (zero-initialised residual)
# Output: updated G, D, E_delta
def gdes_iteration(batch, rtd_lambda):
# 1. Generator forward pass and MLM loss [§3.1] [eq. 2]
gen_logits = G(batch.masked_ids) # (B, L, V)
mlm_loss = masked_cross_entropy(gen_logits, batch.original_ids)
# 2. Update generator and E_G from MLM only [§3.3]
update(G, mlm_loss)
# 3. Sample a replacement for each masked position [eq. 3]
sampled = sample_from_softmax(gen_logits[batch.mask])
corrupted = replace_at(batch.original_ids, batch.mask, sampled)
# 4. Build the discriminator embedding with stopped gradient [§3.3]
E_D = stop_gradient(E_G) + E_delta # (V, d)
# 5. Per-token RTD loss, weight lambda = 50 in the paper [eq. 4]
labels = corrupted != batch.original_ids # True = replaced
rtd_loss = binary_cross_entropy(D(corrupted, E_D), labels)
update(D, rtd_lambda * rtd_loss) # E_D grads -> E_delta
returnNotes on the sketch: the code writes labels as "replaced" only where the
sampled token differs from the original, which matches the indicator in
equation 4 replaced_token_detection_model.py.
The decoupled schedule that the released code actually runs is described under
Paper vs code.
Hyperparameters
Values for the full pre-training runs in Section 4 are in tab. 10. Where the text disagrees with the table, both are listed in Pitfalls.
| Name | Value | Where | Notes |
|---|---|---|---|
| Layers (discriminator / generator), large | 24 / 12 | tab. 10 §4 | generator half depth §3.1 |
| Layers, base | 12 / 6 | tab. 10 | |
| Layers, small | 6 / 3 | tab. 10 §4 | |
| Layers, xsmall | 12 / 6 | tab. 5 rtd_xsmall.json | xsmall is 384 wide, 6 heads tab. 5 |
| Hidden size, large / base / small | 1024 / 768 / 768 | tab. 10 | |
| FFN inner size | 4096 / 3072 / 3072 | tab. 10 | |
| Attention heads, large | 12 in table, 16 in code | tab. 10 vs rtd_large.json | see Pitfalls |
| Attention head size | 64 | tab. 10 | |
| Vocabulary | 128,000 SentencePiece tokens | §4 | code config uses 128100 rtd_base.json |
| Pre-training steps (full runs) | 500,000 | §4 tab. 10 | |
| Pre-training steps (Section 3 ablations) | 125,000 | §3.1 tab. 10, base-analysis | |
| Batch size (full runs) | 8,192 | §4 tab. 10 | |
| Batch size (Section 3 ablations) | 2,048 | §3.1 tab. 10, base-analysis | |
| Learning rate, large | 3e-4 | §4 tab. 10 | |
| Learning rate, base | 5e-4 in text, 6e-4 in table | §4 vs tab. 10 | see Pitfalls |
| Learning rate, small | 5e-4 in text, 6e-4 in table | §4 vs tab. 10 | see Pitfalls |
| Learning rate, mDeBERTa-base | 6e-4 | tab. 10 | |
| Learning rate, Section 3 ablations | 5e-4 | §3.1 tab. 10, base-analysis | |
| Warmup steps | 10,000 | §3.1 §4 tab. 10 | |
| LR schedule | linear decay | tab. 10 | |
| Optimizer | Adam with decoupled weight decay | §6.4 §4 | text says AdamW in §4 |
| Adam β1, β2, ε | 0.9, 0.98, 1e-6 (full runs); β2 = 0.999 in the Section 3 column | §4 tab. 10 | see Pitfalls |
| Weight decay | 0.01 | tab. 10 | |
| Gradient clipping | 1.0 | tab. 10 | |
| Dropout | 0.1 | tab. 10 | |
| RTD weight λ | 50 | §2.3.2 §3.1 | the released code defaults to 10 |
| Pre-training data, full runs | 160 GB, same mix as RoBERTa and DeBERTa-1.5B | §4 §6.2 | |
| Pre-training data, Section 3 ablations | Wikipedia and BookCorpus | §3.1 | |
| mDeBERTa data | CC100, 2.5T in §4.2, 2.5TB in §6.2 | §4.2 §6.2 | |
| Fine-tuning optimizer | Adam, β1 0.9, β2 0.999, ε 1e-6, weight decay 0.01 | tab. 11 §6.4 | |
| Fine-tuning grid | epochs 10; LR and batch size grid per model; warmup {50, 100, 500, 1000} | tab. 11 | selected on dev set |
| Fine-tuning dropout of task layer | large {0, 0.15, 0.3}; others {0, 0.1, 0.15} | tab. 11 | |
| Fine-tuning batch sizes | large {16, 32, 64}; others {16, 32, 48, 64} | tab. 11 | |
| Fine-tuning LRs, large | {5e-6, 8e-6, 9e-6, 1e-5} | tab. 11 | |
| Fine-tuning LRs, base and mDeBERTa | {1.5e-5, 2e-5, 2.5e-5, 3e-5} | tab. 11 | |
| Fine-tuning LRs, small | {1.5e-5, 2e-5, 3e-5, 4e-5} | tab. 11 | |
| Fine-tuning cost | 1 to 2 hours per run on a DGX-2 node | §6.4 |
Results
Author-reported. Setup: GLUE development sets, one classification head on
[CLS] §4.1.1; large models use DeBERTaV3 with 24 layers and hidden size
1024, compared with BERT, RoBERTa, XLNet, ELECTRA and DeBERTa of similar
structure §4.1.1. Numbers are on dev sets, with per-task hyperparameter
search selected on the same dev set §6.4.
GLUE, large models tab. 3
| Task (metric) | BERT-large | RoBERTa-large | XLNet-large | ELECTRA-large | DeBERTa-large | DeBERTaV3-large |
|---|---|---|---|---|---|---|
| CoLA (Matthews corr.) | 60.6 | 68.0 | 69.0 | 69.1 | 70.5 | 75.3 |
| QQP (acc.) | 91.3 | 92.2 | 92.3 | 92.4 | 92.3 | 93.0 |
| MNLI-m/mm (acc.) | 86.6/- | 90.2/90.2 | 90.8/90.8 | 90.9/- | 91.1/91.1 | 91.8/91.9 |
| SST-2 (acc.) | 93.2 | 96.4 | 97.0 | 96.9 | 96.8 | 96.9 |
| STS-B (corr.) | 90.0 | 92.4 | 92.5 | 92.6 | 92.8 | 93.0 |
| QNLI (acc.) | 92.3 | 93.9 | 94.9 | 95.0 | 95.3 | 96.0 |
| RTE (acc.) | 70.4 | 86.6 | 85.9 | 88.0 | 88.3 | 92.7 |
| MRPC (acc.) | 88.0 | 90.9 | 90.8 | 90.8 | 91.9 | 92.2 |
| Average | 84.05 | 88.82 | 89.15 | 89.46 | 90.00 | 91.37 |
Other tasks, large models tab. 4
| Model | MNLI-m/mm Acc | SQuAD v2.0 F1/EM | RACE Acc | ReCoRD F1/EM | SWAG Acc | CoNLL-03 NER F1 |
|---|---|---|---|---|---|---|
| RoBERTa-large | 90.2/90.2 | 89.4/86.5 | 83.2 | 90.6/90.0 | 89.9 | 93.4 |
| DeBERTa-large | 91.1/91.1 | 90.7/88.0 | 86.8 | 91.4/91.0 | 90.8 | 93.8 |
| DeBERTa-1.5B | 91.7/91.9 | 92.2/89.7 | 90.8 | 94.5/94.0 | 92.3 | not stated |
| DeBERTaV3-large | 91.8/91.9 | 91.5/89.0 | 89.2 | 92.3/91.8 | 93.4 | 93.9 |
The paper's Table 4 also lists ALBERT-xxlarge and Megatron variants. Only the rows above are reproduced here; the paper says DeBERTaV3-Large outperforms ALBERT-xxlarge and Megatron-1.3B on these tasks §4.1.1.
Base and smaller models tab. 5
| Model | Vocab (K) | Backbone params (M) | MNLI-m/mm Acc | SQuAD v2.0 F1/EM |
|---|---|---|---|---|
| BERT-base | 30 | 86 | 84.3/84.7 | 76.3/73.7 |
| RoBERTa-base | 50 | 86 | 87.6/- | 83.7/80.5 |
| XLNet-base | 32 | 92 | 86.8/- | -/80.2 |
| ELECTRA-base | 30 | 86 | 88.8/- | -/80.5 |
| DeBERTa-base | 50 | 100 | 88.8/88.5 | 86.2/83.1 |
| DeBERTaV3-base | 128 | 86 | 90.6/90.7 | 88.4/85.4 |
| TinyBERT-small (distilled) | 30 | 44 | 84.5/- | 77.7/- |
| MiniLMv2-small (distilled) | 30 | 44 | 87.0/- | 81.6/not stated |
| BERT-small | 30 | 44 | 81.8/- | 73.2/- |
| DeBERTaV3-small | 128 | 44 | 88.2/87.9 | 82.9/80.4 |
| MiniLMv2-xsmall (distilled) | 30 | 22 | 86.9/- | 82.3/not stated |
| DeBERTaV3-xsmall | 128 | 22 | 88.1/88.3 | 84.8/82.0 |
Embedding-sharing ablation, 125k-step setting tab. 1, tab. 2
| Setting | Cosine sim. G | Cosine sim. D | MNLI-m/mm | SQuAD v2.0 F1/EM |
|---|---|---|---|---|
| ES (vanilla sharing) | 0.02 | 0.02 | 88.8/88.4 | 86.3/83.5 |
| NES (no sharing) | 0.45 | 0.02 | 88.3/87.9 | 85.3/82.7 |
| GDES | 0.45 | 0.29 | 89.3/89.0 | 87.2/84.5 |
Cosine similarity is averaged over a 10% sample of word pieces [tab. 1, footnote in §3.2]. The DeBERTa-base baseline in this setting is 86.3/86.2 on MNLI and 82.5/79.3 on SQuAD v2.0 tab. 2.
Multilingual XNLI averages tab. 6
| Model | Cross-lingual transfer | Translate-train-all |
|---|---|---|
| XLM | 70.7 | 76.9 |
| mT5-base | 75.4 | 75.9 |
| XLM-R-base | 76.2 | 79.1 |
| mDeBERTaV3-base | 79.8 | 82.2 |
GDES on ELECTRA-base, reimplemented tab. 9, §6.3
| Setting | MNLI-m/mm | SQuAD v2.0 F1/EM |
|---|---|---|
| ES (reimplemented) | 87.9/87.4 | 85.0/82.3 |
| NES | 86.3/85.6 | 81.7/78.9 |
| GDES | 88.3/87.8 | 85.9/83.1 |
Paper vs code
Code is the microsoft/DeBERTa repository at commit 4d7fe0bd4fb3c7d4f4005a7cafabde9800372098, MIT licensed. The RTD implementation lives in DeBERTa/apps/tasks/rtd_task.py.
- Lambda. Paper: λ = 50 §2.3.2 §3.1. Code default:
--rtd_lambdadefaults to 10 rtd_task.py, and the RTD scripts do not pass it rtd.sh. Set it explicitly to match the paper. - Scripts versus paper settings. Paper full runs use batch 8,192 and 500,000 steps with learning rate 3e-4 (large) or 5e-4/6e-4 (base and small) §4 tab. 10. The released
rtd.shtargets the released DeBERTaV3 checkpoints with batch 256, learning rate 1e-4 for base and large, and--num_training_steps 1000000rtd.sh. These are different runs; the script is not a replay of Section 4. - Embedding sharing scope. Paper: GDES applies to token embeddings §3.3. Code also applies the same stop-gradient construction to the position embeddings rtd_task.py.
- GDES formula. Matches: the discriminator weight is the generator weight detached plus a trainable residual, computed in a forward pre-hook rtd_task.py.
- Decoupled schedule. The released default runs the generator and discriminator as two trainers. The discriminator takes one update per generator update on the same batch, after the generator step rtd_task.py. The paper describes the same alternation §3.3, but not a separate optimizer.
- Discriminator learning rate. The code can override the discriminator learning rate with
--discriminator_learning_rate(default -1, meaning the same rate) rtd_task.py. The paper states no separate rate. - Sampling. The code calls its sampler
topk_samplingwithtopk=1. That is sampling from the full softmax at temperature 1, not argmax rtd_task.py, which matches equation 3. The name is misleading. - Masking. Masked positions are replaced with
[MASK]only:keep_prob=0andmask_prob=1rtd_task.py. The default masking budget isround(0.15 × length), capped bymax_preds_per_seqmlm_task.py. - Discriminator head. The code adds the
[CLS]hidden state to every token before the dense and LayerNorm head replaced_token_detection_model.py. The paper does not describe this step. - Architectures. Generator depth is half the discriminator depth in the configs, as the paper says rtd_base.json. Large uses 16 attention heads rtd_large.json, which disagrees with the table (see Pitfalls).
Pitfalls
- λ is not stated consistently. Paper uses 50 §2.3.2, §3.1. Code defaults to 10 and the released scripts do not override it rtd_task.py.
- Learning rate for base and small. Text says 5e-4 §4; the hyperparameter table says 6e-4 tab. 10. Pick one and record the choice.
- Large attention heads. The table gives 12 heads with head size 64 and hidden size 1024 tab. 10, which does not add up (1024 / 64 = 16). The code uses 16 heads rtd_large.json.
- Optimizer name and β2. Section 4 calls the optimizer AdamW with β2 = 0.98 §4; Section 6.4 calls it Adam with weight decay §6.4. The full-run column of Table 10 gives β2 = 0.98, and the Section 3 column gives 0.999 tab. 10.
- Two pre-training regimes. Section 3 ablations use Wikipedia and BookCorpus, batch 2,048, 125k steps §3.1. Section 4 uses 160 GB, batch 8,192, 500k steps §4. Table 2 numbers come from the smaller regime and are not comparable with Tables 3 to 6.
- Data size for mDeBERTa. The text says 2.5T §4.2; the appendix says 2.5TB §6.2.
- Vocabulary size. Paper: 128,000 tokens §4. Config: 128100 rtd_base.json. The released scripts use a SentencePiece model downloaded from Hugging Face rtd.sh.
- Model selection on dev. GLUE and SQuAD numbers are dev-set results, and the fine-tuning grid is selected on the same dev sets tab. 11 §6.4. Treat the margins as optimistic relative to a held-out test.
- Hidden cost. GDES adds a vocabulary-sized residual matrix
E_Δon the discriminator side rtd_task.py. The paper says the per-step computation is the same as ES and NES §3.3; it does not give the memory cost. - Stored discriminator embedding. The code recomputes the discriminator embedding each forward pass and registers it as a buffer rtd_task.py. So a saved discriminator state holds the summed embedding, not the residual alone. This is an inference from the code; I did not run a checkpoint save.
- Figure reading. Figure 2 (the generator's MLM loss under the three sharing methods) is described only in prose. The paper's claim that NES converges faster than ES, and that GDES matches NES, comes from that figure §3.2, §3.3, fig. 2.
Lineage
- Builds on: DeBERTa (He et al., 2020) for disentangled attention and the enhanced mask decoder §2.2; ELECTRA (Clark et al., 2020) for replaced token detection and the embedding-sharing baseline §2.3.
- Compared against: BERT, RoBERTa, XLNet, ALBERT, Megatron, T5 (as context only, since its test results are not comparable) §4.1.1, footnote on T5; XLM, mT5 and XLM-R for multilingual models §4.2; TinyBERT and MiniLMv2 for smaller models tab. 5.
Source and license
Adapted from “DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing” by Pengcheng He, Jianfeng Gao, Weizhu Chen (arXiv:2111.09543), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/microsoft/DeBERTa at commit 4d7fe0bd4fb3 (MIT). Any quoted code is shown under that license.