Update modeling_super_linear.py
Browse files- modeling_super_linear.py +12 -17
modeling_super_linear.py
CHANGED
|
@@ -200,7 +200,7 @@ class RLinear(nn.Module):
|
|
| 200 |
self.revin_layer = RevIN(num_features = None, affine=False, norm_type = None, subtract_last = False)
|
| 201 |
self.zero_shot_Linear = None
|
| 202 |
|
| 203 |
-
def transform_model(self,new_lookback,mode):
|
| 204 |
if mode == 1:
|
| 205 |
W = self.Linear.weight.detach()
|
| 206 |
new_W = W[:, -new_lookback:]
|
|
@@ -226,25 +226,19 @@ class RLinear(nn.Module):
|
|
| 226 |
else:
|
| 227 |
W = self.Linear.weight.detach() # (out_features, seq_len)
|
| 228 |
|
| 229 |
-
# 1
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
# 2️⃣ resize those columns back to `seq_len`
|
| 233 |
-
# ─ use 4-D shape (N=1, C=1, H=out, W=new_lookback)
|
| 234 |
-
W4d = W_tail.unsqueeze(0).unsqueeze(0)
|
| 235 |
-
|
| 236 |
new_W = F.interpolate(
|
| 237 |
W4d,
|
| 238 |
-
size=(
|
| 239 |
-
# stretch cols to seq_len
|
| 240 |
mode='bilinear',
|
| 241 |
align_corners=False
|
| 242 |
-
)[0, 0]
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
self.zero_shot_Linear = W_now
|
| 248 |
|
| 249 |
|
| 250 |
|
|
@@ -254,7 +248,8 @@ class RLinear(nn.Module):
|
|
| 254 |
if x.shape[1] < self.seq_len:
|
| 255 |
#if self.zero_shot_Linear is None:
|
| 256 |
#print(F"new Lookkback : {x.shape[1]}")
|
| 257 |
-
|
|
|
|
| 258 |
|
| 259 |
x = x.clone()
|
| 260 |
#x = x * (x.shape[1]/512)
|
|
|
|
| 200 |
self.revin_layer = RevIN(num_features = None, affine=False, norm_type = None, subtract_last = False)
|
| 201 |
self.zero_shot_Linear = None
|
| 202 |
|
| 203 |
+
def transform_model(self,x,new_lookback,mode):
|
| 204 |
if mode == 1:
|
| 205 |
W = self.Linear.weight.detach()
|
| 206 |
new_W = W[:, -new_lookback:]
|
|
|
|
| 226 |
else:
|
| 227 |
W = self.Linear.weight.detach() # (out_features, seq_len)
|
| 228 |
|
| 229 |
+
W4d = W.unsqueeze(0).unsqueeze(0) # (1, 1, out, in)
|
| 230 |
+
|
| 231 |
+
# resize H → self.horizon and W → new_lookback
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
new_W = F.interpolate(
|
| 233 |
W4d,
|
| 234 |
+
size=(self.horizon, new_lookback), # (H_out, W_out)
|
|
|
|
| 235 |
mode='bilinear',
|
| 236 |
align_corners=False
|
| 237 |
+
)[0, 0] # drop the two singleton dims
|
| 238 |
+
|
| 239 |
+
x = F.linear(x, new_W)
|
| 240 |
+
self.zero_shot_Linear = W
|
| 241 |
+
return x
|
|
|
|
| 242 |
|
| 243 |
|
| 244 |
|
|
|
|
| 248 |
if x.shape[1] < self.seq_len:
|
| 249 |
#if self.zero_shot_Linear is None:
|
| 250 |
#print(F"new Lookkback : {x.shape[1]}")
|
| 251 |
+
|
| 252 |
+
x = self.transform_model(x,x.shape[1],3)
|
| 253 |
|
| 254 |
x = x.clone()
|
| 255 |
#x = x * (x.shape[1]/512)
|