PartitionedVariable doesn't support being used as a reference.
Package:
tensorflow
158813

Exception Class:
NotImplementedError
Raise code
pylint: disable=invalid-name
_ = name
if dtype is not None and not dtype.is_compatible_with(v.dtype):
raise ValueError(
"Incompatible type conversion requested to type '%s' for variable "
"of type '%s'" % (dtype.name, v.dtype.name))
if as_ref:
raise NotImplementedError(
"PartitionedVariable doesn't support being used as a reference.")
else:
return v.as_tensor()
@property
def name(self):
return self._name
@pr
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/tensorflow/tensorflow/blob/7acd515ec218b414d5b16e6710268ac03d9f5421/tensorflow/python/ops/variables.py#L3026Ways to fix
Summary:
This exception is thrown when the _TensorConversoinFunction function is called on an instance of PartitionedVariable. That function has an optional parameter named as_ref, and this parameter must be set to False in order to avoid running into any issues. If it is set to true, you will get this exception.
Code to Reproduce the Error (Wrong):
from tensorflow.python.ops.variables import PartitionedVariable
import numpy as np
import tensorflow as tf
name = "vars"
shape = [1,2,3]
dtype = np.int32
v = tf.Variable(1.)
v.assign(2.)
v.assign_add(0.5)
saveSliceInfo = v.SaveSliceInfo(full_shape=[1,2,3], var_offset=1)
v._set_save_slice_info(saveSliceInfo)
varList = [v, v, v]
partitions =[1,2,3]
pv = PartitionedVariable(name, shape, dtype, varList, partitions)
pv._TensorConversionFunction(v, as_ref=True)
Error Message:
NotImplementedError Traceback (most recent call last)
<ipython-input-31-5c5b562f0c2d> in <module>()
14 partitions =[1,2,3]
15 pv = PartitionedVariable(name, shape, dtype, varList, partitions)
---> 16 pv._TensorConversionFunction(v, as_ref=True)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/variables.py in _TensorConversionFunction(v, dtype, name, as_ref)
3020 if as_ref:
3021 raise NotImplementedError(
-> 3022 "PartitionedVariable doesn't support being used as a reference.")
3023 else:
3024 return v.as_tensor()
NotImplementedError: PartitionedVariable doesn't support being used as a reference.
Working Version (Right):
from tensorflow.python.ops.variables import PartitionedVariable
import numpy as np
import tensorflow as tf
name = "vars"
shape = [1,2,3]
dtype = np.int32
v = tf.Variable(1.)
v.assign(2.)
v.assign_add(0.5)
saveSliceInfo = v.SaveSliceInfo(full_shape=[1,2,3], var_offset=1)
v._set_save_slice_info(saveSliceInfo)
varList = [v, v, v]
partitions =[1,2,3]
pv = PartitionedVariable(name, shape, dtype, varList, partitions)
pv._TensorConversionFunction(v, as_ref=False) # as_ref set to False
Add a possible fix
Please authorize to post fix