-
Notifications
You must be signed in to change notification settings - Fork 601
Renamed bsz to bs for consistency; removed dead code
#299
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,7 +132,6 @@ class Attention(nn.Module): | |
| Attributes: | ||
| n_kv_heads (int): Number of key and value heads. | ||
| n_heads (int): Number of query heads. | ||
| n_local_kv_heads (int): Number of local key and value heads. | ||
| n_rep (int): Number of repetitions for local heads. | ||
| head_dim (int): Dimension size of each attention head. | ||
| wq (Linear): Linear transformation for queries. | ||
|
|
@@ -183,12 +182,12 @@ def forward( | |
| torch.Tensor: Output tensor after attention. | ||
|
|
||
| """ | ||
| bsz, seqlen, _ = x.shape | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all inline comments in this method use |
||
| bs, seqlen, _ = x.shape | ||
| xq, xk, xv = self.wq(x), self.wk(x), self.wv(x) | ||
|
|
||
| xq = xq.view(bsz, seqlen, self.n_heads, self.head_dim) | ||
| xk = xk.view(bsz, seqlen, self.n_kv_heads, self.head_dim) | ||
| xv = xv.view(bsz, seqlen, self.n_kv_heads, self.head_dim) | ||
| xq = xq.view(bs, seqlen, self.n_heads, self.head_dim) | ||
| xk = xk.view(bs, seqlen, self.n_kv_heads, self.head_dim) | ||
| xv = xv.view(bs, seqlen, self.n_kv_heads, self.head_dim) | ||
|
|
||
| xq, xk = apply_rotary_emb(xq, xk, freqs_cis=freqs_cis) | ||
|
|
||
|
|
@@ -205,7 +204,7 @@ def forward( | |
| output = output.transpose( | ||
| 1, 2 | ||
| ).contiguous() # (bs, seqlen, n_local_heads, head_dim) | ||
| output = output.view(bsz, seqlen, -1) | ||
| output = output.view(bs, seqlen, -1) | ||
| return self.wo(output) | ||
|
|
||
|
|
||
|
|
@@ -421,7 +420,7 @@ def forward(self, tokens: torch.Tensor): | |
| torch.Tensor: Output logits after applying the Transformer model. | ||
|
|
||
| """ | ||
| _bsz, seqlen = tokens.shape | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it helps readability to know the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although not used, it improves code readability -- it tells how many dimensions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
just saw this message, yeah I agree
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed it to |
||
| _bs, seqlen = tokens.shape | ||
| h = self.tok_embeddings(tokens) | ||
| self.freqs_cis = self.freqs_cis.to(h.device) | ||
| freqs_cis = self.freqs_cis[0:seqlen] | ||
|
|
||
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.
not an attribute (only one occurrence of
n_local_kv_headsif you search in this file)