Commit 7471264
authored
fix: prevent MilsteinGradFree OOM crash; make GPU test suite hardware-independent (#837)
* fix: prevent MilsteinGradFree OOM crash; make GPU test suite hardware-independent
The Linux CI job (`pytest brainpy/`) was OOM-killed (exit 143) at
`brainpy/integrators/sde/normal_coverage_test.py` [69%]. Root cause: the
vector-Wiener branch of `MilsteinGradFree.step` used the full `(m, m)`
diffusion-bar matrix together with `minus * jnp.sum(noise_p2, -1)`, which left
the noise dimension in the integrated state. Each step grew the output by two
axes — `()` -> `(m, m)` -> `(m, m, m, m)` -> ... — a multi-GB blow-up over a long
integration that exhausted the runner's RAM (macOS/Windows runners had enough
headroom to survive, so only Linux crashed). Take the diagonal of the
diffusion-bar block and contract the per-component Milstein correction over the
noise axis, mirroring the shape-preserving pattern already used by `Milstein`.
The integrated state now stays correctly shaped and the full suite peaks at a
bounded ~9 GB with the crash region flat (no spike).
Also make the suite pass on GPU developer machines without changing CPU/CI
behaviour:
* conftest.py: pin `jax_default_matmul_precision='highest'`. On NVIDIA GPUs the
default uses TF32 for float32 matmuls (~1e-4 relative error), which broke the
operator-vs-dense correctness comparisons (JIT-connectivity layers,
orthonormality checks) on GPU while passing on CPU.
* brainpy/dnn/linear_test.py: use float32-appropriate tolerances
(`rtol=1e-4, atol=1e-5`) for the JIT-operator vs dense `x @ conn` comparison;
the default `atol=1e-8` is tighter than float32 rounding for the near-zero
symmetric-uniform outputs.
* brainpy/math/object_transform/object_transform_fixes_test.py: guard the
`.cuda()` / `.tpu()` `RuntimeError` assertions on device availability so the
test stays meaningful on CPU-only CI yet does not fail on GPU/TPU machines.
* fix(deps): require braintools>=0.3.0 (0.2.0 was yanked from PyPI)
braintools 0.2.0 was yanked from PyPI, so the previous `braintools>=0.2.0`
pin became unsatisfiable and broke `pip install -r requirements.txt` on every
CI runner (install failed in ~10s, before any test ran). 0.3.0 is the next
released version and carries the surrogate / metric fixes that the
`brainpy.math.surrogate` and L1-loss tests assert. Bump the pin in both
requirements.txt and pyproject.toml.
* refactor(math): reuse brainunit.math einops; drop the local port
brainpy's ein_reduce / ein_rearrange / ein_repeat / ein_shape duplicated the
einops implementation that now lives in brainunit.math (einreduce / einrearrange
/ einrepeat / einshape — behaviour-identical and accepting brainpy ``Array``
instances directly). Re-export the historical ``ein_*`` names as thin aliases of
brainunit's and delete the duplicated implementation (einops.py,
einops_parsing.py) and its dedicated tests (einops_test.py,
einops_coverage_test.py, einops_parsing_test.py). The einops tests in
math_compat_fixes_test.py now exercise the public ``bm.ein_*`` aliases and assert
the re-export wiring.
* chore(math): remove taichi/tifunc remnants
The taichi backend is gone; drop the fully-skipped tifunc_test.py (a taichi
``ti.kernel`` test) and the stale ``method`` / Taichi paragraph in the csrmv
docstring (that parameter no longer exists — csrmv dispatches through brainevent).1 parent a1d96a2 commit 7471264
15 files changed
Lines changed: 127 additions & 1698 deletions
File tree
- brainpy
- dnn
- integrators/sde
- math
- object_transform
- sparse
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
| |||
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
171 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
172 | 178 | | |
173 | 179 | | |
174 | 180 | | |
| |||
184 | 190 | | |
185 | 191 | | |
186 | 192 | | |
187 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
188 | 197 | | |
189 | 198 | | |
190 | 199 | | |
| |||
202 | 211 | | |
203 | 212 | | |
204 | 213 | | |
205 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
206 | 218 | | |
207 | 219 | | |
208 | 220 | | |
| |||
221 | 233 | | |
222 | 234 | | |
223 | 235 | | |
224 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
225 | 240 | | |
226 | 241 | | |
227 | 242 | | |
| |||
240 | 255 | | |
241 | 256 | | |
242 | 257 | | |
243 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
244 | 262 | | |
245 | 263 | | |
246 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
506 | 505 | | |
507 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
508 | 517 | | |
| 518 | + | |
509 | 519 | | |
510 | 520 | | |
511 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| |||
0 commit comments