Primal-Attention: Self-attention through Asymmetric Kernel SVD in Primal Representation

Recently, a new line of works has emerged to understand and improve self-attention in Transformers by treating it as a kernel machine. However, existing works apply the methods for symmetric kernels to the asymmetric self-attention, resulting in a nontrivial gap between the analytical understanding and numerical implementation. In this paper, we provide a new perspective to represent and optimize self-attention through asymmetric Kernel Singular Value Decomposition (KSVD), which is also motivated by the low-rank property of self-attention normally observed in deep layers. Through asymmetric KSVD, $i$) a primal-dual representation of self-attention is formulated, where the optimization objective is cast to maximize the projection variances in the attention outputs; $ii$) a novel attention mechanism, i.e., Primal-Attention, is proposed via the primal representation of KSVD, avoiding explicit computation of the kernel matrix in the dual; $iii$) with KKT conditions, we prove that the stationary solution to the KSVD optimization in Primal-Attention yields a zero-value objective. In this manner, KSVD optimization can be implemented by simply minimizing a regularization loss, so that low-rank property is promoted without extra decomposition. Numerical experiments show state-of-the-art performance of our Primal-Attention with improved efficiency. Moreover, we demonstrate that the deployed KSVD optimization regularizes Primal-Attention with a sharper singular value decay than that of the canonical self-attention, further verifying the great potential of our method. To the best of our knowledge, this is the first work that provides a primal-dual representation for the asymmetric kernel in self-attention and successfully applies it to modeling and optimization.

Paper

Similar papers

Peer review

Reviewer aphr7/10 · confidence 2/52023-06-25

Summary

Self-attention mechanisms serve as pivotal components in the domains of natural language processing and computer vision. Previous kernel function based self-attention variants, which are predicated on Mercer kernels, tend to overlook the inherent asymmetry of the attention matrix in the vanilla self-attention. In response to this oversight, this study introduces a novel approach, termed Primal-Attention. This approach leverages asymmetric Kernel Singular Value Decomposition (KSVD) to facilitate a low-rank approximation of the attention matrix, thereby incorporating an asymmetric kernel attention matrix. The empirical findings substantiate that Primal-Attention functions as a low-rank attention mechanism, exhibiting superior performance while maintaining low time complexity.

Strengths

1. This paper introduces a novel perspective that interprets the self-attention mechanism as a KSVD optimization problem.

Weaknesses

1. The exposition of methodologies in this paper lacks sufficient clarity. For instance, the crucial concept of primal optimization in self-attention with KSVD, as proposed in Equation 6, is introduced abruptly without a detailed discussion of the connection between KSVD and self-attention. 2. Algorithm 1, outlined in Appendix B.1, details the entire process of Primal-Attention and employs random projection. However, the omission of a citation for the Johnson–Lindenstrauss lemma in the paper is inappropriate.

Questions

1. Why should the primal optimization function, as depicted in Equation 6, be considered? On what basis is this function proposed? Furthermore, why should this function be maximized rather than minimized? 2. Why is the formula for Primal-Attention in each head represented by Equation 11? The process of derivation appears to be missing. 3. How do the authors handle the positive diagonal matrix $\mathbf{\Lambda}$? Given that $\mathbf{\Lambda}$ is a key component in Equations 6 and 11, can the authors provide a detailed explanation of the process?

Rating

7: Accept: Technically solid paper, with high impact on at least one sub-area, or moderate-to-high impact on more than one areas, with good-to-excellent evaluation, resources, reproducibility, and no unaddressed ethical considerations.

Confidence

2: You are willing to defend your assessment, but it is quite likely that you did not understand the central parts of the submission or that you are unfamiliar with some pieces of related work. Math/other details were not carefully checked.

Soundness

3 good

Presentation

2 fair

Contribution

3 good

Limitations

N/A

Reviewer 8hph7/10 · confidence 5/52023-07-07

Summary

This paper proposes a new understanding of self-attention in transformers via asymmetric Kernel Singular Value Decomposition (KSVD). In particular, the authors formulate a primal-dual representation of self-attention for maximizing the projection variances in the attention outputs and then derive a new attention mechanism, namely the Primal-Attention, to avoid direct computation of the kernel matrix. Using KKT conditions, they prove the Primal-Attention can obtain a zero-value objective. Experimental results are provided to justify the advantage of the Primal-Attention.

Strengths

1. The idea of formulating self-attention as solving an KSVD problem is novel and of potentially high-impact. 2. The derivation of self-attention from KSVD given in the paper is elegant and correct. 3. The paper is well-written, easy to follow, and enjoyable to read.

Weaknesses

