@@ -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 ]
0 commit comments