We present a theoretical analysis of the Jacobian of an attention block within a transformer, showing that it is governed by the query, key, and value projections that define the attention mechanism. Leveraging this insight, we introduce a method that systematically alters the spectral properties of each attention layer to reduce the Jacobian's condition number, thereby improving the overall conditioning of the attention layers within a transformer network. We empirically show that this improved Jacobian conditioning translates to enhanced performance in practice. Our approach is simple, broadly applicable, and can be easily integrated as a drop-in replacement for a wide range of existing attention mechanisms. We validate its effectiveness across diverse transformer architectures and tasks, demonstrating consistent improvements in performance.
Figures & tables
Figure 1: An illustration of spectrally conditioned self-attention within a transformer layer. At each layer, the self-attention weights WQ , WK , and WV are modified by adding correction terms CQ , CK , and CV , respectively. The correction terms CQ , CK , and CV are initialized before training using Theorem 3.8 and remain fixed throughout training.
Figure 2: Analysis for ViT-B. Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) and their spectrally conditioned counterparts ( WQ+CQ , WK+CK , WV+CV ) throughout training. Middle: Condition numbers of WQ , WK , and WV , and their spectrally conditioned forms during training. Right: Average condition number of the self-attention Jacobian over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 .
Figure 3: Analysis for XCiT-M. Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) and their spectrally conditioned counterparts ( WQ+CQ , WK+CK , WV+CV ) throughout training. Middle: Condition numbers of WQ , WK , and WV , and their spectrally conditioned forms during training. Right: Average condition number of the self-attention Jacobian over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 .
ViT-B
DeiT-B
Swin-B
XCiT-M
DaViT-B
Original
80.7 ( ± 0.41)
81.6 ( ± 0.30)
83.4 ( ± 0.28)
82.6 ( ± 0.39)
84.3 ( ± 0.26)
Spec. cond.
81.7 ( ± 0.38)
82.6 ( ± 0.32)
84.1 ( ± 0.25)
83.5 ( ± 0.35)
84.9 ( ± 0.21)
Table 1: Comparison of Vision Transformers with their original attention architecture versus one with spectrally conditioned attention (Spec. cond.), pre-trained on the ImageNet-1k dataset. We report Top-1% classification accuracy. In each case, spectral conditioning improves performance over the original attention mechanism.
Model
APb
AP50b
AP75b
APm
AP50m
AP75m
original
44.9 ( ± 0.33)
66.1 ( ± 0.31)
48.9 ( ± 0.35)
40.1 ( ± 0.29)
63.1 ( ± 0.31)
42.8 ( ± 0.34)
Spec. cond.
45.6 ( ± 0.31)
66.7 ( ± 0.36)
49.6 ( ± 0.32)
40.5 ( ± 0.33)
63.4 ( ± 0.28)
43.3 ( ± 0.32)
Table 2: Performance evaluation of object detection and instance segmentation on the COCO dataset. For each metric, our spectrally conditioned architecture (Spec. cond.) outperforms the original.
Figure 4: Analysis for Nyströmformer on text classification task. Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) and their spectrally conditioned counterparts ( WQ+CQ , WK+CK , WV+CV ) throughout training. Middle: Condition numbers of WQ , WK , and WV , and their spectrally conditioned forms during training. Right: Average condition number of the attention Jacobian over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 .
Model
ListOps
Text
Retrieval
Image
Pathfinder
Original
37.1 ( ± 0.21)
63.8 ( ± 0.24)
79.8 ( ± 0.26)
39.9 ( ± 0.20)
72.9 ( ± 0.25)
Spec. cond.
37.8 ( ± 0.23)
64.8 ( ± 0.20)
80.6 ( ± 0.27)
40.2 ( ± 0.22)
73.7 ( ± 0.23)
Table 3: Comparison of a Nyströmformer using its original architecture (original) with a Nyströmformer using spectral conditioned attention (Spec. cond.) on the LRA benchmark. We report evaluation accuracy (%). As shown, our methodology consistently improves performance across all tasks.
MNLI
SST-2
STSB
RTE
QNLI
QQP
MRPC
CoLA
Avg.
Original
83.8 ( ± 0.21)
92.3 ( ± 0.18)
86.3 ( ± 0.21)
55.1 ( ± 0.20)
90.1 ( ± 0.23)
87.3 ( ± 0.15)
85.0 ( ± 0.25)
48.9 ( ± 0.26)
78.6
Spec. cond.
84.3 ( ± 0.20)
92.7 ( ± 0.19)
86.6 ( ± 0.22)
55.5 ( ± 0.24)
91.0 ( ± 0.22)
87.5 ( ± 0.23)
86.1 ( ± 0.23)
51.7 ( ± 0.24)
79.4
Table 4: Evaluation of a pre-trained Crammed BERT on the GLUE benchmark using the original architecture (Original) and our spectrally conditioned variant (Spec. cond.). Spectral conditioning improves performance across all tasks.
Appendix figures & tables25 assets
Supplementary material from the paper’s appendix.
Appendix
λ
2
4
6
8
10
12
14
16
ViT-B Acc.
80.8
81.1
81.4
81.6
81.7
81.7
81.6
81.5
Appendix
Table 5: Ablation on λ for ViT-B
ViT-B
DeiT-B
Swin-B
XCiT-M
DaViT-B
Original (with only layer norm.)
80.7 ( ± 0.41)
81.6 ( ± 0.30)
83.4 ( ± 0.28)
82.6 ( ± 0.39)
84.3 ( ± 0.26)
Spec. cond. + layer norm.
81.7 ( ± 0.38)
82.6 ( ± 0.32)
84.1 ( ± 0.25)
83.5 ( ± 0.35)
84.9 ( ± 0.21)
Spec. cond. - layer norm.
79.8 ( ± 0.31)
80.4 ( ± 0.33)
80.5 ( ± 0.23)
80.0 ( ± 0.35)
80.3 ( ± 0.21)
Appendix
Table 6: Performance comparison of spectral conditioning with and without layer normalization.
Model
Acc.
Training time (hrs:mins)
ViT-B (original)
80.7
29:29
ViT-B spec. cond. (Thm. 3.5)
82.0
41:38
ViT-B spec. cond. (Thm. 3.8)
81.7
29:33
DeiT-B (original)
81.6
26:16
DeiT-B spec. cond. (Thm. 3.5)
82.9
37:54
DeiT-B spec. cond. (Thm. 3.8)
82.6
26:24
Appendix
Table 7: Comparison of accuracy and training time across transformer variants with spectral conditioning of attention following Theorem 3.5 and Theorem 3.8 .
Memory Aspect
Original Attention
With Spectral Conditioning
Trainable Parameters
3×Dd
3×Dd
Gradient Storage
3×Dd
3×Dd
Correction Matrices ( CQ , CK , CV )
–
negligible (constant scalar)
Activation Memory
3×Nd
3×Nd (no extra tensors)
Appendix
Table 8: Comparison of memory overhead for spectral conditioning relative to standard attention projections.
Operation
FLOPS (Original)
FLOPS (With Spectral Conditioning)
Query projection ( XWQ )
2NDd
2NDd+Nd
Key projection ( XWK )
2NDd
2NDd+Nd
Value projection ( XWV )
2NDd
2NDd+Nd
Total Projection FLOPS
6NDd
6NDd+3Nd
Appendix
Table 9: FLOPS comparison for the forward pass of the attention projection layers with and without spectral conditioning. N denotes the sequence length, D the embedding dimension, and d the projection dimension per head.
Figure 5: Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation. Right: Average minimum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation.
Figure 6: Left: Average maximum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation. Right: Average maximum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation.
Figure 7: Left: Average condition number of the query, key, and value projection matrices ( WQ , WK , WV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation. Right: Average condition number of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a ViT-B during training. We plot the mean over five trials and the standard deviation.
Figure 8: Average condition number of the self-attention Jacobian of a ViT-B over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 . We ran five trials with five different random seeds with plots showing the mean and standard deviations.
Figure 9: Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation. Right: Average minimum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation.
Figure 10: Left: Average maximum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation. Right: Average maximum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation.
Figure 11: Left: Average condition number of the query, key, and value projection matrices ( WQ , WK , WV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation. Right: Average condition number of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a XCiT-M during training. We plot the mean over five trials and the standard deviation.
Figure 12: Average condition number of the self-attention Jacobian of a XCiT-M over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 . We ran five trials with five different random seeds with plots showing the mean and standard deviations.
Model
APb
AP50b
AP75b
APm
AP50m
AP75m
Swin-base
45.9
67.1
50.1
41.1
63.7
43.8
Spec. cond. Swin-base
46.8
68.1
50.7
41.8
64.2
44.6
Appendix
Table 10: Comparison of Swin-base and spectrally conditioned (spec. cond.) Swin-base on COCO benchmarks.
λ
2
4
6
8
10
12
14
16
Acc.
63.7
64.1
64.3
64.6
64.8
64.8
64.7
64.7
Appendix
Table 11: Ablation on λ for Nyströmformer on text classification task.
Acc.(%)
Original (with only layer norm.)
63.8 ( ± 0.24)
Spec. cond. + layer norm.
64.8 ( ± 0.20)
Spec. cond. - layer norm
62.3 ( ± 0.23)
Appendix
Table 12: Comparing spectral conditioning with and without layer normalization for the Nyströmformer on text classification.
Figure 13: Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the text classification task during training. We plot the mean over five trials and the standard deviation. Right: Average minimum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the text classification during training. We plot the mean over five trials and the standard deviation.
Figure 14: Left: Average maximum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the text classification task during training. We plot the mean over five trials and the standard deviation. Right: Average maximum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the text classification during training. We plot the mean over five trials and the standard deviation.
Figure 15: Left: Average condition number of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the text classification task during training. We plot the mean over five trials and the standard deviation. Right: Average condition number of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the text classification task during training. We plot the mean over five trials and the standard deviation.
Figure 16: Average condition number of the self-attention Jacobian of a Nyströmformer on the text classification task over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 . We ran five trials with five different random seeds with plots showing the mean and standard deviations.
Figure 17: Analysis for Nyströmformer on listops task. Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) and their spectrally conditioned counterparts ( WQ+CQ , WK+CK , WV+CV ) throughout training. Middle: Condition numbers of WQ , WK , and WV , and their spectrally conditioned forms during training. Right: Average condition number of the attention Jacobian over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 .
Figure 18: Left: Average minimum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation. Right: Average minimum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation.
Figure 19: Left: Average maximum singular value of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation. Right: Average maximum singular value of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation.
Figure 20: Left: Average condition number of the query, key, and value projection matrices ( WQ , WK , WV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation. Right: Average condition number of the corrected query, key, and value projection matrices ( WQ+CQ , WK+CK , WV+CV ) for a Nyströmformer on the listops task during training. We plot the mean over five trials and the standard deviation.
Figure 21: Average condition number of the self-attention Jacobian of a Nyströmformer on the listops task over the course of training, before and after spectral conditioning, along with the theoretical bound from Equation 10 . We ran five trials with five different random seeds with plots showing the mean and standard deviations.