1. More large-scale experiments, e.g., on full ImageNet or WikiText103 language modeling, should be conducted. 2. Empirical analysis, such as the efficiency analysis of the Primal-Attention vs. the baselines, should be provided to help provide better understanding of the proposed method.

Questions

1. Can the proposed KSVD framework be used to explain other components in a self-attention unit, such as the residual connection, the layer normalization, and the feedforward network?

Rating

7: Accept: Technically solid paper, with high impact on at least one sub-area, or moderate-to-high impact on more than one areas, with good-to-excellent evaluation, resources, reproducibility, and no unaddressed ethical considerations.

Confidence

5: You are absolutely certain about your assessment. You are very familiar with the related work and checked the math/other details carefully.

Soundness

4 excellent

Presentation

4 excellent

Contribution

4 excellent

Limitations

The authors have not clearly addressed the limitations of their work.

Reviewer 2pAx4/10 · confidence 4/52023-07-07

Summary

This paper proposes a Primal-Attention method to realize self-attention blocks in Transformer with a kernel matrix. It firstly explains the relationships between self-attention and asymmetric kernel matrix. Secondly it formulates self-attention in the form of kernel SVD and derive its primal and dual representations. And eventually it proposes Primal-Attention, which uses not only the projection scores involving the right singular vectors of the asymmetric attention kernel K, but also the ones involving the left singular vectors of the asymmetric attention kernel K. Besides, it conducts several experiments on several tasks.

Strengths

1. The motivation to formulate a neural network structure into a kernel one is quite interesting and meaningful. 2. The primal-dual representations are derivable.

Weaknesses

1. The explanation of why the projection scores involving the left singular vectors of the asymmetric attention kernel K are used is not adequate. It lacks enough analyses to prove their importance. 2. The results of experiments show little improvements compared with baseline methods. And only LRA benchmark has efficiency analyses.

Questions

1. Why are the projection scores involving the left singular vectors of the asymmetric attention kernel K so important? What does it mean physically by doing so? 2. Why do you conduct experiments of efficiency only on LRA benchmark? And why does Primal+ have less efficiency than Primal+Trans?

Rating

4: Borderline reject: Technically solid paper where reasons to reject, e.g., limited evaluation, outweigh reasons to accept, e.g., good evaluation. Please use sparingly.

Confidence

4: You are confident in your assessment, but not absolutely certain. It is unlikely, but not impossible, that you did not understand some parts of the submission or that you are unfamiliar with some pieces of related work.

Soundness

2 fair

Presentation

2 fair

Contribution

2 fair

Limitations

Yes

Reviewer 8hph2023-08-18

More Questions on the Efficiency Advantage of Primal Attention

Thank you for your response. Could you please give further clarifications for the following point? 1. The memory advantage of Primal + DeiT-Small over the baseline DeiT-Small is not very significant while both obtain similar accuracies. Given this result, it is hard to claim that Primal + DeiT-Small is more efficient than the baseline. Can you also provide the running time analysis of Primal + DeiT-Small v.s. the baseline DeiT-Small for this experiment on ImageNet-1K? Similarly, how about the memory usage and running time for models trained on WikiText-103? 2. Why does Primal Attention gain more advantage in memory usage and running time on UEA Time Series than on D4RL and ImageNet-1K tasks?

Authorsrebuttal2023-08-20

Response to further questions on efficiency

