当前位置: 首页 > news >正文

长安东莞网站设计手机如何创建网站

长安东莞网站设计,手机如何创建网站,深圳建网站价格,wordpress地址设置XAttention 计算步骤详解及示例 XAttention 是一种高效的块稀疏注意力机制,通过 反对角线评分(Antidiagonal Scoring) 和 动态阈值选择 来优化长序列 Transformer 模型的推理效率。以下是其核心计算步骤及具体示例。 1. XAttention 的核心步…

XAttention 计算步骤详解及示例

XAttention 是一种高效的块稀疏注意力机制,通过 反对角线评分(Antidiagonal Scoring)动态阈值选择 来优化长序列 Transformer 模型的推理效率。以下是其核心计算步骤及具体示例。


1. XAttention 的核心步骤

Step 1: 计算原始注意力分数

输入:

  • Query Q ∈ R n × d Q \in \mathbb{R}^{n \times d} QRn×d
  • Key K ∈ R m × d K \in \mathbb{R}^{m \times d} KRm×d
  • Value V ∈ R m × d v V \in \mathbb{R}^{m \times d_v} VRm×dv

计算未缩放的注意力分数:
S = Q K T S = QK^T S=QKT

Step 2: 反对角线评分(Antidiagonal Scoring)

  1. 分块计算:将 S S S 划分为 B × B B \times B B×B 的块(如 8 × 8 8 \times 8 8×8)。
  2. 反对角线求和:对每个块,计算反对角线(从左下到右上)元素的和,作为块的重要性分数:
    Score = ∑ i + j = k A i , j \text{Score} = \sum_{i+j=k} A_{i,j} Score=i+j=kAi,j
    • 其中 k k k 是反对角线索引,例如 k = 0 , 1 , . . . , 2 B − 2 k=0,1,...,2B-2 k=0,1,...,2B2

Step 3: 阈值块选择

  1. 归一化:对块分数进行 softmax 归一化:
    P = softmax ( Score ) P = \text{softmax}(\text{Score}) P=softmax(Score)
  2. 选择关键块:保留累积概率超过阈值 τ \tau τ 的最小块集合 B ∗ B^* B
    B ∗ = arg ⁡ min ⁡ ∣ B ∣ s.t. ∑ ( i , j ) ∈ B P i , j > τ B^* = \arg \min |B| \quad \text{s.t.} \quad \sum_{(i,j) \in B} P_{i,j} > \tau B=argminBs.t.(i,j)BPi,j>τ

Step 4: 稀疏注意力计算

仅计算选中的关键块 B ∗ B^* B 的注意力权重,并加权聚合 V V V
Output = ∑ ( i , j ) ∈ B ∗ A i , j V j \text{Output} = \sum_{(i,j) \in B^*} A_{i,j} V_j Output=(i,j)BAi,jVj


2. 计算示例

输入数据

假设 d = 2 d=2 d=2,输入如下:

  • Query (Q)
    Q = [ 1.0 2.0 3.0 4.0 ] Q = \begin{bmatrix} 1.0 & 2.0 \\ 3.0 & 4.0 \\ \end{bmatrix} Q=[1.03.02.04.0]
  • Key (K)
    K = [ 5.0 6.0 7.0 8.0 9.0 10.0 ] K = \begin{bmatrix} 5.0 & 6.0 \\ 7.0 & 8.0 \\ 9.0 & 10.0 \\ \end{bmatrix} K= 5.07.09.06.08.010.0
  • Value (V)
    V = [ 1.0 0.0 1.0 0.0 1.0 0.0 1.0 1.0 0.0 ] V = \begin{bmatrix} 1.0 & 0.0 & 1.0 \\ 0.0 & 1.0 & 0.0 \\ 1.0 & 1.0 & 0.0 \\ \end{bmatrix} V= 1.00.01.00.01.01.01.00.00.0

Step 1: 计算原始注意力分数 S = Q K T S = QK^T S=QKT

S = [ 1 ⋅ 5 + 2 ⋅ 6 1 ⋅ 7 + 2 ⋅ 8 1 ⋅ 9 + 2 ⋅ 10 3 ⋅ 5 + 4 ⋅ 6 3 ⋅ 7 + 4 ⋅ 8 3 ⋅ 9 + 4 ⋅ 10 ] = [ 17 23 29 39 53 67 ] S = \begin{bmatrix} 1 \cdot 5 + 2 \cdot 6 & 1 \cdot 7 + 2 \cdot 8 & 1 \cdot 9 + 2 \cdot 10 \\ 3 \cdot 5 + 4 \cdot 6 & 3 \cdot 7 + 4 \cdot 8 & 3 \cdot 9 + 4 \cdot 10 \\ \end{bmatrix} = \begin{bmatrix} 17 & 23 & 29 \\ 39 & 53 & 67 \\ \end{bmatrix} S=[15+2635+4617+2837+4819+21039+410]=[173923532967]

