Gated Local-Global Graph Attention
Implementation & benchmark of arXiv:2608.23414 — Graph-Native Attention Acceleration for Attack Detection in Cyber-Physical Systems
Source paper: Graph-Native Attention Acceleration for Attack Detection in Cyber-Physical Systems arXiv:2608.23414 ⓘ · analyzed Sep 1, 2026
AI-generated research hypothesis, automatically tested. Not peer-reviewed.
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.
Formulas
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$.
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
Stage 1 · Toy mechanism gate: Passed ✓
Stage 2 · Mechanism transferred to benchmark: Confirmed ✓
Stage 2 · Practical benchmark result: Significant win ✓
Methodology: 8 paired seeds, permutation test (p<0.05) against a learning-rate-tuned baseline. How verification works
Stage 1 — Mechanism check agent confidence 8/10
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.
- Agent confidence
- 8/10
- Baseline
- Dense attention: synthetic MSE 0.065324; latency N=64/128/256/512: 0.328/0.619/0.502/0.345 ms
- Idea
- Hybrid attention: synthetic MSE 0.0000226; latency N=64/128/256/512: 1.934/1.809/1.460/1.956 ms; operation-proxy ratio dense/hybrid grows 2.67x to 21.33x
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.
How to run: python3 run_experiment.py
Stage 2 — Benchmark vs. tuned baseline (arXiv:2608.23414)
Beats the tuned baseline by 7.6% (p=0.0147, wins 7 / 8 paired seeds; metric: lower is better).
- Benchmark
- Sequence modeling
- Model
- transformer_tiny
- Paired seeds
- 8
- Baseline mean
- 0.4032
- Idea mean
- 0.3726
- Effect (Δ)
- -0.0305 (−7.6%; negative = idea better)
- Wins
- 7 / 8 paired seeds
- p-value
- 0.0147 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±4.9%
- Mechanism
- Confirmed ✓
- Practical effect
- Helps
- Baseline tuning
- swept over 3 configs
Only the registered built-in sequence forecasting track was tested. Wall-clock latency, peak memory, general graph topologies, and larger datasets were not evaluated; the local branch used a fixed three-neighbor temporal pattern.
How to run: python3 stage2_bench.py
Verdict computed by deterministic test code from paired-seed statistics — not by the language model.
Stage 2 — Benchmark latest Worked ✓
Agent confidence: 8/10
The sequence track is structurally matched to the attention intervention. The gated local-global transformer achieved lower test MSE than the tuned dense transformer (0.372641 vs 0.403156), with 7/8 paired wins and permutation p=0.01475, satisfying the harness criterion for a significant win. The trained-model gate signature confirmed use of both local and global paths.
- Baseline
- Dense transformer_tiny, tuned lr=0.001, 8-seed mean MSE 0.403156, std 0.052733
- Delta mean
- -0.030515525490045547
- Idea
- Gated local-global transformer, lr=0.001, 8-seed mean MSE 0.372641, std 0.068380
- P value
- 0.01475
Benchmark result
Beats the tuned baseline by 7.6% (p=0.0147, wins 7 / 8 paired seeds; metric: lower is better).
- Benchmark
- Sequence modeling
- Model
- transformer_tiny
- Paired seeds
- 8
- Baseline mean
- 0.4032
- Idea mean
- 0.3726
- Effect (Δ)
- -0.0305 (−7.6%; negative = idea better)
- Wins
- 7 / 8 paired seeds
- p-value
- 0.0147 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±4.9%
- Mechanism
- Confirmed ✓
- Practical effect
- Helps
- Baseline tuning
- swept over 3 configs
Only the registered built-in sequence forecasting track was tested. Wall-clock latency, peak memory, general graph topologies, and larger datasets were not evaluated; the local branch used a fixed three-neighbor temporal pattern.
How to run: python3 stage2_bench.py
Artifacts
- bench_report.json 2.6 KB View Raw
- gated_attention.py 2.0 KB View Raw
- report.md 1.5 KB View
- report_bench_2026-09-03T000836.md 4.1 KB View
- results.json 1.0 KB View Raw
- run_experiment.py 5.5 KB View Raw
- stage2_bench.py 5.3 KB View Raw