Update modeling_omegacode.py with latest corrections
Browse files- modeling_omegacode.py +15 -3
modeling_omegacode.py
CHANGED
|
@@ -9,7 +9,7 @@ class HolographicMasterCodeTransformer(nn.Module):
|
|
| 9 |
super().__init__()
|
| 10 |
self.d_model = d_model
|
| 11 |
self.n_harmonics = n_harmonics
|
| 12 |
-
self.alpha_0 = 1.0 / 137.035
|
| 13 |
|
| 14 |
self.input_proj = nn.Linear(input_dim, d_model)
|
| 15 |
|
|
@@ -30,19 +30,31 @@ class HolographicMasterCodeTransformer(nn.Module):
|
|
| 30 |
)
|
| 31 |
|
| 32 |
def forward(self, x, alpha=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
if alpha is None:
|
| 34 |
alpha = self.alpha_0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
h = self.input_proj(x)
|
| 36 |
h = h.unsqueeze(1)
|
| 37 |
h = self.transformer(h)
|
| 38 |
h = h.squeeze(1)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
psi = torch.zeros_like(h)
|
| 41 |
for n in range(self.n_harmonics):
|
| 42 |
-
|
|
|
|
| 43 |
psi += self.harmonic_weights[n] * torch.cos(h * (n + 1) + phase)
|
| 44 |
|
| 45 |
-
alpha_dev = torch.abs(
|
| 46 |
security_factor = torch.exp(-300.0 * alpha_dev)
|
| 47 |
|
| 48 |
h = h + 0.35 * psi * security_factor
|
|
|
|
| 9 |
super().__init__()
|
| 10 |
self.d_model = d_model
|
| 11 |
self.n_harmonics = n_harmonics
|
| 12 |
+
self.alpha_0 = torch.tensor(1.0 / 137.035) # Convert to tensor during initialization
|
| 13 |
|
| 14 |
self.input_proj = nn.Linear(input_dim, d_model)
|
| 15 |
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
def forward(self, x, alpha=None):
|
| 33 |
+
# Ensure alpha_0 is on the correct device
|
| 34 |
+
if self.alpha_0.device != x.device:
|
| 35 |
+
self.alpha_0 = self.alpha_0.to(x.device)
|
| 36 |
+
|
| 37 |
if alpha is None:
|
| 38 |
alpha = self.alpha_0
|
| 39 |
+
else:
|
| 40 |
+
# Convert alpha to a tensor if it's not already, and move to the correct device
|
| 41 |
+
alpha = torch.tensor(alpha, device=x.device, dtype=x.dtype) if not isinstance(alpha, torch.Tensor) else alpha.to(x.device)
|
| 42 |
+
|
| 43 |
h = self.input_proj(x)
|
| 44 |
h = h.unsqueeze(1)
|
| 45 |
h = self.transformer(h)
|
| 46 |
h = h.squeeze(1)
|
| 47 |
|
| 48 |
+
# All operands for arithmetic operations should be tensors now
|
| 49 |
+
alpha_diff = alpha - self.alpha_0
|
| 50 |
+
|
| 51 |
psi = torch.zeros_like(h)
|
| 52 |
for n in range(self.n_harmonics):
|
| 53 |
+
# Ensure phase calculation uses tensors
|
| 54 |
+
phase = 2 * torch.pi * (n + 1) * alpha_diff * 800.0
|
| 55 |
psi += self.harmonic_weights[n] * torch.cos(h * (n + 1) + phase)
|
| 56 |
|
| 57 |
+
alpha_dev = torch.abs(alpha_diff) # Now alpha_diff is guaranteed to be a tensor
|
| 58 |
security_factor = torch.exp(-300.0 * alpha_dev)
|
| 59 |
|
| 60 |
h = h + 0.35 * psi * security_factor
|