Skip to content
Latchkey

Python "numpy.core._exceptions._ArrayMemoryError" in CI

NumPy tried to allocate a contiguous block bigger than the memory available on the runner. The shape and dtype imply a buffer the constrained CI box cannot provide, so the allocation fails outright.

What this error means

A NumPy operation aborts with numpy.core._exceptions._ArrayMemoryError: Unable to allocate X GiB for an array with shape (...) and data type Y. It is reproducible for the same input size and tied to the runner’s memory, not the network.

Python traceback
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 11.2 GiB for an
array with shape (40000, 40000) and data type float64

Common causes

Allocation exceeds runner memory

The requested array is larger than the runner’s RAM. A 40000×40000 float64 array is ~12 GiB - far beyond a standard CI box.

Oversized dtype or accidental broadcast

Using float64 where float32 suffices, or an unintended broadcast/outer product, can multiply the needed memory several-fold.

How to fix it

Reduce the allocation

Use a smaller dtype, chunk the work, or operate in place to cut peak memory.

Python
import numpy as np
a = np.zeros((40000, 40000), dtype=np.float32)  # half the memory of float64
# or process in chunks instead of one giant array

Run on a larger runner for genuine workloads

  1. If the size is legitimate, use a higher-memory runner.
  2. Otherwise cap test fixture sizes so CI does not allocate production-scale arrays.
  3. Profile peak memory to find accidental broadcasts.

How to prevent it

  • Use the smallest sufficient dtype (float32/int32) for large arrays.
  • Keep CI fixtures small; do not allocate production-scale arrays in tests.
  • Chunk large computations instead of building one contiguous buffer.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →