TL;DR
torch-harmonics is an open-source PyTorch library that provides efficient, differentiable signal processing and machine learning operations for data defined on a sphere. By combining custom CUDA kernels with distributed computing strategies, it enables researchers to build scalable, rotationally-aware models for complex domains like global weather forecasting and molecular simulations.
What Problem Does This Paper Address?
Many critical scientific fields—from geophysics and climate science to quantum chemistry—deal with data that lives on a sphere ($S^2$). However, standard deep learning tools are designed for flat, Euclidean grids. If you try to "unwrap" a sphere into a flat rectangle (like a world map), you introduce distortions and singularities at the poles, which breaks the underlying physical symmetries and leads to poor model performance.
While "Geometric Deep Learning" offers theoretical solutions like spherical CNNs, these have historically been difficult to adopt because they are computationally expensive and lack efficient, scalable implementations. torch-harmonics bridges this gap by providing a high-performance, differentiable toolkit that respects spherical topology without sacrificing speed or memory efficiency.
Methods
The library implements several core operations designed to handle the unique geometry of the sphere:
- Spherical Harmonic Transform (SHT): The spherical equivalent of the Fourier Transform. It decomposes signals into spherical harmonic basis functions, allowing for efficient global operations in the spectral domain.
- Discrete-Continuous (DISCO) Convolutions: Unlike spectral convolutions which are global and isotropic (uniform in all directions), DISCO convolutions allow for local, anisotropic (direction-dependent) filters. This is crucial for modeling features like atmospheric boundary layers or topographic effects.
- Spherical Attention: The library generalizes Vision Transformers to the sphere using continuous attention formulations. It uses quadrature weights to account for the fact that grid points on a sphere (like latitude-longitude grids) are more densely packed near the poles.
- Performance Optimizations:
- Custom CUDA Kernels: For operations like DISCO and neighborhood attention, the authors wrote specialized CUDA kernels to maximize memory bandwidth.
- Memory Layouts: They use "stride-1" contraction indices to ensure that the heavy matrix multiplications required for spherical transforms are as fast as possible on modern GPUs.
- Distributed Computing: The library supports "pencil decomposition" to split large spherical signals across multiple GPUs, enabling the processing of ultra-high-resolution data.
Datasets
As a library paper, the focus is on the toolkit rather than a specific new dataset. However, the authors demonstrate the library's utility across several benchmarks and real-world applications:
- Shallow Water Equations: A standard PDE benchmark for atmospheric dynamics.
- 360° Images: Used for depth estimation and segmentation tasks, comparing spherical transformers against Euclidean baselines.
- Weather/Climate Data: The library powers models like FourCastNet, which are trained on massive global atmospheric datasets (e.g., ERA5).
- Molecular Force Fields: Used for simulating molecular interactions.
Key Insights and Ideas
- Differentiability is Key: By making every operation differentiable via PyTorch's autograd, the library allows for "Hybrid Physics-ML" architectures. For example, you can embed a differentiable PDE solver directly into a neural network training loop.
- Handling Irregularity: Spherical neighborhoods in a grid have highly irregular counts of neighbors. The authors found that presorting these neighborhoods by size before processing them on the GPU (load balancing) improved runtime by up to 20%.
- Permutation Bottlenecks: In attention mechanisms, switching between "channel-first" and "channel-last" memory layouts is often a hidden bottleneck. By writing a custom specialized transpose kernel, they achieved 6.2 TB/s throughput—an order of magnitude faster than standard PyTorch operators.
Key Results
- Scalability: The library enables training high-resolution models (like the Spherical Fourier Neural Operator) that were previously computationally prohibitive.
- Numerical Precision: The distributed SHT implementation is designed to be bit-wise identical to the serial version, ensuring that scaling up to more GPUs doesn't introduce numerical drift.
- Efficiency: The specialized permutation kernels achieved a massive jump from 0.5 TB/s to 6.2 TB/s on NVIDIA GB200 hardware, making the cost of layout changes negligible.
Limitations and Future Work
- Grid Support: Currently, the library primarily supports equiangular, Legendre-Gauss, and Gauss-Lobatto grids. While these cover most geoscientific use cases, support for other popular spherical grids (like HEALPix or Cubed-Sphere) is still in the planning stages.
- Complexity: While the library is high-level, building custom spherical architectures still requires a solid understanding of spectral methods and spherical geometry, which may have a steeper learning curve than standard 2D CNNs.
- Future Directions: The authors suggest further integration with neural General Circulation Models (GCMs) and expanding the library's reach into robotics and omnidirectional 3D vision.
Summary updated