@@ -361,7 +361,6 @@ def __init__(
361361 self .use_pytorch_sdpa_backends = use_pytorch_sdpa_backends
362362 self .sync_max_audio_length = sync_max_audio_length
363363
364-
365364 assert conv_context_style in ["regular" , "dcc" , "dcc_rc" ], f"Invalid conv_context_style: { conv_context_style } !"
366365 self .conv_context_style = conv_context_style
367366 self .conv_kernel_size = conv_kernel_size
@@ -370,8 +369,12 @@ def __init__(
370369 self .dual_mode_training = dual_mode_training
371370 self .unified_asr_prob = unified_asr_prob
372371 if att_chunk_context_size is not None :
373- assert att_context_style == "chunked_limited_with_rc" , "att_chunk_context_size is only supported for chunked_limited_with_rc attention style!"
374- assert len (att_chunk_context_size ) == 3 , "att_chunk_context_size must have 3 elements: [left_context, chunk_size, right_context]"
372+ assert (
373+ att_context_style == "chunked_limited_with_rc"
374+ ), "att_chunk_context_size is only supported for chunked_limited_with_rc attention style!"
375+ assert (
376+ len (att_chunk_context_size ) == 3
377+ ), "att_chunk_context_size must have 3 elements: [left_context, chunk_size, right_context]"
375378 self .att_chunk_context_size = att_chunk_context_size
376379 else :
377380 self .att_chunk_context_size = None
@@ -855,8 +858,10 @@ def _create_masks(self, att_context_size, padding_length, max_audio_length, offs
855858 )
856859 att_mask = torch .logical_and (att_mask , chunked_limited_mask .unsqueeze (0 ))
857860 elif self .att_context_style == "chunked_limited_with_rc" and sum (att_context_size ) != - 3 :
858- assert len (att_context_size ) == 3 , "att_context_size must have 3 elements: [left_context, chunk_size, right_context]"
859-
861+ assert (
862+ len (att_context_size ) == 3
863+ ), "att_context_size must have 3 elements: [left_context, chunk_size, right_context]"
864+
860865 left_context_frames = att_context_size [0 ]
861866 chunk_size_frames = att_context_size [1 ]
862867 right_context_frames = att_context_size [2 ]
@@ -867,22 +872,23 @@ def _create_masks(self, att_context_size, padding_length, max_audio_length, offs
867872 window_start = chunk_idx * chunk_size_frames - left_context_frames
868873 window_start = torch .maximum (window_start , torch .zeros_like (window_start ))
869874 window_end = chunk_idx * chunk_size_frames + chunk_size_frames - 1 + right_context_frames
870-
875+
871876 if self .training and self .skip_att_chunk_rc_prob > 0.0 :
872877 chunks_num = max_audio_length // chunk_size_frames
873878 for chunk_step in range (chunks_num ):
874879 if random .random () < self .skip_att_chunk_rc_prob :
875- window_end [chunk_step * chunk_size_frames :chunk_step * chunk_size_frames + chunk_size_frames ] -= right_context_frames
876-
880+ window_end [
881+ chunk_step * chunk_size_frames : chunk_step * chunk_size_frames + chunk_size_frames
882+ ] -= right_context_frames
883+
877884 window_end = torch .minimum (window_end , torch .full_like (window_end , max_audio_length - 1 ))
878885 # Create the mask: frame i can see frame j if window_start[i] <= j <= window_end[i]
879886 j_indices = frame_idx .unsqueeze (0 ) # [1, T]
880887 window_start_expanded = window_start .unsqueeze (1 ) # [T, 1]
881- window_end_expanded = window_end .unsqueeze (1 ) # [T, 1]
888+ window_end_expanded = window_end .unsqueeze (1 ) # [T, 1]
882889
883890 chunked_limited_mask = torch .logical_and (
884- j_indices >= window_start_expanded ,
885- j_indices <= window_end_expanded
891+ j_indices >= window_start_expanded , j_indices <= window_end_expanded
886892 )
887893 att_mask = torch .logical_and (att_mask , chunked_limited_mask .unsqueeze (0 ))
888894 else :
0 commit comments