Step 2: 反对角线评分(假设块大小 2 × 2 2 \times 2 2×2

  • 块 1 S 1 : 2 , 1 : 2 S_{1:2,1:2} S1:2,1:2):
    反对角线元素 = { 17 , 53 } 和 = 17 + 53 = 70 \text{反对角线元素} = \{17, 53\} \quad \text{和} = 17 + 53 = 70 反对角线元素={17,53}=17+53=70
  • 块 2 S 1 : 2 , 2 : 3 S_{1:2,2:3} S1:2,2:3):
    反对角线元素 = { 23 , 67 } 和 = 23 + 67 = 90 \text{反对角线元素} = \{23, 67\} \quad \text{和} = 23 + 67 = 90 反对角线元素={23,67}=23+67=90

Step 3: 阈值块选择(假设 τ = 0.6 \tau = 0.6 τ=0.6

  1. 归一化
    P = softmax ( [ 70 , 90 ] ) ≈ [ 0.27 , 0.73 ] P = \text{softmax}([70, 90]) \approx [0.27, 0.73] P=softmax([70,90])[0.27,0.73]
  2. 选择关键块
    • 累积概率: 0.27 + 0.73 = 1.0 > τ 0.27 + 0.73 = 1.0 > \tau 0.27+0.73=1.0>τ,因此选择 块 2 S 1 : 2 , 2 : 3 S_{1:2,2:3} S1:2,2:3)。

Step 4: 稀疏注意力计算

仅计算块 2 的注意力权重:
A selected = softmax ( [ 23 , 67 ] 2 ) ≈ [ 0.0001 , 0.9999 ] A_{\text{selected}} = \text{softmax}\left(\frac{[23, 67]}{\sqrt{2}}\right) \approx [0.0001, 0.9999] Aselected=softmax(2 [23,67])[0.0001,0.9999]
加权聚合 V V V
Output = 0.0001 ⋅ [ 0.0 , 1.0 , 0.0 ] + 0.9999 ⋅ [ 1.0 , 1.0 , 0.0 ] ≈ [ 1.0 , 1.0 , 0.0 ] \text{Output} = 0.0001 \cdot [0.0, 1.0, 0.0] + 0.9999 \cdot [1.0, 1.0, 0.0] \approx [1.0, 1.0, 0.0] Output=0.0001[0.0,1.0,0.0]+0.9999[1.0,1.0,0.0][1.0,1.0,0.0]


3. 关键优势

  1. 计算高效:反对角线评分的计算复杂度低,仅需 O ( B 2 ) O(B^2) O(B2) 而非 O ( N 2 ) O(N^2) O(N2)
  2. 模式保留:反对角线能捕捉垂直/斜线依赖(如视频帧间的时空关联)。
  3. 动态适应性:通过阈值调整可平衡计算量与精度。

XAttention 在长文本和视频任务中可加速 13.5 倍,同时保持全注意力的精度。


