Heinrich Dinkel commited on
Commit
ec2e819
·
1 Parent(s): 7a87364

Fix crash when last audio chunk has fewer frames than patch stride

Browse files

Pad the last chunk to self.time_patches frames when it's shorter after
splitting, preventing a RuntimeError in the Conv2d patch embedding when
input is not a multiple of target_length.

Files changed (1) hide show
  1. modeling_dasheng_encoder.py +8 -2
modeling_dasheng_encoder.py CHANGED
@@ -283,10 +283,16 @@ class DashengEncoder(nn.Module):
283
  x = rearrange(x, "b f t -> b 1 f t")
284
  x = self.init_bn(x)
285
 
286
- input_splits = x.split(self.target_length, dim=-1)
287
  masks = [None for _ in range(len(input_splits))]
288
  if attention_mask is not None:
289
- masks = attention_mask.split(self.target_length, dim=-1)
 
 
 
 
 
 
290
 
291
  outputs = []
292
  for i, (input_split_x, mask) in enumerate(zip(input_splits, masks)):
 
283
  x = rearrange(x, "b f t -> b 1 f t")
284
  x = self.init_bn(x)
285
 
286
+ input_splits = list(x.split(self.target_length, dim=-1))
287
  masks = [None for _ in range(len(input_splits))]
288
  if attention_mask is not None:
289
+ masks = list(attention_mask.split(self.target_length, dim=-1))
290
+
291
+ if input_splits[-1].shape[-1] < self.time_patches:
292
+ pad_size = self.time_patches - input_splits[-1].shape[-1]
293
+ input_splits[-1] = torch.nn.functional.pad(input_splits[-1], (0, pad_size))
294
+ if masks[-1] is not None:
295
+ masks[-1] = torch.nn.functional.pad(masks[-1], (0, pad_size), value=0)
296
 
297
  outputs = []
298
  for i, (input_split_x, mask) in enumerate(zip(input_splits, masks)):