Skip to content

Saving large array fails with savez_compressed() but works with save() #5336

Closed

Description

@minhlab

I got this strange problem on a CentOS box, Python 2.6.6, Numpy 1.9.1:

[minhle@node069 ~]$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.version.version
'1.9.1'
>>> a = np.ones((775890380,))
>>> np.savez_compressed('/home/minhle/scratch/test.npz', a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/minhle/.local/lib/python2.6/site-packages/numpy/lib/npyio.py", line 560, in savez_compressed
    _savez(file, args, kwds, True)
  File "/home/minhle/.local/lib/python2.6/site-packages/numpy/lib/npyio.py", line 597, in _savez
    format.write_array(fid, np.asanyarray(val))
  File "/home/minhle/.local/lib/python2.6/site-packages/numpy/lib/format.py", line 562, in write_array
    array.tofile(fp)
IOError: 775890380 requested and 233691638 written
>>> np.save('/home/minhle/scratch/test.npy', a)
>>> b = np.load('/home/minhle/scratch/test.npy')
>>> b[:10]
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
>>> quit()
[minhle@node069 ~]$ cat /etc/*-release
CentOS release 6.5 (Final)
Cluster Manager v5.2
slave
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
CentOS release 6.5 (Final)
CentOS release 6.5 (Final)

Activity

  1. changed the title [-]Saving large array fails with savez_compressed() while works with save()[/-] [+]Saving large array fails with savez_compressed() but works with save()[/+] on Dec 2, 2014
  2. omerlevy commented on Mar 20, 2015

    @omerlevy

    Got the same error... any solution in sight?

  3. samuela commented on Jul 10, 2015

    @samuela

    I just got this error too but with np.savez as opposed to np.savez_compressed.

  4. samuela commented on Jul 21, 2015

    @samuela

    For future reference, using np.save instead of np.savez[_compressed] seems to work as @omerlevy's example code indicates.

    So, is this an issue with savez? Anyone who knows numpy well have any ideas what's happening here?

  5. pv commented on Jul 21, 2015

    @pv
    Member

    savez needs to store files temporarily on disk, and perhaps you run out of space on /tmp.
    Try setting TMPDIR=$HOME/tmp or so.

  6. samuela commented on Aug 14, 2015

    @samuela

    @pv Yeah, changing TMPDIR did the trick for me. It may also be worth noting that I'm on an NFS filesystem. I'm not sure what sort of effects, if any, that might have. I'm guessing that I'm into subtleties in the way that /tmp is configured.

  7. samuela commented on Aug 14, 2015

    @samuela

    However, I think numpy should make this issue explicit in the documentation and provide some semblance of an intelligent, approachable error message.

  8. pwolfram commented on Dec 1, 2015

    @pwolfram
    Contributor

    Agreed. I ran onto this issue on HPC resources too and I agree that it would be good if the error / warning message recommended checking to make sure TMPDIR was set properly with adequate space.

  9. yarikoptic commented on Jan 27, 2016

    @yarikoptic
    Contributor

    Ran into the same problem (kudos to ngoldbaum@IRC for pointing me here). I understand that for temp storage TEMPDIR is usually the logical location. BUT when dealing with large datasets, there is a reason why we might want to savez to a different location and /tmp would never be big enough. So why not to follow any other downloader's behavior and use targetfilename + '_tempSMTHRANDOM' suffix instead. This has higher possibility to succeed since would use the target location/partition which should have adequate amount of storage. Also error message should include location of that temp file to give users sensible feedback

  10. added a commit that references this issue on Jan 28, 2016
    33777c6
  11. added a commit that references this issue on Mar 22, 2016
    a9f3179
  12. jinghuangzhu commented on Jun 13, 2016

    @jinghuangzhu

    I have enough space on /tmp, but still ran into the IOError:
    File "/data/anaconda/lib/python2.7/site-packages/numpy/lib/npyio.py", line 534, in savez
    _savez(file, args, kwds, False)
    File "/data/anaconda/lib/python2.7/site-packages/numpy/lib/npyio.py", line 597, in _savez
    format.write_array(fid, np.asanyarray(val))
    File "/data/anaconda/lib/python2.7/site-packages/numpy/lib/format.py", line 562, in write_array
    array.tofile(fp)
    IOError: 938283800 requested and 364613622 written

    So is this a common problem with numpy.savez? still no fix? which means I have to use "save" instead.

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