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
bd1a43b6
Unverified
Commit
bd1a43b6
authored
Dec 20, 2022
by
Sanchit Gandhi
Committed by
GitHub
Dec 20, 2022
Browse files
[S2T, Whisper] Add copied from statements (#20787)
* [S2T, Whisper] Add copied from statements * rebase and fix-copies
parent
5eecf3ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
src/transformers/models/speech_to_text/modeling_speech_to_text.py
...sformers/models/speech_to_text/modeling_speech_to_text.py
+6
-4
src/transformers/models/whisper/modeling_whisper.py
src/transformers/models/whisper/modeling_whisper.py
+6
-6
No files found.
src/transformers/models/speech_to_text/modeling_speech_to_text.py
View file @
bd1a43b6
...
...
@@ -354,6 +354,7 @@ class Speech2TextAttention(nn.Module):
return
attn_output
,
attn_weights_reshaped
,
past_key_value
# Copied from transformers.models.mbart.modeling_mbart.MBartEncoderLayer with MBart->Speech2Text
class
Speech2TextEncoderLayer
(
nn
.
Module
):
def
__init__
(
self
,
config
:
Speech2TextConfig
):
super
().
__init__
()
...
...
@@ -377,14 +378,14 @@ class Speech2TextEncoderLayer(nn.Module):
attention_mask
:
torch
.
Tensor
,
layer_head_mask
:
torch
.
Tensor
,
output_attentions
:
bool
=
False
,
):
)
->
torch
.
Tensor
:
"""
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
`(
config.
encoder_attention_heads,)`.
`(encoder_attention_heads,)`.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.
...
...
@@ -422,6 +423,7 @@ class Speech2TextEncoderLayer(nn.Module):
return
outputs
# Copied from transformers.models.mbart.modeling_mbart.MBartDecoderLayer with MBart->Speech2Text
class
Speech2TextDecoderLayer
(
nn
.
Module
):
def
__init__
(
self
,
config
:
Speech2TextConfig
):
super
().
__init__
()
...
...
@@ -460,7 +462,7 @@ class Speech2TextDecoderLayer(nn.Module):
past_key_value
:
Optional
[
Tuple
[
torch
.
Tensor
]]
=
None
,
output_attentions
:
Optional
[
bool
]
=
False
,
use_cache
:
Optional
[
bool
]
=
True
,
):
)
->
torch
.
Tensor
:
"""
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
...
...
@@ -473,7 +475,7 @@ class Speech2TextDecoderLayer(nn.Module):
layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
`(encoder_attention_heads,)`.
cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
size
*
(decoder_attention_heads,)
*
.
size
`
(decoder_attention_heads,)
`
.
past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
...
...
src/transformers/models/whisper/modeling_whisper.py
View file @
bd1a43b6
...
...
@@ -261,7 +261,7 @@ class WhisperAttention(nn.Module):
return
attn_output
,
attn_weights_reshaped
,
past_key_value
# Copied from transformers.models.
speech_to_text.modeling_speech_to_text.Speech2Tex
tEncoderLayer with
Speech2Tex
t->Whisper
# Copied from transformers.models.
mbart.modeling_mbart.MBar
tEncoderLayer with
MBar
t->Whisper
class
WhisperEncoderLayer
(
nn
.
Module
):
def
__init__
(
self
,
config
:
WhisperConfig
):
super
().
__init__
()
...
...
@@ -285,14 +285,14 @@ class WhisperEncoderLayer(nn.Module):
attention_mask
:
torch
.
Tensor
,
layer_head_mask
:
torch
.
Tensor
,
output_attentions
:
bool
=
False
,
):
)
->
torch
.
Tensor
:
"""
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
`(
config.
encoder_attention_heads,)`.
`(encoder_attention_heads,)`.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.
...
...
@@ -330,7 +330,7 @@ class WhisperEncoderLayer(nn.Module):
return
outputs
# Copied from transformers.models.
speech_to_text.modeling_speech_to_text.Speech2Tex
tDecoderLayer with
Speech2Tex
t->Whisper
# Copied from transformers.models.
mbart.modeling_mbart.MBar
tDecoderLayer with
MBar
t->Whisper
class
WhisperDecoderLayer
(
nn
.
Module
):
def
__init__
(
self
,
config
:
WhisperConfig
):
super
().
__init__
()
...
...
@@ -369,7 +369,7 @@ class WhisperDecoderLayer(nn.Module):
past_key_value
:
Optional
[
Tuple
[
torch
.
Tensor
]]
=
None
,
output_attentions
:
Optional
[
bool
]
=
False
,
use_cache
:
Optional
[
bool
]
=
True
,
):
)
->
torch
.
Tensor
:
"""
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)`
...
...
@@ -382,7 +382,7 @@ class WhisperDecoderLayer(nn.Module):
layer_head_mask (`torch.FloatTensor`): mask for attention heads in a given layer of size
`(encoder_attention_heads,)`.
cross_attn_layer_head_mask (`torch.FloatTensor`): mask for cross-attention heads in a given layer of
size
*
(decoder_attention_heads,)
*
.
size
`
(decoder_attention_heads,)
`
.
past_key_value (`Tuple(torch.FloatTensor)`): cached past key and value projection states
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
...
...
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