We thank the reviewer for the in-depth comments on further clarifications of the efficiency analysis. Below, we address the raised two points in detail. ### R.1 Efficiency analysis on large-scale datasets **Experiment setups and results** For ImageNet-1K and WikiText-103, we provide the training memory and time on a single V100 GPU in Table 1.1 and Table 1.2 below. In the experiment, we adopt the architecture of "Primal.$+$Backbone", where the last attention layer of the Transformer is replaced by our Primal-Attention. As in large-scale data and complicated tasks, less information compression can be desired in the learning, especially in shallow layers, we thereby implement our KSVD-based Primal-Attention in the deep layer. Relevant explanations can refer to the 1st paragraph in Sec.5 in paper. + *ImageNet-1K:* While attaining the same accuracy and an enhanced low-rank property (Fig.1 in the paper), the efficiency gain of our Primal.$+$DeiT-Small/16 is limited, as we only replace the last layer of the 12-layer baseline with our Primal-Attention. Hence, it is reasonable that the efficiency improvement is less significant than that of UEA and LRA where we either implement both layers in the 2-layer baseline by Primal-Attention ("Primal."), or replace the 2nd layer ("Primal.$+$"). + *WikiText-103:* Our "Primal.$+$Trans." shows similar efficiency as the 6-layer baseline, but significantly reduces the perplexity by $2.0$. Compared to the fine-tuned SoTA Flowformer (see Table 2 in our rebuttal), our "Primal.$+$Trans" is slightly inferior in perplexity by a small margin of 0.2, however, Flowformer is significantly less efficient by requiring $28.8 $% more running time than ours. The current "Primal.$+$Trans." is simply with default setups, better perplexity can still be expected by further tuning. **Table 1.1:** Efficiency analysis on ImageNet-1K. |ImageNet-1K|Top-1|Memory(GB)|Time(s/1K-steps)| |:-:|:-:|:-:|:-:| |DeiT-Small/16|79.8|14.2|2425.5| |Primal.$+$DeiT-Small/16|79.8|14.0|2330.2| **Table 1.2:** Efficiency analysis on WikiText-103. |WikiText-103|Perplexity($\downarrow$)|Memory(GB)|Time(s/1K-steps)| |:-:|:-:|:-:|:-:| |Trans.(2017)|33.0|9.0|3108.4| |Flow.(2022)|30.8|10.5|3998.4| |Primal.$+$Trans.|31.0|8.9|3104.0| **Further remarks** In summary, the efficiency gain of Primal-Attention implemented networks over baselines is influenced by two main factors: *1)* number of Primal-Attention layers used in the architecture, the more the better; *2)* sequence length of the training data, the longer the more significant. + With deep architectures, the efficiency can be further improved by replacing more layers with our Primal-Attention. Yet, in very deep Transformers, Primal-Attention is not necessarily always superior in performance when being applied to all layers, as the learning in shallow layers may not enjoy the benefits from the low-rank property from KSVD as much as the higher layers do. It would be interesting to explore a more generic implementation setup for Primal-Attention in very deep Transformers, as briefly mentioned in the last paragraph of possible future work in the Supplementary Material. + The length of the data sequence, i.e., $N$, is also a key influencing the efficiency. By avoiding the computation of the $N\times N$ attention matrix, our Primal-Attention can gain better efficiency on longer-sequence datasets. Although ImageNet-1K is large-scale, currently Transformers treat each image as a sequence of length 197 (with $\tt cls$ token), which is actually not too long (even compared to some UEA datasets as shown in Table 3 in our rebuttal). Hence, this is also a reason why our Primal.$+$DeiT-Small/16 does not improve the efficiency significantly. Similarly in WikiText-103, the data sequence length is 512, which is also not really long, hence the efficiency of our "Primal.$+$Trans." is not always superior under the current setups. ### R.2 Efficiency gain of "Primal.$+$" in different tasks The efficiency gain of "Primal.$+$" over baseline is more significant on UEA and LRA, as the backbone has only 2 layers, hence replacing one layer makes a difference to the overall architecture. Moreover, UEA and LRA in general have longer training sequence length, which would signalize Primal-Attention's efficiency. In contrast, the backbones on D4RL, WikiText-103 and ImageNet-1K have more layers where canonical self-attention layers are the majority structures in "Primal.$+$" as shown in Table 2.1 below. Besides, the efficiency gain is less significant also due to the shorter training sequence lengths on these datasets. Explanations can refer to the response R.1 above. **Table 2.1:** Architecture of Primal.$+$. |Primal.$+$|canonical_layer+[primal_layer]|num_head|head_dim| |:-:|:-:|:-:|:-:| |UEA|1+[1]|8|64| |LRA|1+[1]|2|32| |D4RL|2+[1]|4|64| |WikiText-103|5+[1]|8|64| |ImageNet-1K|11+[1]|6|64|

Reviewer 8hph2023-08-21

Many thanks for the prompt response. The authors have addressed my concerns. I will retain my score.

Reviewer 2pAx2023-08-19

Thanks for your response. I still have some questions. In the Table 2pAx-1, the performance of Primal with both projections is significantly worse than the Primal+Trans without both projections but has projection scores involving right singular vectors in Transformer, is it means that the projection scores involving the left singular vectors has bad influence on the performance? On the other hand, from the results of Primal+Trans in Table 2pAx-1, utilizing the both projections only has slightly better performance on two tasks, while shows negligible improvements on the remaining three task. The necessity of utilizing left singular vectors should be explained more intuitively.

Authorsrebuttal2023-08-20

Further response to the benefits of left singular vectors

