-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot call AttentionLayer with symbolic tensors and return_attention_scores=True in Keras 3 #20621
Comments
Hi @boweia, Thanks for reporting this. You are trying to access attention scores with symbolic KerasTensor, which are only placeholders and do not hold any real data; while an eager tensor holds actual data and can be evaluated immediately in eager execution mode. Attention layer computes attention scores when the model is executed with real data.
|
Thanks @dhantule. I think what I'm unclear on is why the attention scores cannot be returned from the call method as a symbolic tensor, the same way the attention output is returned. Also, this workflow previously worked in TensorFlow 2.14 with Keras 2 and I only started seeing it after updating to newer versions recently. If defining a wrapper class is the only way to support this I see that it can work, but it seems silly that its necessary instead of purely using the Keras functional API to define a model. |
Hi @boweia, |
I don't think the issue is related to Graph or Eager execution. Calling
I believe there is an issue with Or is there is any reason for current behaviour? |
In Keras 3 I cannot call the call method of AttentionLayer (or other attention layer classes) with a symbolic KerasTensor input and return_attention_scores=True.
I am using Python 3.12.1 and Keras 3.6.0
The layer call method works when replacing the symbolic inputs with np.ndarray inputs.
The text was updated successfully, but these errors were encountered: