torch-harmonics-cu129 0.9.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
The code was authored by the following people:
|
|
2
|
+
|
|
3
|
+
Boris Bonev - NVIDIA Corporation
|
|
4
|
+
Thorsten Kurth - NVIDIA Corporation
|
|
5
|
+
Max Rietmann - NVIDIA Corporation
|
|
6
|
+
Mauro Bisson - NVIDIA Corporation
|
|
7
|
+
Andrea Paris - NVIDIA Corporation
|
|
8
|
+
Alberto Carpentieri - NVIDIA Corporation
|
|
9
|
+
Massimiliano Fatica - NVIDIA Corporation
|
|
10
|
+
Jean Kossaifi - NVIDIA Corporation
|
|
11
|
+
Nikola Kovachki - NVIDIA Corporation
|
|
12
|
+
Christian Hundt - NVIDIA Corporation
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: torch-harmonics-cu129
|
|
3
|
+
Version: 0.9.2
|
|
4
|
+
Summary: Differentiable signal processing on the sphere for PyTorch.
|
|
5
|
+
Author: Boris Bonev, Thorsten Kurth, Max Rietmann, Mauro Bisson, Andrea Paris, Alberto Carpentieri, Massimiliano Fatica, Jean Kossaifi, Nikola Kovachki, Christian Hundt
|
|
6
|
+
Maintainer-email: Boris Bonev <bbonev@nvidia.com>, Thorsten Kurth <tkurth@nvidia.com>
|
|
7
|
+
License: SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved.
|
|
8
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
12
|
+
list of conditions and the following disclaimer.
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE.txt
|
|
35
|
+
License-File: AUTHORS
|
|
36
|
+
Requires-Dist: torch>=2.8.0,<2.9.0
|
|
37
|
+
Requires-Dist: numpy>=1.22.4
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: coverage>=6.5.0; extra == "dev"
|
|
42
|
+
Requires-Dist: parameterized; extra == "dev"
|
|
43
|
+
Requires-Dist: scipy>=1.9.0; extra == "dev"
|
|
44
|
+
Requires-Dist: pre-commit>=4.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: black>=24.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
47
|
+
Provides-Extra: filter-basis
|
|
48
|
+
Requires-Dist: scipy>=1.9.0; extra == "filter-basis"
|
|
49
|
+
Provides-Extra: docs
|
|
50
|
+
Requires-Dist: sphinx>=7.1; extra == "docs"
|
|
51
|
+
Requires-Dist: nvidia-sphinx-theme>=0.0.9; extra == "docs"
|
|
52
|
+
Requires-Dist: myst-nb>=1.0; extra == "docs"
|
|
53
|
+
Requires-Dist: sphinx-copybutton>=0.5; extra == "docs"
|
|
54
|
+
Requires-Dist: sphinxcontrib-bibtex>=2.6; extra == "docs"
|
|
55
|
+
Provides-Extra: 2d3ds
|
|
56
|
+
Requires-Dist: requests; extra == "2d3ds"
|
|
57
|
+
Requires-Dist: tqdm; extra == "2d3ds"
|
|
58
|
+
Requires-Dist: pillow; extra == "2d3ds"
|
|
59
|
+
Requires-Dist: h5py; extra == "2d3ds"
|
|
60
|
+
Dynamic: license-file
|
|
61
|
+
|
|
62
|
+
<!--
|
|
63
|
+
SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved.
|
|
64
|
+
|
|
65
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
66
|
+
|
|
67
|
+
Redistribution and use in source and binary forms, with or without
|
|
68
|
+
modification, are permitted provided that the following conditions are met:
|
|
69
|
+
|
|
70
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
71
|
+
list of conditions and the following disclaimer.
|
|
72
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
73
|
+
this list of conditions and the following disclaimer in the documentation
|
|
74
|
+
and/or other materials provided with the distribution.
|
|
75
|
+
|
|
76
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
77
|
+
contributors may be used to endorse or promote products derived from
|
|
78
|
+
this software without specific prior written permission.
|
|
79
|
+
|
|
80
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
81
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
82
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
83
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
84
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
85
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
86
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
87
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
88
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
89
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
90
|
+
-->
|
|
91
|
+
|
|
92
|
+
<!-- <div align="center">
|
|
93
|
+
<img src="https://raw.githubusercontent.com/NVIDIA/torch-harmonics/main/images/logo/logo.png" width="568">
|
|
94
|
+
<br>
|
|
95
|
+
<a href="https://github.com/NVIDIA/torch-harmonics/actions/workflows/tests.yml"><img src="https://github.com/NVIDIA/torch-harmonics/actions/workflows/tests.yml/badge.svg"></a>
|
|
96
|
+
<a href="https://pypi.org/project/torch_harmonics/"><img src="https://img.shields.io/pypi/v/torch_harmonics"></a>
|
|
97
|
+
</div> -->
|
|
98
|
+
|
|
99
|
+
<!--
|
|
100
|
+
[](https://pypi.org/project/torch_harmonics/)
|
|
101
|
+
-->
|
|
102
|
+
|
|
103
|
+
<!-- # spherical harmonic transforms -->
|
|
104
|
+
|
|
105
|
+
# torch-harmonics
|
|
106
|
+
|
|
107
|
+
[**Overview**](#overview) | [**Installation**](#installation) | [**More information**](#more-about-torch-harmonics) | [**Getting started**](#getting-started) | [**Contributors**](#contributors) | [**Cite us**](#cite-us) | [**References**](#references)
|
|
108
|
+
|
|
109
|
+
[](https://github.com/NVIDIA/torch-harmonics/actions/workflows/tests.yml)
|
|
110
|
+
[](https://github.com/NVIDIA/torch-harmonics/actions/workflows/tests.yml)
|
|
111
|
+
[](https://pypi.org/project/torch_harmonics/)
|
|
112
|
+
|
|
113
|
+
## Overview
|
|
114
|
+
|
|
115
|
+
torch-harmonics implements differentiable signal processing on the sphere. This includes differentiable implementations of the spherical harmonic transforms, vector spherical harmonic transforms and discrete-continuous convolutions on the sphere. The package was originally implemented to enable Spherical Fourier Neural Operators (SFNO) [1].
|
|
116
|
+
|
|
117
|
+
The SHT algorithm uses quadrature rules to compute the projection onto the associated Legendre polynomials and FFTs for the projection onto the harmonic basis. This algorithm tends to outperform others with better asymptotic scaling for most practical purposes [2].
|
|
118
|
+
|
|
119
|
+
torch-harmonics uses PyTorch primitives to implement these operations, making it fully differentiable. Moreover, the quadrature can be distributed onto multiple ranks making it spatially distributed.
|
|
120
|
+
|
|
121
|
+
torch-harmonics has been used to implement a variety of differentiable PDE solvers which generated the animations below. Moreover, it has enabled the development of Spherical Fourier Neural Operators [1].
|
|
122
|
+
|
|
123
|
+
<div align="center">
|
|
124
|
+
<table border="0" cellspacing="0" cellpadding="0">
|
|
125
|
+
<tr>
|
|
126
|
+
<td><img src="https://media.githubusercontent.com/media/NVIDIA/torch-harmonics/main/images/sfno.gif" width="240"></td>
|
|
127
|
+
<td><img src="https://media.githubusercontent.com/media/NVIDIA/torch-harmonics/main/images/zonal_jet.gif" width="240"></td>
|
|
128
|
+
<td><img src="https://media.githubusercontent.com/media/NVIDIA/torch-harmonics/main/images/allen-cahn.gif" width="240"></td>
|
|
129
|
+
</tr>
|
|
130
|
+
<!-- <tr>
|
|
131
|
+
<td style="text-align:center; border-style : hidden!important;">Shallow Water Eqns.</td>
|
|
132
|
+
<td style="text-align:center; border-style : hidden!important;">Ginzburg-Landau Eqn.</td>
|
|
133
|
+
<td style="text-align:center; border-style : hidden!important;">Allen-Cahn Eqn.</td>
|
|
134
|
+
</tr> -->
|
|
135
|
+
</table>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Installation
|
|
140
|
+
|
|
141
|
+
### Prebuilt wheels
|
|
142
|
+
|
|
143
|
+
Prebuilt Linux wheels with compiled CUDA extensions are available on [pypi.nvidia.com](https://pypi.nvidia.com). Pick the package matching your CUDA toolkit version:
|
|
144
|
+
|
|
145
|
+
| CUDA | Package | Supported PyTorch | Install command |
|
|
146
|
+
|------|---------|-------------------|-----------------|
|
|
147
|
+
| 12.6 | `torch-harmonics-cu126` | 2.6.0 | `pip install torch-harmonics-cu126 --extra-index-url https://pypi.nvidia.com` |
|
|
148
|
+
| 12.8 | `torch-harmonics-cu128` | 2.7.0 | `pip install torch-harmonics-cu128 --extra-index-url https://pypi.nvidia.com` |
|
|
149
|
+
| 12.9 | `torch-harmonics-cu129` | 2.8.0 | `pip install torch-harmonics-cu129 --extra-index-url https://pypi.nvidia.com` |
|
|
150
|
+
| 13.0 | `torch-harmonics-cu130` | 2.9.1 | `pip install torch-harmonics-cu130 --extra-index-url https://pypi.nvidia.com` |
|
|
151
|
+
|
|
152
|
+
If you don't need a specific CUDA version, use one of the rolling aliases:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# latest CUDA build
|
|
156
|
+
pip install torch-harmonics-cuda-latest --extra-index-url https://pypi.nvidia.com
|
|
157
|
+
|
|
158
|
+
# CPU only
|
|
159
|
+
pip install torch-harmonics-cpu-latest --extra-index-url https://pypi.nvidia.com
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
> **Tip:** Run `nvidia-smi` to check your driver's CUDA version.
|
|
163
|
+
|
|
164
|
+
### PyPI
|
|
165
|
+
|
|
166
|
+
The vanilla `torch-harmonics` package on [PyPI](https://pypi.org/project/torch_harmonics/) ships a CPU-only prebuilt wheel. This version is built for the newest PyTorch release. For GPU support, use the NVIDIA PyPI packages above.
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
pip install torch-harmonics
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Building from source
|
|
173
|
+
|
|
174
|
+
If your OS, PyTorch or CUDA toolkit version is not covered by the available wheels, we recomment building torch-harmonics from the GitHub repository. Use `--no-build-isolation` so that custom CPU and CUDA kernels compile against your existing torch installation:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
git clone git@github.com:NVIDIA/torch-harmonics.git
|
|
178
|
+
cd torch-harmonics
|
|
179
|
+
pip install --no-build-isolation -e .
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
If CUDA devices are not detected automatically (e.g. inside a container), set the `TORCH_HARMONICS_BUILD_CUDA_EXTENSION` flag. Set `TORCH_CUDA_ARCH_LIST` to only the architectures you need to reduce compilation time:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
export TORCH_HARMONICS_BUILD_CUDA_EXTENSION=1
|
|
186
|
+
export TORCH_CUDA_ARCH_LIST="8.0 8.6 9.0a 10.0a+PTX"
|
|
187
|
+
pip install --no-build-isolation -e .
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
> **Tip:** Use the `a` suffix (e.g. `9.0a`, `10.0a`) instead of plain `9.0` or `10.0` to enable architecture-specific tensor core instructions (e.g. `wgmma` on Hopper). Some layers such as DISCO benefit significantly from this. The trade-off is that the resulting binary is only compatible with the exact GPU generation it was compiled for.
|
|
191
|
+
|
|
192
|
+
:warning: Custom CUDA extensions require architectures >= 7.0.
|
|
193
|
+
|
|
194
|
+
Alternatively, build a Docker container:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
git clone git@github.com:NVIDIA/torch-harmonics.git
|
|
198
|
+
cd torch-harmonics
|
|
199
|
+
docker build . -t torch_harmonics
|
|
200
|
+
docker run --gpus all -it --rm --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 torch_harmonics
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## More about torch-harmonics
|
|
204
|
+
|
|
205
|
+
### Spherical harmonics
|
|
206
|
+
|
|
207
|
+
The [spherical harmonics](https://en.wikipedia.org/wiki/Spherical_harmonics) are special functions defined on the two-dimensional sphere $S^2$ (embedded in three dimensions). They form an orthonormal basis of the space of square-integrable functions defined on the sphere $L^2(S^2)$ and are comparable to the harmonic functions defined on a circle/torus. The spherical harmonics are defined as
|
|
208
|
+
|
|
209
|
+
$$
|
|
210
|
+
Y_l^m(\theta, \lambda) = \sqrt{\frac{(2l + 1)}{4 \pi} \frac{(l - m)!}{(l + m)!}} P_l^m(\cos \theta) \exp(im\lambda),
|
|
211
|
+
$$
|
|
212
|
+
|
|
213
|
+
where $\theta$ and $\lambda$ are colatitude and longitude respectively, and $P_l^m$ the normalized, [associated Legendre polynomials](https://en.wikipedia.org/wiki/Associated_Legendre_polynomials).
|
|
214
|
+
|
|
215
|
+
<div align="center">
|
|
216
|
+
<img src="https://media.githubusercontent.com/media/NVIDIA/torch-harmonics/main/images/spherical_harmonics.gif" width="432">
|
|
217
|
+
<br>
|
|
218
|
+
Spherical harmonics up to degree 5
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
### Spherical harmonic transform
|
|
222
|
+
|
|
223
|
+
The spherical harmonic transform (SHT)
|
|
224
|
+
|
|
225
|
+
$$
|
|
226
|
+
f_l^m = \int_{S^2} \overline{Y_{l}^{m}}(\theta, \lambda) f(\theta, \lambda) \mathrm{d} \mu(\theta, \lambda)
|
|
227
|
+
$$
|
|
228
|
+
|
|
229
|
+
realizes the projection of a signal $f(\theta, \lambda)$ on $S^2$ onto the spherical harmonics basis. The SHT generalizes the Fourier transform on the sphere. Conversely, a truncated series expansion of a function $f$ can be written in terms of spherical harmonics as
|
|
230
|
+
|
|
231
|
+
$$
|
|
232
|
+
f (\theta, \lambda) = \sum_{m=-M}^{M} \exp(im\lambda) \sum_{l=|m|}^{M} \hat f_l^m P_l^m (\cos \theta),
|
|
233
|
+
$$
|
|
234
|
+
|
|
235
|
+
where $\hat{f}_l^m$, are the expansion coefficients associated to the mode $m$, $n$.
|
|
236
|
+
|
|
237
|
+
The implementation of the SHT follows the algorithm as presented in [2]. A direct spherical harmonic transform can be accomplished by a Fourier transform
|
|
238
|
+
|
|
239
|
+
$$
|
|
240
|
+
\hat f^m(\theta) = \frac{1}{2 \pi} \int_{0}^{2\pi} f(\theta, \lambda) \exp(-im\lambda) \mathrm{d} \lambda
|
|
241
|
+
$$
|
|
242
|
+
|
|
243
|
+
in longitude and a Legendre transform
|
|
244
|
+
|
|
245
|
+
$$
|
|
246
|
+
\hat f_l^m = \frac{1}{2} \int^{\pi}_0 \hat f^{m} (\theta) P_l^m (\cos \theta) \sin \theta \mathrm{d} \theta
|
|
247
|
+
$$
|
|
248
|
+
|
|
249
|
+
in latitude.
|
|
250
|
+
|
|
251
|
+
### Discrete Legendre transform
|
|
252
|
+
|
|
253
|
+
The second integral, which computed the projection onto the Legendre polynomials is realized with quadrature. On the Gaussian grid, we use Gaussian quadrature in the $\cos \theta$ domain. The integral
|
|
254
|
+
|
|
255
|
+
$$
|
|
256
|
+
\hat f_l^m = \frac{1}{2} \int_{-1}^1 \hat{f}^m(\arccos x) P_l^m (x) \mathrm{d} x
|
|
257
|
+
$$
|
|
258
|
+
|
|
259
|
+
is obtained with the substitution $x = \cos \theta$ and then approximated by the sum
|
|
260
|
+
|
|
261
|
+
$$
|
|
262
|
+
\hat f_l^m = \sum_{j=1}^{N_\theta} \hat{f}^m(\arccos x_j) P_l^m(x_j) w_j.
|
|
263
|
+
$$
|
|
264
|
+
|
|
265
|
+
Here, $x_j \in [-1,1]$ are the quadrature nodes with the respective quadrature weights $w_j$.
|
|
266
|
+
|
|
267
|
+
### Discrete-continuous convolutions on the sphere
|
|
268
|
+
|
|
269
|
+
torch-harmonics now provides local discrete-continuous (DISCO) convolutions as outlined in [5] on the sphere. These are use in local neural operators [2] to generalize convolutions to structured and unstructured meshes on the sphere.
|
|
270
|
+
|
|
271
|
+
### Spherical (neighborhood) attention
|
|
272
|
+
|
|
273
|
+
torch-harmonics introduces spherical attention mechanisms which correctly generalize the attention mechanism to the sphere. The use of quadrature rules makes the resulting operations approximately equivariant and equivariant in the continuous limit. Moreover, neighborhood attention is correctly generalized onto the sphere by using the geodesic distance to determine the size of the neighborhood.
|
|
274
|
+
|
|
275
|
+
## Getting started
|
|
276
|
+
|
|
277
|
+
The main functionality of `torch_harmonics` is provided in the form of `torch.nn.Modules` for composability. A minimum example is given by:
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
import torch
|
|
281
|
+
import torch_harmonics as th
|
|
282
|
+
|
|
283
|
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
284
|
+
|
|
285
|
+
nlat = 512
|
|
286
|
+
nlon = 2*nlat
|
|
287
|
+
batch_size = 32
|
|
288
|
+
signal = torch.randn(batch_size, nlat, nlon, device=device)
|
|
289
|
+
|
|
290
|
+
# transform data on an equiangular grid
|
|
291
|
+
sht = th.RealSHT(nlat, nlon, grid="equiangular").to(device)
|
|
292
|
+
|
|
293
|
+
coeffs = sht(signal)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
To enable scalable model-parallelism, `torch-harmonics` implements a distributed variant of the SHT located in `torch_harmonics.distributed`.
|
|
297
|
+
|
|
298
|
+
Detailed usage of torch-harmonics, alongside helpful analysis provided in a series of notebooks:
|
|
299
|
+
|
|
300
|
+
1. [Getting started](./notebooks/getting_started.ipynb)
|
|
301
|
+
2. [Quadrature](./notebooks/quadrature.ipynb)
|
|
302
|
+
3. [Visualizing the spherical harmonics](./notebooks/plot_spherical_harmonics.ipynb)
|
|
303
|
+
4. [Spectral fitting vs. SHT](./notebooks/gradient_analysis.ipynb)
|
|
304
|
+
5. [Conditioning of the Gramian](./notebooks/conditioning_sht.ipynb)
|
|
305
|
+
6. [Solving the Helmholtz equation](./notebooks/helmholtz.ipynb)
|
|
306
|
+
7. [Solving the shallow water equations](./notebooks/shallow_water_equations.ipynb)
|
|
307
|
+
8. [Training Spherical Fourier Neural Operators (SFNO)](./notebooks/train_spherical_neural_operator.ipynb)
|
|
308
|
+
9. [Resampling signals on the sphere](./notebooks/resample_sphere.ipynb)
|
|
309
|
+
10. [Computing partial derivatives with the SHT](./notebooks/partial_derivatives.ipynb)
|
|
310
|
+
|
|
311
|
+
## Benchmarks
|
|
312
|
+
|
|
313
|
+
The `benchmarks/` directory contains a performance benchmark suite covering SHT, DISCO
|
|
314
|
+
convolution, and spherical attention across resolutions, dtypes, and channel counts.
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# run full suite on current GPU
|
|
318
|
+
python benchmarks/run.py
|
|
319
|
+
|
|
320
|
+
# filter by name or tag
|
|
321
|
+
python benchmarks/run.py --name disco
|
|
322
|
+
python benchmarks/run.py --tags attention neighborhood
|
|
323
|
+
|
|
324
|
+
# save a baseline, then compare after a change
|
|
325
|
+
python benchmarks/run.py --save-csv before.csv
|
|
326
|
+
python benchmarks/run.py --reference-csv before.csv
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md#running-benchmarks) for the full workflow expected
|
|
330
|
+
in performance-related PRs.
|
|
331
|
+
|
|
332
|
+
## Examples and reproducibility
|
|
333
|
+
|
|
334
|
+
The `examples` folder contains training scripts for three distinct tasks:
|
|
335
|
+
|
|
336
|
+
* [solution of the shallow water equations on the rotating sphere](./examples/shallow_water_equations/train.py)
|
|
337
|
+
* [depth estimation on the sphere](./examples/depth/train.py)
|
|
338
|
+
* [semantic segmentation on the sphere](./examples/segmentation/train.py)
|
|
339
|
+
|
|
340
|
+
Results from the papers can generally be reproduced by running `python train.py`. In the case of some older results the number of epochs and learning-rate may need to be adjusted by passing the corresponding command line argument.
|
|
341
|
+
|
|
342
|
+
## Remarks on automatic mixed precision (AMP) support
|
|
343
|
+
|
|
344
|
+
Note that torch-harmonics uses Fourier transforms from `torch.fft` which in turn uses kernels from the optimized `cuFFT` library. This library supports fourier transforms of `float32` and `float64` (i.e. `single` and `double` precision) tensors for all input sizes. For `float16` (i.e. `half` precision) and `bfloat16` inputs however, the dimensions which are transformed are restricted to powers of two. Since data is converted to one of these reduced precision floating point formats when `torch.autocast` is used, torch-harmonics will issue an error when the input shapes are not powers of two. For these cases, we recommend disabling autocast for the harmonics transform specifically:
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
import torch
|
|
348
|
+
import torch_harmonics as th
|
|
349
|
+
|
|
350
|
+
sht = th.RealSHT(512, 1024, grid="equiangular").cuda()
|
|
351
|
+
|
|
352
|
+
with torch.autocast(device_type="cuda", enabled = True):
|
|
353
|
+
# do some AMP converted math here
|
|
354
|
+
x = some_math(x)
|
|
355
|
+
# convert tensor to float32
|
|
356
|
+
x = x.to(torch.float32)
|
|
357
|
+
# now disable autocast specifically for the transform,
|
|
358
|
+
# making sure that the tensors are not converted
|
|
359
|
+
# back to reduced precision internally
|
|
360
|
+
with torch.autocast(device_type="cuda", enabled = False):
|
|
361
|
+
xt = sht(x)
|
|
362
|
+
|
|
363
|
+
# continue operating on the transformed tensor
|
|
364
|
+
xt = some_more_math(xt)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Depending on the problem, it might be beneficial to upcast data to `float64` instead of `float32` precision for numerical stability.
|
|
368
|
+
|
|
369
|
+
## Contributors
|
|
370
|
+
|
|
371
|
+
[Boris Bonev](https://bonevbs.github.io) (bbonev@nvidia.com), [Thorsten Kurth](https://github.com/azrael417) (tkurth@nvidia.com), [Max Rietmann](https://github.com/rietmann-nv), [Mauro Bisson](https://scholar.google.com/citations?hl=en&user=f0JE-0gAAAAJ), [Andrea Paris](https://github.com/apaaris), [Alberto Carpentieri](https://github.com/albertocarpentieri), [Massimiliano Fatica](https://scholar.google.com/citations?user=Deaq4uUAAAAJ&hl=en), [Nikola Kovachki](https://kovachki.github.io), [Jean Kossaifi](http://jeankossaifi.com), [Christian Hundt](https://github.com/gravitino)
|
|
372
|
+
|
|
373
|
+
## Cite us
|
|
374
|
+
|
|
375
|
+
If you use `torch-harmonics` in an academic paper, please cite [1]
|
|
376
|
+
|
|
377
|
+
```bibtex
|
|
378
|
+
@misc{bonev2023spherical,
|
|
379
|
+
title={Spherical Fourier Neural Operators: Learning Stable Dynamics on the Sphere},
|
|
380
|
+
author={Boris Bonev and Thorsten Kurth and Christian Hundt and Jaideep Pathak and Maximilian Baust and Karthik Kashinath and Anima Anandkumar},
|
|
381
|
+
year={2023},
|
|
382
|
+
eprint={2306.03838},
|
|
383
|
+
archivePrefix={arXiv},
|
|
384
|
+
primaryClass={cs.LG}
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## References
|
|
389
|
+
|
|
390
|
+
<a id="1">[1]</a>
|
|
391
|
+
Bonev B., Kurth T., Hundt C., Pathak, J., Baust M., Kashinath K., Anandkumar A.;
|
|
392
|
+
Spherical Fourier Neural Operators: Learning Stable Dynamics on the Sphere;
|
|
393
|
+
International Conference on Machine Learning, 2023. [arxiv link](https://arxiv.org/abs/2306.03838)
|
|
394
|
+
|
|
395
|
+
<a id="1">[2]</a>
|
|
396
|
+
Liu-Schiaffini M., Berner J., Bonev B., Kurth T., Azizzadenesheli K., Anandkumar A.;
|
|
397
|
+
Neural Operators with Localized Integral and Differential Kernels;
|
|
398
|
+
International Conference on Machine Learning, 2024. [arxiv link](https://arxiv.org/abs/2402.16845)
|
|
399
|
+
|
|
400
|
+
<a id="1">[3]</a>
|
|
401
|
+
Schaeffer N.;
|
|
402
|
+
Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations;
|
|
403
|
+
G3: Geochemistry, Geophysics, Geosystems, 2013.
|
|
404
|
+
|
|
405
|
+
<a id="1">[4]</a>
|
|
406
|
+
Wang B., Wang L., Xie Z.;
|
|
407
|
+
Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids;
|
|
408
|
+
Adv Comput Math, 2018.
|
|
409
|
+
|
|
410
|
+
<a id="1">[5]</a>
|
|
411
|
+
Ocampo, Price, McEwen, Scalable and equivariant spherical CNNs by discrete-continuous (DISCO) convolutions, ICLR (2023), arXiv:2209.13603
|
|
412
|
+
|
|
413
|
+
<a id="1">[6]</a>
|
|
414
|
+
Bonev B., Rietmann M., Paris A., Carpentieri A., Kurth T.; Attention on the Sphere; [arxiv link](https://arxiv.org/abs/2505.11157)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2
|
|
3
|
+
|
|
4
|
+
[build-system]
|
|
5
|
+
requires = ["wheel-stub"]
|
|
6
|
+
build-backend = "wheel_stub.buildapi"
|
|
7
|
+
|
|
8
|
+
[tool.wheel_stub]
|
|
9
|
+
index_url = "https://pypi.nvidia.com/"
|
|
10
|
+
include_cuda_debuginfo = true
|