Skip to content
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

Restore casting of masked_spec_embed #30336

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/transformers/models/data2vec/modeling_data2vec_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -868,7 +868,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/hubert/modeling_hubert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1015,7 +1015,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/sew/modeling_sew.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -872,7 +872,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/sew_d/modeling_sew_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1398,7 +1398,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/speecht5/modeling_speecht5.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -626,7 +626,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/unispeech/modeling_unispeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1131,7 +1131,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1149,7 +1149,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/wav2vec2/modeling_wav2vec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1506,7 +1506,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1097,7 +1097,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1283,7 +1283,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/wavlm/modeling_wavlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def _mask_hidden_states(

if mask_time_indices is not None:
# apply SpecAugment along time axis with given mask_time_indices
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)
elif self.config.mask_time_prob > 0 and self.training:
mask_time_indices = _compute_mask_indices(
(batch_size, sequence_length),
Expand All @@ -1168,7 +1168,7 @@ def _mask_hidden_states(
min_masks=self.config.mask_time_min_masks,
)
mask_time_indices = torch.tensor(mask_time_indices, device=hidden_states.device, dtype=torch.bool)
hidden_states[mask_time_indices] = self.masked_spec_embed
hidden_states[mask_time_indices] = self.masked_spec_embed.to(hidden_states.dtype)

if self.config.mask_feature_prob > 0 and self.training:
# generate indices & apply SpecAugment along feature axis
Expand Down
Loading