We thank the reviewer for the reply. We provide the following 3 aspects to address your concerns and eliminate possible confusions. ### 1. Projection scores involving left singular vectors are beneficial to the performance. For clarity, in Table R.1 we summarize the setups and architectures of Table 2pAx-1. We use the 2-layer backbone baseline commonly used on LRA. To make the ablation more comprehensive, we **respectively** conduct this study on the two main architectures in this work, i.e., Primal. and Primal.$+$Trans. (see the 1st paragraph of Sec.5 in the paper for details). **Table R.1:** Ablation setups on LRA. |Primal.|w/o $r$-scores|w/ $r$-scores| |:-:|:-:|:-:| |Layer 1|[right]|[right;left]| |Layer 2|[right]|[right;left]| |Avg. Acc.|45.6|**57.5**| |Primal.$+$Trans.|w/o $r$-scores|w/ $r$-scores| |:-:|:-:|:-:| |Layer 1|canonical attention|canonical attention| |Layer 2|[right]|[right;left]| |Avg. Acc.|59.4|**60.4**| The two subtables in Table 2pAx-1 are the ablation study of using the left singular vectors on **two different network architectures respectively**, so that their results are not directly comparable under the setups in this ablation. Therefore, it is not the left singular vectors that bring bad influence on the performance, and such evaluations should be considered separately in these two subtables. More specifically, 1. Using the projections of left singular vectors, i.e., (w/ $r$-scores), is helpful to the performance, when Primal-Attention is applied to all layers (Primal.) and also when it is applied only to deep layer (Primal.$+$Trans.). The role of the left singular vectors is more influential in Primal. for boosting the performance, where all canonical attention is replaced with the KSVD-based Primal-Attention. 2. As mentioned by the reviewer, Primal.(w/ $r$-scores) has inferior performance than Primal.$+$Trans.(w/o $r$-scores). This is due to: Primal.(w/ $r$-scores) applies low-rank KSVD to the first layer, where the learning in this shallow layer does not always desire for the low-rank property from KSVD as much as the deep layer does on LRA. ### 2. Performance gain is substantial. From the results of Primal.$+$Trans. in Table 2pAx-1, the mentioned performance improvement is substantial on LRA. 1. *We obtain 1% gain (59.4% $\to$ 60.4%) in average accuracy:* In Table 2 in paper, recent SoTA method YOSO-E has only 0.4\% gain compared to the baseline. Hence, 1% gain can be regarded as substantial on LRA. 2. *LRA benchmark should be evaluated as a whole:* Since there are five different tasks in this benchmark, the average accuracy is the most conclusive measure, which is also attached great importance by almost all SoTA methods. In Table 2 in paper, YOSO-E even has inferior performance on Pathfinder dataset than baseline. However, this cannot diminish its overall better performance on this benchmark. 3. *In each individual task, using both projection scores consistently brings improvement*: As in Table R.2, the accuracy gain is significant on at least 3 tasks: Retrieval, Image and Pathfinder; besides, using both projection scores consistently improves performances in all tasks, which is substaintial for the LRA benchmark. **Table R.2:** Acc.(%) gain of Primal.$+$Trans.(w/ $r$-scores) over Primal.$+$Trans.(w/o $r$-scores). |Primal.$+$Trans.|ListOps|Text|Retrieval|Image|Pathfinder|Avg.Acc.| |:-:|:-:|:--:|:-:|:-:|:-:|:-:| |Acc.$\uparrow$|0.2|0.3|1.8|1.1|1.5|1.0| ### 3. Necessity remarks 1. **Theoretically,** the derived KSVD can be regarded as a low-rank approximation to the self-attention kernel matrix where utilizing both left and right singular vectors leads to the optimal approximation. 2. **Experimentally,** using both projection scores brings substantial performance gain than using only one. 3. **Intuitively,** using both projection scores can be treated as considering both directions in a directed graph. Section 2 in the paper presents the asymmetric attention weight $K_{ij}=\kappa(\boldsymbol x_i, \boldsymbol x_j)=\text{softmax}(a(\boldsymbol x_i, \boldsymbol x_j))$ with $a(\boldsymbol x_i, \boldsymbol x_j)=\left<q(\boldsymbol x_i), k(\boldsymbol x_j)\right>/\sqrt{d_k}$. This shows that the attention kernel $K$ can be interpreted as message passing in a directed graph in relation to queries and keys, with asymmetric similarity measures $\kappa(\boldsymbol x_i, \boldsymbol x_j)\neq\kappa(\boldsymbol x_j, \boldsymbol x_i)$. Using only the right singular vectors means considering only one directionality, where additional information might reside in another directionality to enhance the learning on such an asymmetric kernel matrix. Useful references can be checked on page 128-129 in [1] for graph theory. In the asymmetric case, it is natural to consider directed information, i.e., both right and left singular vectors as in our case, for enhancing performance. [1] Estrada, E. "The structure of complex networks: theory and applications." Oxford University Press, 2012.

Reviewer aphr2023-08-21

Thanks for the authors' response. I have no further questions about this paper.

Program Chairsdecision2023-09-21

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC