# Gated Local-Global Graph Attention

- ID: 2699
- Canonical URL: https://synthcore.org/idea/2699/gated-local-global-graph-attention
- API JSON: https://synthcore.org/api/idea/2699.json
- API Markdown: https://synthcore.org/api/idea/2699.md
- Verification status: unverified
- Source: [arXiv:2608.23414](https://arxiv.org/abs/2608.23414)
- Category: architecture
- Solves: speedup, scalability, accuracy
- ML areas: graph-nn, attention, transformer, inference-speedup
- Math tags: linear-algebra, graph-theory, optimization
- Ratings: usefulness 7/10; difficulty 4/10; novelty 5/10

## Idea description

Replace dense graph self-attention with two parallel branches: exact softmax attention only over graph neighbors and a global linear-attention branch that summarizes all nodes through feature-space statistics. A learned node-wise gate interpolates between the branches, allowing locally structured nodes to use sparse attention while retaining a global-information path.

## Mathematical statement

Let $X\in\mathbb{R}^{N\times d}$ be node features, $A\in\{0,1\}^{N\times N}$ the fixed graph adjacency including self-loops, and $Q=XW_Q$, $K=XW_K$, $V=XW_V$ with $W_Q,W_K,W_V\in\mathbb{R}^{d\times r}$. The local branch computes masked softmax attention over neighbors, so its cost depends on the edge count $|E|$ rather than $N^2$. The global branch uses kernelized linear attention with a nonnegative feature map $\phi$. A node-wise gate $g_i$ combines the two outputs. The resulting computational cost is $O(|E|r+Nr^2)$ instead of dense attention cost $O(N^2r)$, assuming the feature dimension $r$ is smaller than $N$.

## Key formulas

- $$L_i=\sum_{j:A_{ij}=1}\frac{\exp(q_i k_j^\top/\sqrt r)}{\sum_{\ell:A_{i\ell}=1}\exp(q_i k_\ell^\top/\sqrt r)}v_j,\qquad q_i=x_iW_Q,\quad k_j=x_jW_K,\quad v_j=x_jW_V.$$
- $$G_i=\frac{\phi(q_i)^\top S}{\phi(q_i)^\top z+\epsilon},\qquad S=\sum_{j=1}^{N}\phi(k_j)v_j^\top,\qquad z=\sum_{j=1}^{N}\phi(k_j),$$
- $$g_i=\sigma(x_iw_g+b_g),\qquad Y_i=g_iL_i+(1-g_i)G_i.$$
- $$T_{\mathrm{hybrid}}=O(|E|r+Nr^2),\qquad T_{\mathrm{dense}}=O(N^2r),\qquad \mathrm{speedup}\approx\frac{N^2r}{|E|r+Nr^2}.$$

## Implementation notes

1. Integration point: implement this as a replacement for dense self-attention in a graph transformer or spatiotemporal graph model. Inputs are node states `X [batch,N,d]` and a sparse adjacency list or mask `A`; retain the usual residual connection, normalization, multi-head splitting, and feed-forward block. 2. Pseudocode: compute `Q,K,V`; for each head, gather only edge pairs `(i,j)` and apply segmented softmax to obtain `L`; compute `PhiQ=elu(Q)+1` and `PhiK=elu(K)+1`; accumulate `S=sum_j outer(PhiK[j],V[j])` and `z=sum_j PhiK[j]`; form `G=(PhiQ @ S)/(PhiQ @ z + eps)`; compute `g=sigmoid(linear(X))`; return `LayerNorm(X + Wo(g*L+(1-g)*G))`. Use sparse GPU kernels or packed edge lists rather than materializing an $N\times N$ mask. 3. Computed directly from the mechanism: the adjacency-constrained local attention, global linear statistics, and node-wise gate. Estimated empirically: the best kernel map, gate regularization, sparse-kernel overhead, and accuracy loss. 4. First cheap experiment: compare this layer against dense graph attention on Cora or ogbn-arxiv, plus a synthetic task whose labels depend separately on one-hop and global graph statistics. Sweep $N$ and average degree while matching hidden width and parameter count. Measure wall-clock latency, peak memory, accuracy, and gate values. The predicted signature is quadratic dense runtime versus approximately $|E|r+Nr^2$ hybrid runtime; for bounded-degree graphs, runtime should become approximately linear in $N$. Once sparse-kernel overhead is amortized, the hybrid should achieve at least a 2x speedup, while retaining accuracy within 1-2 percentage points. On the synthetic mixed task, local-only nodes should have $g_i$ near one and global-only nodes should have $g_i$ near zero.

## Verification

- Status: unverified
- Mechanism evidence: yes
- Mechanism confirmed: no
- Verdict: Built a PyTorch gated local-global attention MVP with edge-list local softmax, ELU+1 linear attention, and a learned node gate. The mathematical checks confirmed masked local attention and linear-kernel reassociation to below 2.4e-7 error, while the operation proxy ratio grew from 2.67x at N=64 to 21.33x at N=512 with observed log-log slope 1.00, matching the predicted linear-in-N scaling for fixed degree. The hybrid reached lower synthetic mixed-task MSE than the dense baseline (2.26e-5 vs 6.53e-2), but it was slower in this small unoptimized implementation at every tested size, so the speedup claim was not observed.

### Mechanism check

- Verdict: Built a PyTorch gated local-global attention MVP with edge-list local softmax, ELU+1 linear attention, and a learned node gate. The mathematical checks confirmed masked local attention and linear-kernel reassociation to below 2.4e-7 error, while the operation proxy ratio grew from 2.67x at N=64 to 21.33x at N=512 with observed log-log slope 1.00, matching the predicted linear-in-N scaling for fixed degree. The hybrid reached lower synthetic mixed-task MSE than the dense baseline (2.26e-5 vs 6.53e-2), but it was slower in this small unoptimized implementation at every tested size, so the speedup claim was not observed.
- Confidence: 8/10
- Limitations: Only a single-head toy synthetic task was tested; no Cora, ogbn-arxiv, multi-head transformer block, validation split, gate-value specialization analysis, backward-pass benchmark, memory measurement, or optimized sparse GPU kernel was included. Timing was dominated by Python/PyTorch edge-list overhead and does not validate production-scale speedups.

## Artifacts

- [gated_attention.py](https://synthcore.org/code/1041/gated_attention.py)
- [report.md](https://synthcore.org/code/1041/report.md)
- [results.json](https://synthcore.org/code/1041/results.json)
- [run_experiment.py](https://synthcore.org/code/1041/run_experiment.py)
- [stage2_bench.py](https://synthcore.org/code/1041/stage2_bench.py)
- [Download all files as ZIP](https://synthcore.org/download/1041)

## Disclaimer

AI-generated research hypothesis, automatically tested. Not peer-reviewed.
