Skip to content

Commit 5abe122

Browse files
committed
fixing .to(device), remove rnn_flatten, avoid rev if fails
1 parent d81652d commit 5abe122

11 files changed

Lines changed: 54 additions & 308 deletions

File tree

recipes/LibriSpeech/ASR/seq2seq/experiment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def compute_forward(self, x, y, stage):
7171
# Forward pass
7272
feats = self.hparams.compute_features(wavs)
7373
feats = self.hparams.normalize(feats, wav_lens)
74-
x = self.hparams.enc(feats)
74+
x = self.hparams.enc(feats.detach())
7575
e_in = self.hparams.emb(y_in)
7676
h, _ = self.hparams.dec(e_in, x, wav_lens)
7777

speechbrain/alignment/aligner.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,19 @@ def _make_trans_prob(self, phn_lens_abs):
518518
)
519519

520520
# clear probabilities for too-long sequences
521-
mask_a = torch.arange(U_max).to(device)[None, :] < phn_lens_abs[:, None]
521+
mask_a = (
522+
torch.arange(U_max, device=device)[None, :] < phn_lens_abs[:, None]
523+
)
522524
mask_a = mask_a.unsqueeze(2)
523525
mask_a = mask_a.expand(-1, -1, U_max)
524526
mask_b = mask_a.permute(0, 2, 1)
525527
trans_prob = trans_prob * (mask_a & mask_b).float()
526528

527529
## put -infs in place of zeros:
528530
trans_prob = torch.where(
529-
trans_prob == 1, trans_prob, torch.tensor(-float("Inf")).to(device)
531+
trans_prob == 1,
532+
trans_prob,
533+
torch.tensor(-float("Inf"), device=device),
530534
)
531535

532536
## normalize
@@ -575,7 +579,7 @@ def _make_emiss_pred_useful(
575579
emiss_pred_acc_lens = torch.where(
576580
mask_lens[:, :, None],
577581
emission_pred,
578-
torch.tensor([0.0]).to(device),
582+
torch.tensor([0.0], device=device),
579583
)
580584

581585
# manipulate phn tensor, and then 'torch.gather'
@@ -590,7 +594,7 @@ def _make_emiss_pred_useful(
590594
emiss_pred_useful = torch.where(
591595
mask_phn_lens[:, None, :],
592596
emiss_pred_useful,
593-
torch.tensor([self.neg_inf]).to(device),
597+
torch.tensor([self.neg_inf], device=device),
594598
)
595599

596600
emiss_pred_useful = emiss_pred_useful.permute(0, 2, 1)
@@ -647,8 +651,8 @@ def _dp_forward(
647651

648652
# initialise
649653
alpha_matrix = self.neg_inf * torch.ones(
650-
[batch_size, U_max, fb_max_length]
651-
).to(device)
654+
[batch_size, U_max, fb_max_length], device=device
655+
)
652656
alpha_matrix[:, :, 0] = pi_prob + emiss_pred_useful[:, :, 0]
653657

654658
for t in range(1, fb_max_length):
@@ -733,9 +737,11 @@ def _dp_viterbi(
733737
trans_prob = trans_prob.to(device)
734738

735739
v_matrix = self.neg_inf * torch.ones(
736-
[batch_size, U_max, fb_max_length]
737-
).to(device)
738-
backpointers = -99 * torch.ones([batch_size, U_max, fb_max_length])
740+
[batch_size, U_max, fb_max_length], device=device
741+
)
742+
backpointers = -99 * torch.ones(
743+
[batch_size, U_max, fb_max_length], device=device
744+
)
739745

740746
# initialise
741747
v_matrix[:, :, 0] = pi_prob + emiss_pred_useful[:, :, 0]

speechbrain/decoders/decoders.py

Lines changed: 0 additions & 255 deletions
This file was deleted.

0 commit comments

Comments
 (0)