Abdullah-Nazhat commited on
Commit
cf5b6c7
·
verified ·
1 Parent(s): 90e16cd

Update tensormapper.py

Browse files
Files changed (1) hide show
  1. tensormapper.py +9 -9
tensormapper.py CHANGED
@@ -13,12 +13,12 @@ class VecDyT(nn.Module):
13
  return x
14
 
15
  class GatingUnit(nn.Module):
16
- def __init__(self,dim):
17
 
18
  super().__init__()
19
 
20
- self.proj_1 = nn.Linear(dim,dim,bias=False)
21
- self.proj_2 = nn.Linear(dim,dim,bias=False)
22
 
23
  self.gelu = nn.GELU()
24
 
@@ -37,9 +37,9 @@ class TTT(nn.Module):
37
 
38
  super(TTT, self).__init__()
39
 
40
- self.mapping = nn.Linear(dim,dim,bias=False)
41
- self.State = nn.Linear(dim,dim,bias=False)
42
- self.Probe = nn.Linear(dim,dim,bias=False)
43
 
44
  def forward(self, in_seq: Tensor) -> Tensor:
45
 
@@ -52,14 +52,14 @@ class TTT(nn.Module):
52
  label_view = state
53
  loss = nn.functional.mse_loss(self.mapping(train_view), label_view)
54
  grads = torch.autograd.grad(
55
- loss, self.mapping.parameters(),create_graph=True)
56
  with torch.no_grad():
57
  for param, grad in zip(self.mapping.parameters(), grads):
58
 
59
  param -= 0.01 * grad
60
  readout = self.mapping(self.Probe(in_seq[:,seq,:])).detach()
61
  outs.append(readout)
62
- out = torch.stack(outs, dim=1)
63
 
64
  return out
65
 
@@ -104,4 +104,4 @@ class TensorMapper(nn.Module):
104
 
105
  def forward(self, x):
106
 
107
- return self.model(x)
 
13
  return x
14
 
15
  class GatingUnit(nn.Module):
16
+ def __init__(self, dim):
17
 
18
  super().__init__()
19
 
20
+ self.proj_1 = nn.Linear(dim, dim, bias = False)
21
+ self.proj_2 = nn.Linear(dim, dim, bias = False)
22
 
23
  self.gelu = nn.GELU()
24
 
 
37
 
38
  super(TTT, self).__init__()
39
 
40
+ self.mapping = nn.Linear(dim, dim, bias = False)
41
+ self.State = nn.Linear(dim, dim, bias = False)
42
+ self.Probe = nn.Linear(dim, dim, bias = False)
43
 
44
  def forward(self, in_seq: Tensor) -> Tensor:
45
 
 
52
  label_view = state
53
  loss = nn.functional.mse_loss(self.mapping(train_view), label_view)
54
  grads = torch.autograd.grad(
55
+ loss, self.mapping.parameters(), create_graph = True)
56
  with torch.no_grad():
57
  for param, grad in zip(self.mapping.parameters(), grads):
58
 
59
  param -= 0.01 * grad
60
  readout = self.mapping(self.Probe(in_seq[:,seq,:])).detach()
61
  outs.append(readout)
62
+ out = torch.stack(outs, dim = 1)
63
 
64
  return out
65
 
 
104
 
105
  def forward(self, x):
106
 
107
+ return self.model(x)