Update modeling_super_linear.py
Browse files- modeling_super_linear.py +7 -6
modeling_super_linear.py
CHANGED
|
@@ -576,7 +576,7 @@ class SuperLinearForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 576 |
return y
|
| 577 |
|
| 578 |
|
| 579 |
-
def fourier_downsample_dim1(self,x,
|
| 580 |
|
| 581 |
L = x.size(1)
|
| 582 |
# 1. Forward real FFT along dim-1
|
|
@@ -592,12 +592,12 @@ class SuperLinearForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 592 |
|
| 593 |
return y
|
| 594 |
|
| 595 |
-
def upsample_interpolate(self, x, target_len: int = 512):
|
| 596 |
# Add channel dimension if input is 2D
|
| 597 |
if len(x.shape) == 2:
|
| 598 |
x = x.unsqueeze(1) # [B, 1, L]
|
| 599 |
|
| 600 |
-
|
| 601 |
upsample = interpolate(x, scale_factor=scale_factor, mode='linear') # [B, C, new_L]
|
| 602 |
|
| 603 |
# Take last 500 timesteps and rearrange to [B, L, C]
|
|
@@ -636,15 +636,16 @@ class SuperLinearForCausalLM(PreTrainedModel, GenerationMixin):
|
|
| 636 |
|
| 637 |
if x_enc.shape[1] < 512:
|
| 638 |
#x_enc = self.revin_layer(x_enc, 'norm')
|
| 639 |
-
|
|
|
|
| 640 |
pass
|
| 641 |
|
| 642 |
-
|
| 643 |
# backbone returns (B, pred_len, C)
|
| 644 |
self.backbone.inf_pred_len = 96*scale_factor
|
| 645 |
|
| 646 |
preds = self.backbone(x_enc)
|
| 647 |
-
x_enc = self.upsample_interpolate(x_enc,x_enc.shape[1])
|
| 648 |
#preds = self.fourier_downsample_dim1(preds,96)
|
| 649 |
#preds = self.revin_layer(preds, 'denorm')
|
| 650 |
|
|
|
|
| 576 |
return y
|
| 577 |
|
| 578 |
|
| 579 |
+
def fourier_downsample_dim1(self,x,target_len: int):
|
| 580 |
|
| 581 |
L = x.size(1)
|
| 582 |
# 1. Forward real FFT along dim-1
|
|
|
|
| 592 |
|
| 593 |
return y
|
| 594 |
|
| 595 |
+
def upsample_interpolate(self, x,scale_factor, target_len: int = 512):
|
| 596 |
# Add channel dimension if input is 2D
|
| 597 |
if len(x.shape) == 2:
|
| 598 |
x = x.unsqueeze(1) # [B, 1, L]
|
| 599 |
|
| 600 |
+
|
| 601 |
upsample = interpolate(x, scale_factor=scale_factor, mode='linear') # [B, C, new_L]
|
| 602 |
|
| 603 |
# Take last 500 timesteps and rearrange to [B, L, C]
|
|
|
|
| 636 |
|
| 637 |
if x_enc.shape[1] < 512:
|
| 638 |
#x_enc = self.revin_layer(x_enc, 'norm')
|
| 639 |
+
scale_factor = int(np.ceil(512/x_enc.shape[-1]))
|
| 640 |
+
x_enc = self.upsample_interpolate(x_enc,scale_factor,512)
|
| 641 |
pass
|
| 642 |
|
| 643 |
+
|
| 644 |
# backbone returns (B, pred_len, C)
|
| 645 |
self.backbone.inf_pred_len = 96*scale_factor
|
| 646 |
|
| 647 |
preds = self.backbone(x_enc)
|
| 648 |
+
x_enc = self.upsample_interpolate(x_enc,1/scale_factor,x_enc.shape[1])
|
| 649 |
#preds = self.fourier_downsample_dim1(preds,96)
|
| 650 |
#preds = self.revin_layer(preds, 'denorm')
|
| 651 |
|