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
77412343
Unverified
Commit
77412343
authored
May 05, 2023
by
Andrei Filatov
Committed by
GitHub
May 05, 2023
Browse files
fixed whisper positional encoding (#23167)
parent
1b9c352e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
2 deletions
+2
-2
src/transformers/models/whisper/modeling_tf_whisper.py
src/transformers/models/whisper/modeling_tf_whisper.py
+1
-1
src/transformers/models/whisper/modeling_whisper.py
src/transformers/models/whisper/modeling_whisper.py
+1
-1
No files found.
src/transformers/models/whisper/modeling_tf_whisper.py
View file @
77412343
...
@@ -128,7 +128,7 @@ class TFWhisperPositionalEmbedding(tf.keras.layers.Layer):
...
@@ -128,7 +128,7 @@ class TFWhisperPositionalEmbedding(tf.keras.layers.Layer):
def
call
(
self
,
input_ids
,
past_key_values_length
=
0
):
def
call
(
self
,
input_ids
,
past_key_values_length
=
0
):
past_key_values_length
=
tf
.
cast
(
past_key_values_length
,
tf
.
int32
)
past_key_values_length
=
tf
.
cast
(
past_key_values_length
,
tf
.
int32
)
gather_indices
=
tf
.
range
(
tf
.
shape
(
input_ids
)[
-
1
],
delta
=
1
)
+
past_key_values_length
gather_indices
=
tf
.
range
(
tf
.
shape
(
input_ids
)[
1
],
delta
=
1
)
+
past_key_values_length
return
tf
.
gather
(
self
.
weight
,
gather_indices
)
return
tf
.
gather
(
self
.
weight
,
gather_indices
)
...
...
src/transformers/models/whisper/modeling_whisper.py
View file @
77412343
...
@@ -226,7 +226,7 @@ class WhisperPositionalEmbedding(nn.Embedding):
...
@@ -226,7 +226,7 @@ class WhisperPositionalEmbedding(nn.Embedding):
super
().
__init__
(
num_positions
,
embedding_dim
)
super
().
__init__
(
num_positions
,
embedding_dim
)
def
forward
(
self
,
input_ids
,
past_key_values_length
=
0
):
def
forward
(
self
,
input_ids
,
past_key_values_length
=
0
):
return
self
.
weight
[
past_key_values_length
:
past_key_values_length
+
input_ids
.
shape
[
-
1
]]
return
self
.
weight
[
past_key_values_length
:
past_key_values_length
+
input_ids
.
shape
[
1
]]
class
WhisperAttention
(
nn
.
Module
):
class
WhisperAttention
(
nn
.
Module
):
...
...
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