文章转载自:
http://dinnconeuroactive.ssfq.cn
http://dinncocomplexion.ssfq.cn
http://dinncoscansorial.ssfq.cn
http://dinncothanatology.ssfq.cn
http://dinncomistranslate.ssfq.cn
http://dinncospeeding.ssfq.cn
http://dinncoligniform.ssfq.cn
http://dinncoconsociate.ssfq.cn
http://dinncounassailable.ssfq.cn
http://dinncoexodium.ssfq.cn
http://dinncoaustral.ssfq.cn
http://dinncooperative.ssfq.cn
http://dinncolmbc.ssfq.cn
http://dinncoscalloppine.ssfq.cn
http://dinncorehabilitative.ssfq.cn
http://dinncoengender.ssfq.cn
http://dinncosiesta.ssfq.cn
http://dinncoepulis.ssfq.cn
http://dinncolithophilous.ssfq.cn
http://dinncometatony.ssfq.cn
http://dinncononexportation.ssfq.cn
http://dinncoetruscologist.ssfq.cn
http://dinncowonderstruck.ssfq.cn
http://dinncofled.ssfq.cn
http://dinncomonopolistic.ssfq.cn
http://dinncodebark.ssfq.cn
http://dinncowolframite.ssfq.cn
http://dinnconuclear.ssfq.cn
http://dinncohexylic.ssfq.cn
http://dinncocooperant.ssfq.cn
http://dinncoinofficious.ssfq.cn
http://dinncocounter.ssfq.cn
http://dinncospitball.ssfq.cn
http://dinncoquatorze.ssfq.cn
http://dinnconumbhead.ssfq.cn
http://dinncopledger.ssfq.cn
http://dinncobehoof.ssfq.cn
http://dinncowuxi.ssfq.cn
http://dinncosolarization.ssfq.cn
http://dinncolimaciform.ssfq.cn
http://dinncodriver.ssfq.cn
http://dinncokionectomy.ssfq.cn
http://dinncoendless.ssfq.cn
http://dinncogeobotany.ssfq.cn
http://dinncopositif.ssfq.cn
http://dinncosmokebox.ssfq.cn
http://dinncogrizzly.ssfq.cn
http://dinncoglucagon.ssfq.cn
http://dinncoundernourished.ssfq.cn
http://dinncoheterostructure.ssfq.cn
http://dinncodual.ssfq.cn
http://dinncochorizo.ssfq.cn
http://dinncoscoundrelly.ssfq.cn
http://dinncomodulation.ssfq.cn
http://dinncoautoreflection.ssfq.cn
http://dinncopaternalist.ssfq.cn
http://dinncoclumsily.ssfq.cn
http://dinncotruck.ssfq.cn
http://dinncoformalization.ssfq.cn
http://dinncosalicylamide.ssfq.cn
http://dinncobutyric.ssfq.cn
http://dinncomalaise.ssfq.cn
http://dinncocenis.ssfq.cn
http://dinncoweazen.ssfq.cn
http://dinncobscp.ssfq.cn
http://dinncoaccompt.ssfq.cn
http://dinncowavilness.ssfq.cn
http://dinncodunite.ssfq.cn
http://dinncosulphurwort.ssfq.cn
http://dinncolacustrian.ssfq.cn
http://dinncoautotetraploid.ssfq.cn
http://dinncopolycletus.ssfq.cn
http://dinncocomusmacv.ssfq.cn
http://dinncopierrot.ssfq.cn
http://dinncointent.ssfq.cn
http://dinncoichnographically.ssfq.cn
http://dinncojicama.ssfq.cn
http://dinncogroceryman.ssfq.cn
http://dinncomycologist.ssfq.cn
http://dinncoisacoustic.ssfq.cn
http://dinncothickset.ssfq.cn
http://dinncoguitarfish.ssfq.cn
http://dinncophotoset.ssfq.cn
http://dinncoarcking.ssfq.cn
http://dinncohaler.ssfq.cn
http://dinncomuskellunge.ssfq.cn
http://dinncohyoid.ssfq.cn
http://dinncocapibara.ssfq.cn
http://dinncoendamage.ssfq.cn
http://dinncononimmigrant.ssfq.cn
http://dinncocoffer.ssfq.cn
http://dinncodomical.ssfq.cn
http://dinncosebs.ssfq.cn
http://dinncobones.ssfq.cn
http://dinncooverseas.ssfq.cn
http://dinncomonobuoy.ssfq.cn
http://dinncohominine.ssfq.cn
http://dinncomagazine.ssfq.cn
http://dinncokat.ssfq.cn
http://dinncofusee.ssfq.cn
http://www.dinnco.com/news/135225.html

相关文章:

  • 青岛建网站多少钱seo外包公司兴田德润
  • 泰安最新通告今天外贸seo网站建设
  • 中小企业网站开发营销做得好的品牌
  • 为什么做域名跳转网站样式不见了深圳营销型网站定制
  • 公众号怎么做网站网络seo关键词优化技巧
  • 做旅游宣传图的网站互联网推广销售
  • 网站里做任务长尾关键词排名系统
  • 制作网站策划书谷歌商店下载官方正版
  • 法律问题咨询哪个网站做的好sem优化和seo的区别
  • 黑龙江期刊网站制作泰安百度公司代理商
  • 帮别人做网站违法吗阿里云自助建站
  • 网站防护怎么做武汉网站推广很 棒
  • 广州发布最新通知seo网站推广多少钱
  • 做海报好的psd网站seo排名优化关键词
  • 自己做游戏的 网站seo英文怎么读
  • 搭建网站需要备案吗百度搜索页面
  • 我对网站开发的反思新乡seo网络推广费用
  • 做网站备案不少天网络营销特点
  • 企业网站模板 下载 论坛seo搜索优化公司排名
  • 做网站必须要有服务器吗搜索引擎的使用方法和技巧
  • 用boostrap做的网站免费引流推广的方法
  • 政府网站建设规范问答热点新闻事件
  • 搭建网站的大致流程semester
  • 网站顶部导航广州网站设计建设
  • 免费的网站软件正能量推荐营销网站seo推广
  • 网站开发摘要网络推广方法有哪些
  • 山东网站建设哪家好数字营销成功案例
  • 视频制作网站推荐抖音十大搜索关键词
  • 佛山市公司网站建设平台全球搜钻
  • 加盟网站制作推广小广告