-
Notifications
You must be signed in to change notification settings - Fork 15
Adding STU layer #154
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
base: main
Are you sure you want to change the base?
Adding STU layer #154
Conversation
Summary of ChangesHello @LakshmiKalaKadali, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the Keras framework by integrating a new Structured Transformer Unit (STU) layer. This layer provides a comprehensive set of functionalities for building sophisticated attention-based models, including multi-head attention, efficient handling of variable-length sequences through jagged tensor conversions, and optimized inference via KV caching. The introduction of the STU layer aims to offer more flexible and performant options for deep learning practitioners working with Keras. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new STU layer with its dependent functions, including custom attention mechanisms, jagged tensor handling, and caching logic. The implementation is comprehensive but contains several critical issues that need to be addressed. My review has identified problems related to incorrect imports, bugs in attention padding and masking, potential type errors from handling optional tensors, and incorrect tensor manipulations. Additionally, there are several unused parameters and opportunities to replace manual implementations with standard Keras operations for better performance and maintainability. Addressing these points will be crucial for ensuring the correctness and robustness of the new STU layer.
row_ids = ops.broadcast_to(ops.reshape(ids, (N, 1)), (N, N)) | ||
col_ids = ops.transpose(row_ids) | ||
row_ids = ops.reshape(row_ids, (1, N, N)) | ||
col_ids = ops.reshape(col_ids, (1, N, N)) | ||
max_ids = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in this else
block does not correctly handle batches. It creates row_ids
and col_ids
with a shape of (1, N, N)
, ignoring the batch size B
calculated earlier. If the batch size is greater than 1, this will lead to incorrect masking due to broadcasting. The mask should have a shape of (B, N, N)
to be consistent with the if num_targets is not None
branch.
else:
row_ids = ops.broadcast_to(ops.reshape(ids, (1, N, 1)), (B, N, N))
col_ids = ops.broadcast_to(ops.reshape(ids, (1, 1, N)), (B, N, N))
max_ids = None
num_heads: int = 1, | ||
linear_dim: int = -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v_cache: Optional[keras.KerasTensor] = None | ||
kv_caching_offsets: Optional[keras.KerasTensor] = None | ||
|
||
def __init__(self, config: STULayerConfig, is_inference: bool = False, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning Gemini encountered an error creating the review. You can try again by commenting |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This PR creates the STU layer with necessary dependent functions.