Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

Differential Transformer

The Differential Transformer subtracts one softmax attention map from another to cancel attention noise, improving long-context retrieval and quantization.

The Differential Transformer, or DIFF Transformer, is a transformer architecture whose attention heads compute two softmax attention maps and subtract one from the other, canceling the weight that both maps spread over irrelevant context. Tianzhu Ye, Li Dong, Furu Wei, and colleagues at Microsoft Research and Tsinghua University introduced it in October 2024 in Differential Transformer, an oral paper at ICLR 2025. The design borrows from differential amplifiers and noise-canceling headphones, which subtract two signals so that the noise they share drops out. In language modeling, a DIFF Transformer needed about 65% of the parameters or training tokens of a standard transformer to reach the same loss: a 6.8-billion-parameter model matched an 11-billion-parameter transformer.

How Differential Attention Works#

Standard self-attention gives every token a nonnegative weight, so some weight always lands on tokens that do not matter, which the authors call attention noise. Differential attention splits each head's query and key projections into two halves, computes a softmax map from each pair, and combines the values as (map1 − λ × map2) × V. Both maps assign weight to the same irrelevant tokens, so the subtraction cancels it while weight that only map1 assigns survives. Because each map sums to 1, every row of the result sums to 1 − λ, and individual weights can be negative:

import torch

torch.manual_seed(0)
n, d, lam = 6, 8, 0.8  # 6 tokens, head size 8, lambda near the paper's 0.8 initialization
q1, k1, q2, k2 = torch.randn(4, n, d)
v = torch.randn(n, 2 * d)  # values are twice as wide as each query-key pair

# Two ordinary softmax attention maps from separate query and key projections
map1 = torch.softmax(q1 @ k1.T / d**0.5, dim=-1)
map2 = torch.softmax(q2 @ k2.T / d**0.5, dim=-1)

# Subtracting cancels weight that both maps place on the same tokens
diff = map1 - lam * map2
out = diff @ v
print(f"Each row sums to {diff.sum(dim=-1)[0]:.2f}; {(diff < 0).sum().item()} of {n * n} weights are negative")

It prints Each row sums to 0.20; 13 of 36 weights are negative, two properties no softmax attention map can have. In the real model, λ is learned through four small vectors and starts at 0.8 − 0.6 × exp(−0.3 × (l − 1)) for layer l, so deeper layers start closer to 0.8. Each head's output is normalized on its own, which the paper writes as GroupNorm, then scaled by (1 − λ at initialization) to keep gradients the same size as in a standard transformer. The model uses half as many heads, each with values twice as wide, so its parameter count matches the baseline. Each map is ordinary softmax attention, so implementations reuse flash attention kernels, and training throughput on H100 GPUs was 6% to 12% lower than for a transformer of the same size.

Reported Benefits#

In a needle-in-a-haystack test with 6 needles and 2 questions in a 4K-token context window, the DIFF Transformer scored 0.85 against 0.55 for a standard transformer, and the paper's attention analysis traced this to focus: it put 0.27 to 0.40 of its attention on the answer, against 0.03 to 0.09 for the transformer. It also produced fewer hallucinations in text summarization and question answering, and in few-shot in-context learning it was more accurate and less sensitive to the order of the examples.

Activation outliers shrank as well. Its largest attention logit was 38.8, against 318.0 for a standard transformer, and its largest hidden-state activation was 1,688 against 3,609. With attention logits quantized to 4 bits, it matched the accuracy of a standard transformer at 6 bits and beat a 4-bit transformer by about 25% in accuracy.

That result matters for model quantization, because a few extreme activations set the range that every other value must share. The same applies to vision models: when Ultralytics YOLO26 is exported with quantize=8, the exporter calibrates activation ranges on images from the data dataset and recommends at least 300 of them, while quantize="w8a16" keeps weights at 8 bits and activations at 16 for LiteRT, Core ML, and QNN exports.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning