All models

MiniLM (L12-H384-uncased)

A 12-layer, 384-wide BERT-style encoder distilled by mimicking its teacher's last-layer self-attention.

Language · 302 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (26 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
33.4M
Operations
302
Framework
PyTorch
Recurrent
No
Published
NeurIPS 2020
Cited by
703 (as of 18 October 2026)
Authors
Wenhui Wang, Furu Wei, Li Dong and others
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m13761
Graph hash
2a44819f7901329b9e226ffba40697ca1c43cc66e6315e4043a09198798416e1
Skeleton hash
6e2351ffa82f55b6b05932459b5f9d5ee28a2b29a846468ef19a6c8ea1ad8329
Architecture hash
7ccf4b02485d596d13101c91f09b6bbe8d31114891e72136da58205857cf4806
Diagram SHA-256
674c054d5393abb95e3497250f2bd7b978c7aba1e3e4069cbff581a689b790b7
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

How this diagram was made

transformers.AutoModel.from_config()

What it is

MiniLM is a distilled model: a compact Transformer encoder trained to mimic a large pre-trained language model. The checkpoint traced here is the uncased 12-layer model with a 384-dimensional hidden size, distilled from an in-house pre-trained UniLM v2 model in BERT-Base size. The card is blunt about how to use it: the checkpoint can be an in-place substitution for BERT, and it needs to be fine-tuned before use.

The paper's problem is practical: pre-trained models such as BERT usually consist of hundreds of millions of parameters, which brings challenges for fine-tuning and online serving due to latency and capacity constraints. Its answer is deep self-attention distillation, in which the small student is trained by deeply mimicking the self-attention module of the large teacher. Rather than matching the teacher layer by layer, the student mimics only the attention of the teacher's last Transformer layer, which leaves the student free to have a different number of layers. Alongside the usual attention distributions, the student also matches the scaled dot-product between values, which the paper calls the value relation. Because the scaled dot-product turns vectors of any hidden width into relation matrices of the same size, the student can use a more flexible hidden dimension without extra parameters to transform its representations.

For students much smaller than the teacher, the authors add a teacher assistant, an intermediate-size student model that is distilled first and then teaches the final student. In the in-house setup behind this checkpoint, the 12x384 model is used as the teacher assistant to train the 6x384 model. On the dev sets the card reports, MiniLM-L12xH384 reaches 81.7 on SQuAD 2.0 and 85.7 on MNLI-m with 33M parameters. The paper's own verdict on the 12x384 model is that it achieves a 2.7x speedup while performing competitively better than BERT-Base on SQuAD 2.0 and GLUE. What the graph shows is the student itself: MiniLMv1-L12-H384-uncased, a 12-layer, 384-hidden, 12-head encoder with 33M parameters that runs 2.7x faster than BERT-Base.

Key idea. Deep self-attention distillation: the student is trained by mimicking only the self-attention module of the teacher's last Transformer layer, which is effective and flexible for the student. In addition to attention distributions, it transfers the scaled dot-product between values as a new kind of self-attention knowledge.

  • MiniLM
  • MiniLMv1-L12-H384-uncased
  • MiniLM-L12-H384
  • MiniLM-L12xH384
  • deep self-attention distillation
  • knowledge distillation
  • BERT
  • compressed transformer
  • small pre-trained language model
  • text encoder
  • Microsoft
  • UniLM

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{wang2020minilmdeepselfattentiondistillation,
      title={MiniLM: Deep Self-Attention Distillation for Task-Agnostic Compression of Pre-Trained Transformers}, 
      author={Wenhui Wang and Furu Wei and Li Dong and Hangbo Bao and Nan Yang and Ming Zhou},
      year={2020},
      eprint={2002.10957},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2002.10957}, 
}