Skip to content

Loading from .h5ad taking much more memory than loading same dataset from 10x .h5 #146

Closed

Description

@ivirshup

I was just trying to run the 1.3 million cell clustering example, but have come across some strange behavior.

When loading in the hdf5 file from 10x to an AnnData object, the whole process uses about 30gb. If I write that AnnData object to disk with adata.write, then try to load that file (with sc.read) I end up using all the memory on the machine (~60g) before segfault-ing. I'd think that any dataset I wrote from memory, I should be able to read back into memory.

I've put the full scripts to reproduce on my system in this gist, but essentially I've run:

# gen_h5ad.py
import scanpy.api as sc
adata = sc.read_10x_h5("{DATAPTH}/1M_neurons_filtered_gene_bc_matrices_h5.h5") # Uses about 30gb
adata.write("./write/1M_neurons.h5ad")
# load_anndata.py
import scanpy.api as sc
adata = sc.read("./write/1M_neurons.h5ad") # Ends with segfault

I'm running scanpy installed with conda with the following versions:

scanpy==1.0.4 anndata==0.6 numpy==1.14.2 scipy==1.0.1 pandas==0.22.0 scikit-learn==0.19.1 statsmodels==0.8.0

Thanks for the great package! Let me know if you'd like any more details on my setup.

Activity

  1. falexwolf commented on May 5, 2018

    @falexwolf
    Member

    Oh, this is of course really strange and shouldn't occur... we'll figure that out! Thank you for mentioning this!

  2. falexwolf commented on Dec 3, 2018

    @falexwolf
    Member

    Finally fixed by @Koncopd via scverse/anndata#85.

  3. sjfleming commented on Feb 14, 2024

    @sjfleming
    Contributor

    Is this still fixed? I see that loading a 36GB h5ad file requires me to use a machine with 128GB RAM.

  4. ivirshup commented on Feb 15, 2024

    @ivirshup
    MemberAuthor

    @sjfleming I can't reproduce this behaviour locally anymore. For example:

    In [1]: import anndata as ad
    %
    In [2]: %load_ext memory_profiler
    
    In [3]: %memit adata = ad.read_h5ad("tmp.h5ad")
    peak memory: 17805.42 MiB, increment: 17595.69 MiB
    
    In [4]: !du -hs tmp.h5ad
    18G	tmp.h5ad

    But you would see this if the file is compressed

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions