Update modeling_super_linear.py
Browse files207 unmodified lines2082092102112122132142152161 unmodified line218219220221222223224207 unmodified linesfinal_scaling = original_norm / new_norm if new_norm.item() != 0 else 1.0#final_scaling = 1new_W = new_W * final_scalingself.zero_shot_Linear = new_Wdef forward(self, x):# x: [Batch, Input length,Channel]1 unmodified lineif x.shape[1] < self.seq_len:if self.zero_shot_Linear is None:#print(F"new Lookkback : {x.shape[1]}")self.transform_model(x.shape[1],2)x = x.clone()#x = x * (x.shape[1]/512)207 unmodified lines2082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372381 unmodified line240241242243244245246207 unmodified linesfinal_scaling = original_norm / new_norm if new_norm.item() != 0 else 1.0#final_scaling = 1new_W = new_W * final_scalingself.zero_shot_Linear = new_Welse:W = self.Linear.weight.detach()target_indices = torch.linspace(0, self.seq_len - 1, steps=new_lookback, device=W.device)source_indices = torch.arange(0, self.seq_len, device=W.device).float()# Initialize the new weight matrixnew_W = torch.zeros((W.size(0), new_lookback), device=W.device)# Linear interpolation for each rowfor i in range(W.size(0)):new_W[i] = torch.tensor([torch.sum(W[i] * (1 - torch.abs(idx - source_indices) / self.seq_len).clamp(min=0))for idx in target_indices], device=W.device)# Maintain the same norm as the original weightsoriginal_norm = torch.norm(W, p=2)new_norm = torch.norm(new_W, p=2)final_scaling = original_norm / new_norm if new_norm.item() != 0 else 1.0new_W = new_W * final_scalingself.zero_shot_Linear = new_Wdef forward(self, x):# x: [Batch, Input length,Channel]1 unmodified lineif x.shape[1] < self.seq_len:if self.zero_shot_Linear is None:#print(F"new Lookkback : {x.shape[1]}")self.transform_model(x.shape[1],3)x = x.clone()#x = x * (x.shape[1]/512)
modeling_super_linear.py+24-2