Update modeling_super_linear.py
Browse files- modeling_super_linear.py +14 -15
modeling_super_linear.py
CHANGED
|
@@ -593,22 +593,21 @@ class SuperLinearForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 593 |
return y
|
| 594 |
|
| 595 |
def upsample_interpolate(self, x,scale_factor, target_len: int = 512):
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
if
|
| 599 |
-
x = x.unsqueeze(1)
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
return upsample
|
| 612 |
|
| 613 |
|
| 614 |
|
|
|
|
| 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 |
+
|
| 606 |
+
# ββ restore original layout βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 607 |
+
if was_2d: # back to [B, target_len]
|
| 608 |
+
return x_up.squeeze(1).float()
|
| 609 |
+
else: # back to [B, target_len, C]
|
| 610 |
+
return x_up.permute(0, 2, 1).float()
|
|
|
|
| 611 |
|
| 612 |
|
| 613 |
|