Update modeling_super_linear.py
Browse files510 unmodified lines5115125135145155161 unmodified line5185195205215225235245251 unmodified line527528529530531532533534535536537538539540541542543544545546547548549510 unmodified linesdef forward(self, x_enc, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None, freq=[None], get_prob=False):if len(x_enc.shape) > 2:x = x_enc.permute(0, 2, 1)B, V, L = x.shape1 unmodified linex = x_encB, L = x.shapeV = 1x = x.reshape(B * V, L)expert_probs = Noneif get_prob:1 unmodified lineelse:out, self.moe_loss = self.moe(x)if self.auto_regressive and self.max_horizon < self.inf_pred_len:#print("bitch")outputs = [out]ar_x = torch.cat([x, out], dim=1)[:, -self.seq_len:]for i in range(0, self.inf_pred_len, self.max_horizon):ar_out, _ = self.moe(ar_x)outputs.append(ar_out)ar_x = torch.cat([ar_x, ar_out], dim=1)[:, -self.seq_len:]out = torch.cat(outputs, dim=1)[:, :self.inf_pred_len]if len(x_enc.shape) > 2:out = out.reshape(B, V, out.shape[-1])result = out.permute(0, 2, 1)else:result = outif get_prob:expert_probs = expert_probs.reshape(B, V, expert_probs.shape[-1])return result, expert_probs510 unmodified lines5115125135145155165175185195201 unmodified line5225235245255265275285295305315325335345355365375385395405415425435445455465471 unmodified line549550551552553554555556557558559560561562563564565566567568569570510 unmodified linesdef forward(self, x_enc, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None, freq=[None], get_prob=False):if inf_pred_len is None:inf_pred_len = self.inf_pred_lenif len(x_enc.shape) > 2:x = x_enc.permute(0, 2, 1)B, V, L = x.shape1 unmodified linex = x_encB, L = x.shapeV = 1short_lookback = Falseif L < self.seq_len:# print("test!")#ceil - very bad heuristic!scale_factor = self.seq_len / Lscale_factor = int(np.ceil(scale_factor))orig_pred_len = inf_pred_leninf_pred_len = inf_pred_len*scale_factorx = interpolate(x_enc.permute(0, 2, 1), scale_factor=scale_factor, mode='linear')x = x[:,: , -self.seq_len:]orig_L = LL = self.seq_lenshort_lookback = Truex = x.reshape(B * V, L)expert_probs = Noneif get_prob:1 unmodified lineelse:out, self.moe_loss = self.moe(x)if self.auto_regressive and self.max_horizon < inf_pred_len:outputs = [out]ar_x = torch.cat([x, out], dim=1)[:, -self.seq_len:]for i in range(0, inf_pred_len, self.max_horizon):ar_out, _ = self.moe(ar_x)outputs.append(ar_out)ar_x = torch.cat([ar_x, ar_out], dim=1)[:, -self.seq_len:]out = torch.cat(outputs, dim=1)[:,:inf_pred_len]out = out.reshape(B, V, out.shape[-1])if short_lookback:out = interpolate(out, scale_factor=1/scale_factor, mode='linear')# print(out.shape)out = out[:, :,:orig_pred_len]result = out.permute(0, 2, 1)if get_prob:expert_probs = expert_probs.reshape(B, V, expert_probs.shape[-1])return result, expert_probs
modeling_super_linear.py+32-11