Skip to content

BUG: it use more than 600MB, when i just import numpy #28565

Closed as not planned
Closed as not planned

Description

@cmyf123

Describe the issue:

I import numpy, just using it in a simple way, or not using it at all. At the beginning, the program only occupies around 20MB of memory, but after a while, the memory usage suddenly spikes to around 600MB, occasionally.
help!

Reproduce the code example:

import time
import numpy as np

if __name__ == '__main__':
    while True:
        time.sleep(0.5)

Error message:

No error occur, memory usage illogical

Python and NumPy Versions:

python 3.12.9 (tags/v3.12.9:fdb8142, Feb 4 2025, 15:27:58) [MSC v.1942 64 bit (AMD64)]
numpy v2.2.4

Runtime Environment:

[{'numpy_version': '2.2.4',
'python': '3.12.9 (tags/v3.12.9:fdb8142, Feb 4 2025, 15:27:58) [MSC v.1942 '
'64 bit (AMD64)]',
'uname': uname_result(system='Windows', node='xxx', release='11', version='10.0.22631', machine='AMD64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Haswell',
'filepath': 'D:\Python\Python312\Lib\site-packages\numpy.libs\libscipy_openblas64_-43e11ff0749b8cbe0a615c9cf6737e0e.dll',
'internal_api': 'openblas',
'num_threads': 20,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.28'}]

Context for the issue:

I need to develop a tool that consumes minimal system resources but relies on numpy.

Activity

  1. charris commented on Mar 21, 2025

    @charris
    Member

    What cpu do you have?

  2. cmyf123 commented on Mar 21, 2025

    @cmyf123
    Author

    What cpu do you have?
    13th Gen Intel(R) Core(TM) i7-13700H 2.40 GHz

  3. eendebakpt commented on Mar 21, 2025

    @eendebakpt
    Contributor

    How did you measure the memory usage? And does the issue also occur if you remove the numpy import?

  4. seberg commented on Mar 21, 2025

    @seberg
    Member

    This is presumably some openblas warmup, although I wouldn't be surprised if openblas is nice about it (does it use that much memory even if it isn't free/you have massively more?).

    Also as the question may already say: This would be heavily dependent on the system (e.g. scale with the number of cores and likely more. Openblas has 20 threads there, but your "minimal system" likely does not run with so many cores.)

    CC @mattip I feel you messed with settings before in libscipy_openblas to keep this under control a bit (and may know more anyway).

  5. melissawm commented on Mar 21, 2025

    @melissawm
    Member

    Could this be related to #19145?

  6. seberg commented on Mar 21, 2025

    @seberg
    Member

    @melissawm yes, it's related. But here it is clear that we are using the openblas that is packaged with NumPy, while in the other issue, I think it is likely the BLAS wasn't shipped with NumPy, so NumPy has no control at all.

  7. mattip commented on Mar 23, 2025

    @mattip
    Member

    OpenBLAS reservces memory per thread at startup. You can set the envirnment variable OPENBLAS_NUM_THREADS to a low number before starting python

    SET OPENBLAS_NUM_THREADS=1
    python
    >>> import numpy
    

    or use threadpoolctl to restrict the number of threads used, which will reduce the memory usage. Please let us know if this helps.

  8. added
    57 - Close?
    on Mar 24, 2025
  9. ngoldbaum commented on Mar 28, 2025

    @ngoldbaum
    Member

    Please let us know if @mattip's suggestions don't help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug57 - Close?

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions