Attention on the Sphere

Boris Bonev, Max Rietmann, Andrea Paris, Alberto Carpentieri, Thorsten Kurth · DOI

Abstract

Standard Transformer architectures are designed for Euclidean data, such as 2D images or linear text sequences. When applied to spherical domains—including 360° panoramic video, planetary weather patterns, or cosmological maps—these models suffer from geometric distortions and a lack of rotational equivariance. We present a generalized spherical attention mechanism that integrates numerical quadrature weights and geodesic distances directly into the Transformer framework. By treating tokens as points on a continuous $S^2$ surface rather than a flat grid, this approach significantly reduces artifacts at the poles and improves performance across computer vision and geophysical fluid dynamics benchmarks.

Introduction

Most deep learning models are built on the assumption of a "flat" world. However, many of the most critical datasets in science and robotics are inherently spherical. Atmospheric weather patterns, for instance, exist on a globe where the geometry is non-Euclidean. When researchers attempt to process this data using standard Transformers, they typically project the sphere onto a flat map, such as an equirectangular projection.

This projection introduces massive distortions; for example, pixels near the poles represent significantly less surface area than those at the equator. Standard Transformers are "blind" to this variation, treating every token identically regardless of its geometric context. This leads to a lack of rotational equivariance—where the model's perception of a feature changes simply because it has been rotated—and introduces physical inconsistencies in long-term simulations.

Methodology

To address these limitations, we propose a "geometrically faithful" spherical attention mechanism. This method shifts the paradigm from treating tokens as a discrete list to treating them as points on a continuous surface ($S^2$).

1. Quadrature-Weighted Attention

The primary innovation is the integration of numerical quadrature weights ($\omega_i$) into the attention mechanism. Because pixels near the poles represent less physical area, the model weights their contribution to the attention sum accordingly. This ensures that the attention mechanism approximates a continuous integral over the sphere, allowing the model to maintain consistency across different regions of the globe and achieving approximate rotational equivariance.

2. Spherical Neighborhood Attention (SNA)

Global attention scales quadratically ($O(N^2)$), which is computationally prohibitive for high-resolution spherical data. To mitigate this, we developed a local variant called Spherical Neighborhood Attention. Unlike standard local attention, which uses a flat grid square, SNA defines a "geodesic neighborhood"—a circular disk on the sphere's surface determined by the true Haversine distance. This ensures that the local receptive field remains geometrically consistent regardless of latitude.

3. Neural Operators and Resolution Independence

Because the formulation is grounded in continuous integrals, these models function as neural operators. This theoretical foundation allows a model trained at one grid resolution to be evaluated at a different resolution without losing its geometric integrity, a crucial feature for multi-scale climate modeling.

4. Optimized Implementation

Standard deep learning libraries are not optimized for non-uniform spherical neighborhoods. To make this approach practical, the team developed custom CUDA kernels designed to handle geodesic neighborhood calculations efficiently, ensuring the model is fast enough for real-world applications.

Experimental Results

The Spherical Transformer was evaluated against standard Euclidean models across three distinct domains:

Climate Simulation

In the Shallow Water Equations (SWE) benchmark—a proxy for atmospheric and oceanic modeling—the improvement was stark. The local Spherical Transformer achieved a validation loss of 0.007, nearly an order of magnitude better than the standard local Transformer's 0.058. This suggests that respecting spherical geometry is essential for accurate geophysical simulations.

Semantic Segmentation and Depth Estimation

Using the Stanford 2D3DS dataset (indoor 360° RGB images), the $S^2$ SegFormer achieved an Intersection-over-Union (IoU) of 0.645, surpassing the Euclidean version's 0.623. Qualitative analysis showed that while standard models produced "smeary" or distorted predictions near the poles, the spherical model maintained sharp, accurate features across the entire field of view.

Discussion and Future Work

While the Spherical Transformer sets a new bar for geometric intelligence, several challenges remain. Currently, custom CUDA kernels for neighborhood attention are slower than the highly optimized standard kernels (like FlashAttention) found in modern frameworks. Furthermore, the implementation does not yet fully exploit hardware-specific features like Tensor Cores to the same degree as Euclidean models.

Future research will focus on improving the long-term stability of these models in auto-regressive rollouts for weather forecasting and optimizing the kernels for better hardware acceleration. By bridging the gap between geometric theory and Transformer efficiency, we move closer to models that truly understand the curved nature of our world.

Summary updated

BibTeX
@inproceedings{bonev2025attention,
  author = {Boris Bonev and Max Rietmann and Andrea Paris and Alberto Carpentieri and Thorsten Kurth},
  title = {{Attention on the Sphere}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=UCloKhbOvP},
}
Figure