attributeError on `_rebuild_tensor` caused conda install avoided by pip install

Given I installed pytorch by conda install pytorch torchvision -c soumith

The problem 1
_rebuild_tensor inside _utils/ does not in the following output, why is it?

    ", ".join([t for t in dir(torch._utils)])
                                                            ### inside _utils we have the following function, but why not shown up???

                                                            # def _rebuild_tensor(storage, storage_offset, size, stride):
                                                            #     class_name = storage.__class__.__name__.replace('Storage', 'Tensor')
                                                            #     module = importlib.import_module(storage.__module__)
                                                            #     tensor_class = getattr(module, class_name)
                                                            #     return tensor_class().set_(storage, storage_offset, size, stride)

# output is the following
# '__builtins__, __cached__, __doc__, __file__, __loader__, __name__, __package__, __spec__, 
# _accumulate, _cuda, _import_dotted_name, _range, _type, torch'

The problem 2
_rebuild_tensor inside _utils/ does not in the following output, given it is imported inside torch.tensor.py file, why is it?

", ".join([t for t in dir(torch.tensor)])

# output is the following
# '_TensorBase, __builtins__, __cached__, __doc__, __file__, __loader__, __name__, __package__, 
# __spec__, _cuda, _range, _tensor_str, _type, sys, torch'

I think the two problems above is really the same one, that I can’t have access to torch._utils._rebuild_tensor, I wonder why.

Guesses

  1. I just did conda install pytorch torchvision -c soumith to install, was this the problem?
  2. when I ran ./run_test.sh, I got the following error:
ERROR: test_serialization_map_location (__main__.TestTorch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_torch.py", line 2711, in test_serialization_map_location
    tensor = torch.load(test_file_path, map_location=map_location)
  File "/Users/Natsume/miniconda2/envs/dlnd-tf-lab/lib/python3.5/site-packages/torch/serialization.py", line 222, in load
    return _load(f, map_location, pickle_module)
  File "/Users/Natsume/miniconda2/envs/dlnd-tf-lab/lib/python3.5/site-packages/torch/serialization.py", line 370, in _load
    result = unpickler.load()
AttributeError: Can't get attribute '_rebuild_tensor' on <module 'torch._utils' from '/Users/Natsume/miniconda2/envs/dlnd-tf-lab/lib/python3.5/site-packages/torch/_utils.py'>

Solution worked this time

  1. git clone pytorch
  2. create a new env
  3. conda install numpy setuptools cmake cffi
  4. pip install -r requirements.txt
  5. python setup.py install
    but the 5th step has a lot of failures and warnings, I can’t run import torch
    then I did
  6. pip install -e . then I can run import torch and the problems above are gone.
    but when I run cd test/ and ./run_test.sh, previous error is gone, but I got the following Exception:
Exception ignored in: <function WeakValueDictionary.__init__.<locals>.remove at 0x114c5da60>
Traceback (most recent call last):
  File "/Users/Natsume/miniconda2/envs/pytorch-experiment/lib/python3.5/weakref.py", line 117, in remove
TypeError: 'NoneType' object is not callable

should I be worried about this one?

Thanks a lot!

I met the same problem. The reason may be the version of the pretrained model you load doesn’t match with your pytorch.