Verace Contrast
Differential attention with a symplectic second stream and a context-length gate, with a GPT-2 fine-tuning port that applies it.
- Adaptive context gate: Scales the subtraction by tanh of sequence length
- Short sequences: Behave like standard attention
- Long sequences: Receive full cancellation
- Sequence length: Current length, passed in and not learned
Overview
Verace Contrast is the lab's work on differential attention, a mechanism that subtracts a second softmax attention map from a first to cancel attention mass spread over irrelevant tokens. The lab's papers call the research version UFS-Attention (Unified Fused Symplectic Differential Attention) and present it as an extension of the Differential Transformer, prior work by Wang et al. (2024). The question is whether three changes remove that design's weaknesses: lost rank, constant subtraction at short context, and an extra memory pass. A second part applies the mechanism to GPT-2, OpenAI's 117M model, inside an existing third-party GPT-2 fine-tuning codebase by others. Only the lab's additions are described here.
Standard differential attention splits each head's queries and keys into halves and computes . Here and is learned per head. The lab's design specification makes three changes. The second stream uses and with a fixed symplectic matrix , , in place of half-width projections. An adaptive gate turns subtraction off for short sequences. A fused, SRAM-tiled kernel computes both softmaxes in one streaming pass. The block wraps this in RoPE, SwiGLU and RMSNorm, with RMSNorm applied per head after the subtraction.
The research implementation contains a PyTorch language model that switches between standard and differential attention, the three design variants, toy benchmarks, latency microbenchmarks and figure scripts. The papers report needle retrieval at 16k rising from 31.8% to 89.4% and the W4A4 perplexity penalty falling from 26.18 to 1.34. The lab's code audit found that every plotted figure comes from arrays typed into the plot scripts, with no experiment outputs loaded. It also found that, because is orthogonal, the symplectic stream reproduces the first map exactly. The GPT-2 port adds differential attention, supervised fine-tuning and GRPO but has no recorded evaluation.
Status: plain differential attention, the gated and symplectic variants, the toy benchmarks and the GPT-2 training code are implemented. The fused kernel exists only as a design: the variant named for it computes dense softmax maps in PyTorch. No recorded run supports the retrieval, quantization, latency or ablation figures in the papers, which come from hardcoded data. The symplectic stream adds no information as coded, which contradicts the design's full-rank claim. Whether differential attention helps in the lab's own setting has not been measured. The LiveBench reports test another developer's 4-bit DeepSeek-R1-Distill-Qwen-1.5B model with the lab's GRPO adapter and steering hooks; many outputs are incorrect.
Status
Prototype. The attention variants, toy benchmarks and GPT-2 training code are implemented, but the published figures are hardcoded rather than measured, the fused kernel is not built, no evaluation of the GPT-2 port is recorded, and the only LiveBench evaluation covers a separate harness on a 4-bit DeepSeek-R1-Distill-Qwen-1.5B model with many incorrect outputs.
Simulator
A gate rises from 0 to 1 around a threshold. Two hundred made-up inputs are passed through it: set how steep it is, where its threshold lies and how spread out the inputs are.
- the inputs (made up): those the gate passes in colour
- dashed: a hard step at the same threshold
- Inputs passed
- 51%
- Inputs left undecided
- 56%
- Width of the undecided band
- 1.46
- Mean output of the gate
- 0.51
Make the gate steeper and it tends to a hard step: fewer inputs are left undecided. Move the threshold through the inputs.
This simulator is an illustration of the principle, with made-up numbers. It does not run the lab's code or show the lab's data, and nothing in it is a measurement.
Architecture
Differential attention core
Subtracts a second softmax attention map from the first, scaled by a learned per-head , then applies RMSNorm per head. This follows the Differential Transformer formulation by Wang et al.
Symplectic second stream
Design change that builds the second attention map from and with , so it is not computed from half-width projections. The design specification presents this as a way to keep full rank .
Adaptive context gate
Scales the subtraction by in the sequence length . Short sequences therefore behave like standard attention and long sequences receive full cancellation.
Fused FlashDiff kernel design
A specified single-pass, SRAM-tiled kernel that computes both softmaxes and their difference with memory traffic. The design targets FlashAttention-2 latency; no such kernel is implemented.
Comparison language model
A pre-norm PyTorch transformer with RoPE, RMSNorm and a SiLU MLP. A switch selects standard multi-head attention or differential attention.
Synthetic evaluation suite
Toy experiments on attention mass at a planted target token, key-value associative recall, attention-sink mass and attention entropy.
Latency microbenchmarks
FP16 timing of naive standard attention against naive differential attention across sequence lengths.
Paper figure and diagram scripts
Matplotlib scripts that draw architecture diagrams and result plots for the papers. All plotted result values are written directly into the scripts.
GPT-2 differential attention port
TensorFlow and PyTorch GPT-2 models with optional differential attention, RMSNorm, fast GELU, RoPE and further lab additions. The design keeps compatibility with the original GPT-2 checkpoints.
SFT and GRPO training pipeline
Supervised fine-tuning followed by Group Relative Policy Optimization on prompt and response data. A shell script chains the two stages.
Best-of-N inference harness
Samples several completions at different temperatures and keeps the one a deterministic scorer rates highest. An HTTP chat endpoint exposes the harness.
Implementation
Mechanisms as they are implemented in the source code, with the constants the code uses.
- Half-split differential attention
- In
models.py, each head's and are split into halves, giving the output , followed by per-head RMSNorm in the classMultiHeadDifferentialAttention. This is the published Differential Transformer formulation by other authors, implemented here as the lab's baseline. - Learnable lambda reparameterization
- Per head, , with for layer index . The four vectors are initialized from . This parameterization is the published Differential Transformer formulation by other authors, implemented here as the lab's baseline.
- Symplectic J stream as coded
- In
fused_diff_flash_engine.pythe second stream applies to full-width and . Because is orthogonal, , so . The output then reduces to , and the stream contributes no new information. - Scale-adaptive tanh gate
UnifiedScaleAdaptiveDifferentialAttentioncomputes with , where is the current sequence length passed as a Python scalar and not learned. The gate is about 0.12 at and about 1 at . A docstring mentions 40Hz gamma rhythms, which have no counterpart in the code.- Fused online variant as written
FusedDifferentialAttentionOnlinecarries the fused kernel's name but materializes dense softmax maps in ordinary PyTorch. It has no SRAM tiling and no streaming pass.- Interleaved rotary position embedding
- Frequencies are with . Their outer product with positions gives cosine and sine tables, which rotate interleaved pairs of query and key channels.
- Key-value associative recall task
- A sequence interleaves keys drawn from 1 to 49 with values drawn from 51 to 99 and ends with a queried key. The model must output the paired value as the final token. The deeper benchmark uses sequence length 64, 15 pairs, distractor tokens and 400 training steps.
- Attention sink and entropy metrics
- Sink mass is the mean attention weight on position 0 across queries and heads. Entropy is per row, with clamped at . For differential maps, is renormalized to sum to 1 first.
- FLOP parity derivation
- A comment in
clean_kernel_benchmark.pycounts two products at width plus one product at width . The total is FLOPs, equal to standard attention if the extra softmax and subtraction are ignored. - Naive latency benchmarks
- One benchmark times FP16 attention on random tensors with fixed , sequence lengths 512 to 4096, and 16 heads of dimension 64. A second uses (32 heads of 128) at sequence lengths 512 to 16384. It computes KV-cache size per token, but the value for differential attention is never printed.
- Analytic verification script
verify_solutions.pyinstantiates the three variants and runs forward passes. The rank and gate values it prints are computed analytically, not measured from the outputs.- Hardcoded figure data
- The plot scripts embed literal arrays for retrieval accuracy, INT4 perplexity change, latency, common-mode rejection, kurtosis and ablations. Training loss curves are synthetic exponentials with added noise.
- GPT-2 two-stream attention in PyTorch
verace_torch.pyreimplements GPT-2 asVeraceGPT2withUnifiedFusedSymplecticDiffAttention, a two-stream symplectic differential attention. It loads OpenAI's pretrained weights and generates text with top-k, top-p and repetition penalty.- TensorFlow GPT-2 option flags
src/model.pyandsrc/verace_core.pyadd optional differential attention, RMSNorm, fast GELU, RoPE, symplectic steering andnullspace_orthogonalize()on the embeddings. Training adds a label-smoothed loss, a cosine learning-rate schedule with warmup, and a regularizer the code names topos, whose form is not documented.- Supervised fine-tuning trainers
train_sft.py(TensorFlow) andtrain_sft_torch.py(PyTorch, mixed precision) train on prompt and response pairs with label smoothing and the topos regularizer. The TensorFlow trainer applies the loss to all tokens, including the prompt.- GRPO trainers
- Advantages are rewards standardized within a group of completions for one prompt, , so no value critic is needed.
train_grpo.pyuses a PPO-style clipped surrogate and a heuristic reward.train_grpo_torch.pyuses a sequence log-probability policy gradient without ratio clipping, plus the topos regularizer. - Best-of-N selection with truncation
fix_asi.pyrewrites the inference query routine to sample 3 trajectories, add a reminder about the prompt format, truncate repeated text, and return the highest-scoring answer.- Quantized comparison harness
compare_bench.pycompares a 4-bit DeepSeek-R1-Distill-Qwen-1.5B base model, a model from another developer, with the same model plus a GRPO adapter and steering hooks. The comparison uses 5 LiveBench math questions.full_eval.pyruns 2 questions from each of five LiveBench categories.
Results
From the lab's own experiments and records. They have not been independently replicated.
Symplectic stream duplicates the first attention map
The lab's code audit found that is orthogonal, so and the second map equals the first. This contradicts the design specification's claim that the stream adds full-rank information.
Published result figures are hardcoded, not measured
Every plot script embeds its result arrays directly, and the training loss curves are synthetic exponentials with noise. None of the papers' plotted results is loaded from an experiment output.
Reported retrieval and quantization gains lack recorded runs
The papers report needle retrieval at 16k rising from 31.8% to 89.4% and the W4A4 perplexity penalty falling from 26.18 to 1.34. No run in the evaluation records produces these figures.
Ablation claims conflict with the code
The papers report that removing drops rank to 32 and raises perplexity from 8.1 to 8.9. They also report that a fixed gate adds 0.8 short-context perplexity and that an unfused kernel costs 2.5x latency. These come from hardcoded data, and the result cannot hold as coded, since leaves the attention map unchanged.
Fused kernel is a design only
The variant named for the fused online kernel computes dense softmax maps in PyTorch, and the latency benchmarks compare naive unfused implementations. The FlashAttention-2 latency target is untested.
Verification script reports analytic values
The smoke test prints rank and gate values computed by formula rather than measured from model outputs, so it confirms that the variants run but not the properties the papers claim for them.
Differential attention has FLOP parity on paper
A derivation in the benchmark code gives FLOPs for both standard and differential attention, ignoring the extra softmax and subtraction.
Comparison harness outputs often incorrect
The lab's LiveBench evaluation report covers a harness built on a 4-bit DeepSeek-R1-Distill-Qwen-1.5B model from another developer with the lab's GRPO adapter and steering hooks. Its sample outputs across reasoning, coding, data analysis, instruction following and language tasks are often visibly incorrect or truncated. No evaluation of the GPT-2 port itself is recorded.
Concepts
- Common-mode attention noise
- Softmax gives every token some weight, so irrelevant tokens share a background level of attention. Subtracting two maps that share this background cancels it, by analogy with a differential amplifier.
- Differential Transformer
- Prior work by Wang et al. (2024) that subtracts two softmax maps computed from channel-split projections. The lab's papers build on it and criticize it for three weaknesses.
- Softmax noise floor
- A corollary in the lab's papers states that total attention on distractors tends to 1 as sequence length grows. The papers use it to explain why standard attention degrades at long context.
- Common-mode rejection theorem
- A claim in the lab's papers that with a suitably tuned , distractor weights in the differential map become exactly zero.
- Symplectic matrix
- A matrix in the symplectic group . The one used here satisfies and is also orthogonal, which is why it leaves inner products unchanged.
- Rank of the second stream
- The design specification argues that half-width projections reduce attention rank and that the stream keeps full rank . The code audit shows the stream recomputes the first map, so the rank claim does not translate into a distinct second map.
- Scale-adaptive gate
- A gate that scales subtraction strength with sequence length, . It leaves short inputs close to standard attention.
- Head RMSNorm
- Root-mean-square normalization applied to each head's output after the subtraction. It bounds the variance that the difference of two maps can produce.
- Attention sink
- The tendency of attention to pile onto uninformative positions such as the first token. The suite measures it as mean weight on position 0.
- Needle-in-a-haystack retrieval
- A test in which one relevant fact is planted in a long context and the model must retrieve it. The papers' figures for it are hardcoded.
- FlashAttention-style fusion
- Computing attention in tiles held in on-chip SRAM, so the full map is never written to main memory. The fused differential kernel is specified this way but not implemented.
- Kurtosis and INT4 quantization
- Corollary 4.4 in the papers bounds activation kurtosis by through sink suppression. The papers argue this permits near-lossless 4-bit quantization.
- W4A4 quantization
- 4-bit weights and 4-bit activations. The papers report the perplexity penalty under this setting; the values come from hardcoded figure data.
- Rotary position embedding
- Encodes position by rotating pairs of query and key channels by position-dependent angles, so attention scores depend on relative position.
- Supervised fine-tuning
- Training a pretrained model on prompt and response pairs with a next-token loss. It is the first stage of the GPT-2 pipeline.
- Group Relative Policy Optimization
- A reinforcement learning method that standardizes each completion's reward against others sampled for the same prompt. This removes the need for a learned value critic.
- Best-of-N inference
- Drawing several sampled answers and keeping the one a scoring function rates highest. Inference compute is traded for answer quality.
- LiveBench
- An external benchmark with reasoning, coding, data analysis, instruction following, language and math categories. The lab used a few of its questions to check a comparison harness built on another developer's 4-bit DeepSeek-R1-Distill-Qwen-1.5B model with the lab's GRPO adapter and steering hooks, not the GPT-2 port.
Publications
- Differential Attention: Eliminating Attention Noise, Attention Sinks, and Context Smearing via Dual-Subspace Common-Mode CancellationAugust 24, 2026
- Unified Fused Symplectic Differential Attention: Symplectic Geometry, Adaptive Gating, and Fused Online Kernels for Noise-Free Long-Context Sequence ModelingAugust 24, 2026
About this page
Written from the lab's own documents and source code. Figures and results are the lab's measurements as it recorded them at the time, and have not been independently replicated.
Published under the PolyForm Noncommercial License 1.0.0: free for noncommercial use.