razmars commited on
Commit
c23c896
Β·
verified Β·
1 Parent(s): b8782ae

Update modeling_super_linear.py

Browse files
Files changed (1) hide show
  1. modeling_super_linear.py +12 -7
modeling_super_linear.py CHANGED
@@ -592,24 +592,29 @@ class SuperLinearForCausalLM(PreTrainedModel, GenerationMixin):
592
 
593
  return y
594
 
595
- def upsample_interpolate(self, x,scale_factor, target_len: int = 512):
596
  was_2d = x.dim() == 2
597
-
598
  if was_2d: # [B, L] -> [B, 1, L]
599
  x = x.unsqueeze(1)
600
  else: # [B, L, C] -> [B, C, L]
601
  x = x.permute(0, 2, 1)
602
-
603
 
604
- x_up = F.interpolate(x, size=target_len, mode='linear', align_corners=False)
 
 
 
 
 
 
 
605
  x_up = x_up * scale_factor
606
-
607
- # ── restore original layout ─────────────────────────────────────────────────
608
  if was_2d: # back to [B, target_len]
609
  return x_up.squeeze(1).float()
610
  else: # back to [B, target_len, C]
611
  return x_up.permute(0, 2, 1).float()
612
-
613
 
614
 
615
 
 
592
 
593
  return y
594
 
595
+ def upsample_interpolate(self, x, scale_factor, target_len: int = 512, mode='bicubic'):
596
  was_2d = x.dim() == 2
597
+
598
  if was_2d: # [B, L] -> [B, 1, L]
599
  x = x.unsqueeze(1)
600
  else: # [B, L, C] -> [B, C, L]
601
  x = x.permute(0, 2, 1)
 
602
 
603
+ # Add support for bicubic interpolation by adding an extra dimension
604
+ if mode == 'bicubic':
605
+ x = x.unsqueeze(2) # [B, C, 1, L]
606
+ x_up = F.interpolate(x, size=(1, target_len), mode='bicubic', align_corners=False)
607
+ x_up = x_up.squeeze(2) # [B, C, L]
608
+ else:
609
+ x_up = F.interpolate(x, size=target_len, mode=mode, align_corners=False)
610
+
611
  x_up = x_up * scale_factor
612
+
613
+ # Restore original layout
614
  if was_2d: # back to [B, target_len]
615
  return x_up.squeeze(1).float()
616
  else: # back to [B, target_len, C]
617
  return x_up.permute(0, 2, 1).float()
 
618
 
619
 
620