This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
create T5MultiheadAttention module #1825
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
13f9c22
create T5MultiheadAttention module
pmabbo13 9d077bd
Update on "create T5MultiheadAttention module"
pmabbo13 32ad86c
Update on "create T5MultiheadAttention module"
pmabbo13 3b15ffc
Update on "create T5MultiheadAttention module"
pmabbo13 00ae21e
Update on "create T5MultiheadAttention module"
pmabbo13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # /* Portions Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Parts of code are originally from | ||
| # https://github.com/huggingface/transformers/blob/8581a798c0a48fca07b29ce2ca2ef55adcae8c7e/src/transformers/models/t5/modeling_t5.py | ||
| # */ | ||
|
|
||
| import torch | ||
| import torch.nn as nn | ||
|
|
||
|
|
||
| class T5MultiheadAttention(nn.MultiheadAttention): | ||
| def __init__( | ||
| self, | ||
| embed_dim, | ||
| num_heads, | ||
| is_decoder=False, | ||
| dropout=0.0, | ||
| bias=False, | ||
| kdim=None, | ||
| vdim=None, | ||
| device=None, | ||
| dtype=None, | ||
| ) -> None: | ||
| r""" | ||
| Args: | ||
| embed_dim: Total dimension of the model. | ||
| num_heads: Parallel attention heads. | ||
| is_decoder: Whether or not multihead attention is being performed on a decoder layer. Default: `False` | ||
| dropout: Probability of an element to be zeroed. Default: 0.0 | ||
| bias: If specified, adds bias to input / output projection layers. Default: `False`. | ||
| kdim: Total number of features for keys. Default: `None` (uses `kdim=embed_dim`). | ||
| vdim: Total number of features for values. Default: `None` (uses `vdim=embed_dim`). | ||
| """ | ||
| super().__init__(embed_dim, num_heads, dropout, bias, False, False, kdim, vdim, True, device, dtype) | ||
| factory_kwargs = {"device": device, "dtype": dtype} | ||
| self.is_decoder = is_decoder | ||
| self.q_proj_weight = nn.Parameter(torch.empty((embed_dim, embed_dim), **factory_kwargs)) | ||
| self.k_proj_weight = nn.Parameter(torch.empty((embed_dim, self.kdim), **factory_kwargs)) | ||
| self.v_proj_weight = nn.Parameter(torch.empty((embed_dim, self.vdim), **factory_kwargs)) | ||
| self.register_parameter("in_proj_weight", None) | ||
|
|
||
| def forward(): | ||
| pass | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.