Compatibility issues between 0.3.1 and 0.4.1


My code works fine with Pytorch 0.3.1. I used PyTorch to make a differentiable kinematics model in my recent conference paper.

However, when I upgrade to Pytorch 0.4.1, I get the following error:

  File "", line 697, in train_convnet
  File "/usr/local/lib/python2.7/dist-packages/torch/", line 93, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/usr/local/lib/python2.7/dist-packages/torch/autograd/", line 90, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

This only happens in my differentiable kinematics model. It’s annoying that my code would be compatible with an earlier version of PyTorch but not a later version. Also, from this error, I’m not sure how to debug my code. I plan on just using 0.3.1 going forward, but perhaps this problem would be of help to the PyTorch developers.

Further, I’ve got a problem with using PyTorch 0.3.1 conflicting with Keras. When I have PyTorch 0.4.1 installed, Keras works fine. When I have PyTorch 0.3.1 installed, I can’t import anything from Keras. I’d like to use Keras to import a VGG16 image extractor before my PyTorch kinematics network, but because of this issue I can’t. Keras gives the following error:

Traceback (most recent call last):
  File "", line 61, in <module>
    from keras.applications.vgg16 import preprocess_input
  File "/usr/local/lib/python2.7/dist-packages/keras/", line 3, in <module>
    from . import utils
  File "/usr/local/lib/python2.7/dist-packages/keras/utils/", line 6, in <module>
    from . import conv_utils
  File "/usr/local/lib/python2.7/dist-packages/keras/utils/", line 9, in <module>
    from .. import backend as K
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/", line 89, in <module>
    from .tensorflow_backend import *
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/", line 5, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: dlopen: cannot load any more object with static TLS

Failed to load the native TensorFlow runtime.


for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

If anyone has suggestions to these issues, I’d appreciate it.

Henry M. Clever

Could you post a (small) executable code snippet throwing the RuntimeError?

I’m not sure, what’s the cause of the ImportError, but apparently your setup is working with 0.4.1, so it shouldn’t be an issue anymore once we solve the first problem.