Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c965d302
Unverified
Commit
c965d302
authored
Jul 17, 2023
by
bofeng huang
Committed by
GitHub
Jul 17, 2023
Browse files
Fix comments for `_merge_heads` (#24855)
* Fix comments * Fix comments
parent
e4a52b6a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
src/transformers/models/bloom/modeling_bloom.py
src/transformers/models/bloom/modeling_bloom.py
+2
-2
src/transformers/models/falcon/modeling_falcon.py
src/transformers/models/falcon/modeling_falcon.py
+2
-2
No files found.
src/transformers/models/bloom/modeling_bloom.py
View file @
c965d302
...
@@ -253,7 +253,7 @@ class BloomAttention(nn.Module):
...
@@ -253,7 +253,7 @@ class BloomAttention(nn.Module):
def
_merge_heads
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
def
_merge_heads
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
"""
"""
Merge heads together over the last dimens
t
ion
Merge heads together over the last dimension
Args:
Args:
x (`torch.tensor`, *required*): [batch_size * num_heads, seq_length, head_dim]
x (`torch.tensor`, *required*): [batch_size * num_heads, seq_length, head_dim]
...
@@ -344,7 +344,7 @@ class BloomAttention(nn.Module):
...
@@ -344,7 +344,7 @@ class BloomAttention(nn.Module):
# matmul: [batch_size * num_heads, q_length, head_dim]
# matmul: [batch_size * num_heads, q_length, head_dim]
context_layer
=
torch
.
bmm
(
attention_probs_reshaped
,
value_layer
)
context_layer
=
torch
.
bmm
(
attention_probs_reshaped
,
value_layer
)
# change view [batch_size,
num_heads, q_length,
head_dim]
# change view [batch_size,
q_length, num_heads *
head_dim]
context_layer
=
self
.
_merge_heads
(
context_layer
)
context_layer
=
self
.
_merge_heads
(
context_layer
)
# aggregate results across tp ranks. See here: https://github.com/pytorch/pytorch/issues/76232
# aggregate results across tp ranks. See here: https://github.com/pytorch/pytorch/issues/76232
...
...
src/transformers/models/falcon/modeling_falcon.py
View file @
c965d302
...
@@ -255,7 +255,7 @@ class FalconAttention(nn.Module):
...
@@ -255,7 +255,7 @@ class FalconAttention(nn.Module):
# Copied from transformers.models.bloom.modeling_bloom.BloomAttention._merge_heads
# Copied from transformers.models.bloom.modeling_bloom.BloomAttention._merge_heads
def
_merge_heads
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
def
_merge_heads
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
"""
"""
Merge heads together over the last dimens
t
ion
Merge heads together over the last dimension
Args:
Args:
x (`torch.tensor`, *required*): [batch_size * num_heads, seq_length, head_dim]
x (`torch.tensor`, *required*): [batch_size * num_heads, seq_length, head_dim]
...
@@ -384,7 +384,7 @@ class FalconAttention(nn.Module):
...
@@ -384,7 +384,7 @@ class FalconAttention(nn.Module):
# matmul: [batch_size * num_heads, q_length, head_dim]
# matmul: [batch_size * num_heads, q_length, head_dim]
context_layer
=
(
attention_probs_reshaped
@
value_layer_
).
flatten
(
0
,
1
)
context_layer
=
(
attention_probs_reshaped
@
value_layer_
).
flatten
(
0
,
1
)
# change view [batch_size,
num_heads, q_length,
head_dim]
# change view [batch_size,
q_length, num_heads *
head_dim]
context_layer
=
self
.
_merge_heads
(
context_layer
)
context_layer
=
self
.
_merge_heads
(
context_layer
)
output_tensor
=
self
.
dense
(
context_layer
)
output_tensor
=
self
.
dense
(
context_layer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment