Skip to content
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

Refactoring: turn the attribute _return_attention_scores into an argument #20803

Merged

Conversation

apehex
Copy link
Contributor

@apehex apehex commented Jan 23, 2025

I have a small refactoring for the class MultiHeadAttention 👾

I propose to replace the private attribute _return_attention_scores with an extra argument in _compute_attention.

This would make subclassing more straightforward and avoid cases where the attention scores are None.
This issue shows in CachedMultiHeadAttention on KerasHub.

The rationale is explained in more details in #20802

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.01%. Comparing base (90568da) to head (4c5557e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20803      +/-   ##
==========================================
- Coverage   82.01%   82.01%   -0.01%     
==========================================
  Files         557      557              
  Lines       52016    52014       -2     
  Branches     8037     8037              
==========================================
- Hits        42659    42657       -2     
  Misses       7403     7403              
  Partials     1954     1954              
Flag Coverage Δ
keras 81.83% <100.00%> (-0.01%) ⬇️
keras-jax 64.22% <100.00%> (-0.01%) ⬇️
keras-numpy 58.96% <0.00%> (-0.01%) ⬇️
keras-openvino 29.89% <0.00%> (+<0.01%) ⬆️
keras-tensorflow 64.78% <0.00%> (-0.01%) ⬇️
keras-torch 64.17% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is a good change. Thanks!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Jan 24, 2025
@fchollet fchollet merged commit d7d2e43 into keras-team:master Jan 24, 2025
8 checks passed
@google-ml-butler google-ml-butler bot removed ready to pull Ready to be merged into the codebase kokoro:force-run labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants