With keras==3.7.0, the following snippet:
import keras
from keras import layers
attention = layers.Attention()
x = keras.Input(shape=(3, 5))
y = keras.Input(shape=(3, 5))
out_attn, out_attn_scores = attention(x, y, return_attention_scores=True)
Throws:
Traceback (most recent call last):
File "attention_repro.py", line 10, in <module>
out_attn, out_attn_scores = attention(x, y, return_attention_scores=True)
File "venv\lib\site-packages\keras\src\backend\common\keras_tensor.py", line 121, in __iter__
raise NotImplementedError(
NotImplementedError: Iterating over a symbolic KerasTensor is not supported.
Because return_attention_scores seems to have no effect, and the second output is not returned. The attention.call() method seems right, it's just that the call doesn't seem to construct the output tuple correctly.