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
cfb22e03
Unverified
Commit
cfb22e03
authored
Jun 14, 2024
by
Mansu Kim
Committed by
GitHub
Jun 14, 2024
Browse files
Support Clip QKV for MPT (#31307)
parent
b7672826
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
src/transformers/models/mpt/modeling_mpt.py
src/transformers/models/mpt/modeling_mpt.py
+4
-0
No files found.
src/transformers/models/mpt/modeling_mpt.py
View file @
cfb22e03
...
...
@@ -82,6 +82,7 @@ class MptAttention(nn.Module):
self
.
softmax_scale
=
1
/
math
.
sqrt
(
self
.
hidden_size
/
self
.
n_heads
)
self
.
attn_dropout_p
=
config
.
attn_config
.
attn_pdrop
self
.
clip_qkv
=
config
.
attn_config
.
clip_qkv
self
.
Wqkv
=
nn
.
Linear
(
self
.
hidden_size
,
3
*
self
.
hidden_size
,
bias
=
False
)
self
.
out_proj
=
nn
.
Linear
(
self
.
hidden_size
,
self
.
hidden_size
,
bias
=
False
)
...
...
@@ -95,6 +96,9 @@ class MptAttention(nn.Module):
batch_size
,
seq_length
=
hidden_states
.
shape
[:
2
]
mixed_qkv
=
self
.
Wqkv
(
hidden_states
)
if
self
.
clip_qkv
:
mixed_qkv
=
mixed_qkv
.
clamp
(
min
=-
self
.
clip_qkv
,
max
=
self
.
clip_qkv
)
query_states
,
key_states
,
value_states
=
mixed_qkv
.
chunk
(
3
,
dim
=
2
)
query_states
=
query_states
.
reshape
(
batch_size
,
seq_length
,
self
.
n_heads
,
self
.
head_dim
).
transpose
(
1
,
2
)
key_states
=
key_states
.
reshape
(
batch_size
,
seq_length
,
self
.
n_heads
,
self
.
head_dim
).
transpose
(
1
,
2
)
...
...
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