Skip to content

Improve ML cupy memory estimation#644

Merged
daurer merged 5 commits into
devfrom
ml-cupy-memory-estimation
Jun 11, 2026
Merged

Improve ML cupy memory estimation#644
daurer merged 5 commits into
devfrom
ml-cupy-memory-estimation

Conversation

@daurer

@daurer daurer commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

In some cases, we have noticed that when the last block of data is allocated in the ML cupy engine, there is not enough memory available despite upfront calculations on how much device memory is free.

The origin of this issue could be related to discrepancies between memory allocation of cupy and via the lower level CUDA runtime API - this needs further investigation.

As an intermediate solution, I am adding the capabilities to leave more extra device memory (now defined as a fraction of total memory) and allow users to change this "safety margin" by adding an environment variable PTYPY_DEVICE_MEM_SAFETY.

The new default for this safety margin is 2.5% of the total device memory or at least 400 MB (previously it was hardcoded to 200 MB) to make sure we can always operate on low-memory devices.

@daurer

daurer commented Feb 18, 2026

Copy link
Copy Markdown
Contributor Author

Keep fractional idea but never go below an absolute value (increase that from 200 MB to 400 MB)

@daurer daurer force-pushed the ml-cupy-memory-estimation branch from 9a49b9f to 6f202eb Compare April 10, 2026 13:24
@daurer daurer marked this pull request as ready for review April 10, 2026 13:33
@daurer daurer self-assigned this Apr 10, 2026
@daurer daurer requested a review from bjoernenders April 10, 2026 14:42
@daurer daurer force-pushed the ml-cupy-memory-estimation branch from d3fcc8c to 6fb03cd Compare April 13, 2026 09:18
@daurer daurer merged commit 4bbf4f4 into dev Jun 11, 2026
20 checks passed
@daurer daurer deleted the ml-cupy-memory-estimation branch June 11, 2026 10:11
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