Skip to content

feat: optional CuPy GPU backend, float32 support and a treasure-grade polish pass - #8

Merged
XavierSpycy merged 8 commits into
mainfrom
perf/cupy
Aug 16, 2026
Merged

XavierSpycy merged 8 commits into
mainfrom
perf/cupy

Conversation

@XavierSpycy

Copy link
Copy Markdown
Owner

What's in this PR

Optional CuPy GPU backend (the headline feature)

  • numpy_keras.set_backend("cupy") / NUMPY_KERAS_BACKEND=cupy; default behavior stays bit-identical pure NumPy, missing CuPy degrades gracefully
  • Host-side RNG keeps same-seed runs bit-identical across backends; params/grads/optimizer state auto-sync both ways at fit/predict/evaluate
  • RNN GPU branches batch the input projection into one 3D matmul (CPU paths untouched, pinned at rtol=1e-12)
  • Fused GPU optimizer kernels (the device twin of the Cython kernels) + device-side predict + contracted softmax backward
  • 44 GPU parity tests incl. finite-difference gradcheck on the device

float32 compute dtype

  • Sequential(..., dtype="float32") with dtype enforced at the choke points (cupy scalar promotion silently produced float64 — fixed and tested)
  • 9 dedicated tests; honest note: on the A800 (FP64 tensor cores) f32 ≈ f64 at teaching scale; f32 halves memory and pays off on consumer GPUs

Fixes and infrastructure

  • autograd/ subpackage repaired (Flatten dispatch, predict, best-weights restore, import crash without autograd) + 7 tests
  • Tutorial chapter 13 (CuPy GPU) + excerpt re-sync for 02/03/06/07/09/10 (14/14 byte-verified)
  • GitHub Actions CI: numpy-only matrix (py3.10–3.12) + full-CPU job with Cython/autograd, coverage gate ≥75%, Codecov upload
  • API polish: xavier_* canonical spelling (old names aliased), EarlyStopping(monitor="loss"), predict return-type documented
  • CONTRIBUTING.md; release bump to 2.2.0

Verification

  • pytest tests/: 318 passed (186 original untouched + backend 12, GPU parity 44, float32 9, autograd 7, Cython 58 after in-place build)
  • check_snippets.py: 14/14
  • Benchmarks on 2× A800 80GB: MLP end-to-end ~3.2× vs pure NumPy (no metrics), fused Adam ~83×; RNNs at teaching scale are honestly reported as slower on GPU

@XavierSpycy
XavierSpycy merged commit 4eb20ad into main Aug 16, 2026
4 checks passed
@XavierSpycy
XavierSpycy deleted the perf/cupy branch August 16, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant