tensorflow: tf.function and tf.nest break for valid Mapping instances
tf.function
makes invalid assumptions about arguments that are Mapping
instances. In general, there are no requirements for Mapping
instances to have constructors that accept [(key, value)]
initializers, as assumed here.
This leads to cryptic exceptions when used with perfectly valid Mapping
subclasses such as this one:
class CustomMapping(Mapping):
def __init__(self, **kwargs):
self.mapping = kwargs
def __getitem__(self, key):
return self.mapping[key]
def __iter__(self):
return iter(self.mapping)
def __len__(self):
return len(self.mapping)
See this Colab notebook for an example.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 33 (15 by maintainers)
Commits related to this issue
- Improved error message to clarify why a custom mapping is not being accepted. Based on this issue: https://github.com/tensorflow/tensorflow/issues/36146 — committed to tonytonev/tensorflow by tonytonev 4 years ago
- Improved error message to clarify why a custom mapping is not being accepted. Based on this issue: https://github.com/tensorflow/tensorflow/issues/36146 — committed to tonytonev/tensorflow by tonytonev 4 years ago
Hey @Joey155 ! PR #36186 has been opened regarding the same.
I think the error you see is expected - it’s the bug described in the OP.
@namedtoaster see the guide: https://www.tensorflow.org/install/source; you may want to skip to the Docker section for a ready-made setup.
Issue replicating in tf-nightly. Thanks.