Error while loading tensors RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0

Hi, I am new to pytorch and I tried to load tensors to my server. However, I encountered an error. Here is my code.

# -*- coding: utf-8 -*-
import torch
import torchnet
torch.load("imgs0.pt")

I got an error like

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-7-f6f1f025b648> in <module>
      2 import torch
      3 import torchnet
----> 4 torch.load("imgs0.pt")
      5 model.to(device)

/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    385         f = f.open('rb')
    386     try:
--> 387         return _load(f, map_location, pickle_module, **pickle_load_args)
    388     finally:
    389         if new_fd:

/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    572     unpickler = pickle_module.Unpickler(f, **pickle_load_args)
    573     unpickler.persistent_load = persistent_load
--> 574     result = unpickler.load()
    575 
    576     deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)

/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py in persistent_load(saved_id)
    533             location = maybe_decode_ascii(location)
    534             if root_key not in deserialized_objects:
--> 535                 obj = data_type(size)
    536                 obj._torch_load_uninitialized = True
    537                 deserialized_objects[root_key] = restore_location(obj, location)

RuntimeError: [enforce fail at CPUAllocator.cpp:56] posix_memalign(&data, gAlignment, nbytes) == 0. 12 vs 0

At first, I thought maybe my cpu’s memory is not big enough for loading this tensor, and I tried to load it with my gpu. However, I got the same error, so I wondered whether this error is caused because of unpickling in python. Thank you for your help.

This error might point to not enough RAM on your machine.
Do you know the size of the data you are trying to load and if so, would it theoretically fit in your RAM?

1 Like

Thank you! My problem is solved. My data is roughly 8gb, but my cpu’s memory is only 3.75 gb. It’s solved after I upgraded my cpu.