ValueError: The AttentionMechanism instances passed to this AttentionWrapper should be initialized with a memory first, either by passing it to the AttentionMechanism constructor or calling attention_mechanism.setup_memory()
The cause of this error is probably the rnn_cell_impl.assert_like_rnncell("cell", cell) check which is present in the BasicDecoder's constructor. The above assertion will end up in AttentionWrapper.output_size or AttentionWrapper.state_size.
It appears assert_like_rnncell reimplements its own hasattr in terms of getattr: tensorflow/tensorflow@d70e8ee. This is certainly to support cells overriding __getattribute__ but it's unclear how common this use case is.
As it is a private TensorFlow API, I would suggest to implement an alternative that works for us. What do you think?
Yes, I think it would work completely fine. However, it would restrict the type of RNNCells that we could potentially accept. So probably we need to document it somewhere in our code to inform the future users.
In addition, Maybe we should warn the user to not use our .output_size/.state_size before the memory initialization. And even double-check our code to make sure that we wait until the initialization of the memory.