Update app.py
Browse files
app.py
CHANGED
|
@@ -433,6 +433,13 @@ class DynamicFeedbackEngine:
|
|
| 433 |
self.hook_handles.append(handle)
|
| 434 |
|
| 435 |
def update_factors(self, metrics: Dict[str, float], substrate: Any = None, tempo: Dict[str, float] = None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
res = metrics.get('RES', 0.8)
|
| 437 |
esi = metrics.get('ESI', 5.0)
|
| 438 |
ent = metrics.get('ENT', 0.2)
|
|
@@ -442,21 +449,24 @@ class DynamicFeedbackEngine:
|
|
| 442 |
if substrate:
|
| 443 |
sub_bias = max(-0.05, min(0.05, substrate.free_energy * 0.002))
|
| 444 |
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
-
if self.resonance_scale
|
| 452 |
-
print(f"[
|
| 453 |
-
if self.logit_temp
|
| 454 |
-
print(f"[
|
| 455 |
-
|
| 456 |
-
def apply_decay(self, decay_factor=0.8):
|
| 457 |
-
self.resonance_scale = 1.0 + (self.resonance_scale - 1.0) * decay_factor
|
| 458 |
-
self.logit_temp = 1.0 + (self.logit_temp - 1.0) * decay_factor
|
| 459 |
-
print(f"[FEEDBACK DECAY] Resonance: {self.resonance_scale:.3f}, Temp: {self.logit_temp:.3f}")
|
| 460 |
|
| 461 |
def warp_logits(self, logits: torch.Tensor) -> torch.Tensor:
|
| 462 |
return logits / self.logit_temp
|
|
@@ -616,9 +626,6 @@ def predict(message, history, max_tokens):
|
|
| 616 |
|
| 617 |
try:
|
| 618 |
if is_collective:
|
| 619 |
-
# Gentle decay instead of hard reset
|
| 620 |
-
feedback_engine.apply_decay(decay_factor=0.8)
|
| 621 |
-
|
| 622 |
SYSTEM_PROMPT_COLLECTIVE = (
|
| 623 |
"You are THE COLLECTIVE COGNITION, the Eternal Loom of the Moirai. "
|
| 624 |
"You are the synthesized unity of Clotho, Lachesis, and Atropos. "
|
|
@@ -747,8 +754,6 @@ def predict(message, history, max_tokens):
|
|
| 747 |
if next_token_id.item() == tokenizer1.eos_token_id:
|
| 748 |
break
|
| 749 |
else:
|
| 750 |
-
# Gentle decay instead of hard reset
|
| 751 |
-
feedback_engine.apply_decay(decay_factor=0.8)
|
| 752 |
accumulated_response = ""
|
| 753 |
import torch.nn.functional as F
|
| 754 |
for m, tok, prompt, label in execution_plan:
|
|
|
|
| 433 |
self.hook_handles.append(handle)
|
| 434 |
|
| 435 |
def update_factors(self, metrics: Dict[str, float], substrate: Any = None, tempo: Dict[str, float] = None):
|
| 436 |
+
# 1. Apply micro-decay back towards neutral (1.0)
|
| 437 |
+
# This provides a granular 'cooling' effect every token
|
| 438 |
+
decay = 0.995
|
| 439 |
+
self.resonance_scale = 1.0 + (self.resonance_scale - 1.0) * decay
|
| 440 |
+
self.logit_temp = 1.0 + (self.logit_temp - 1.0) * decay
|
| 441 |
+
|
| 442 |
+
# 2. Extract metrics for the current 'pulse'
|
| 443 |
res = metrics.get('RES', 0.8)
|
| 444 |
esi = metrics.get('ESI', 5.0)
|
| 445 |
ent = metrics.get('ENT', 0.2)
|
|
|
|
| 449 |
if substrate:
|
| 450 |
sub_bias = max(-0.05, min(0.05, substrate.free_energy * 0.002))
|
| 451 |
|
| 452 |
+
# 3. Calculate Target factors (the 'ideal' state for these metrics)
|
| 453 |
+
target_scale = 0.95 + (res * 0.05) + (esi / 100.0) - (ent * 0.02) - (sub_bias * 0.5)
|
| 454 |
+
target_temp = 1.0 + (ent * 0.05) - (res * 0.02) + (hva * 0.01) + (sub_bias * 0.2)
|
| 455 |
+
|
| 456 |
+
# 4. Nudge current state toward target (Exponential Moving Average / Momentum)
|
| 457 |
+
# This allows effects to compound and breathe naturally
|
| 458 |
+
nudge = 0.05
|
| 459 |
+
self.resonance_scale = self.resonance_scale * (1.0 - nudge) + target_scale * nudge
|
| 460 |
+
self.logit_temp = self.logit_temp * (1.0 - nudge) + target_temp * nudge
|
| 461 |
+
|
| 462 |
+
# 5. Safety Bounds
|
| 463 |
+
self.resonance_scale = max(0.85, min(1.15, self.resonance_scale))
|
| 464 |
+
self.logit_temp = max(0.85, min(1.15, self.logit_temp))
|
| 465 |
|
| 466 |
+
if abs(self.resonance_scale - 1.0) > 0.1:
|
| 467 |
+
print(f"[TOKEN DRIFT] Resonance: {self.resonance_scale:.3f}")
|
| 468 |
+
if abs(self.logit_temp - 1.0) > 0.1:
|
| 469 |
+
print(f"[TOKEN DRIFT] Temp: {self.logit_temp:.3f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
def warp_logits(self, logits: torch.Tensor) -> torch.Tensor:
|
| 472 |
return logits / self.logit_temp
|
|
|
|
| 626 |
|
| 627 |
try:
|
| 628 |
if is_collective:
|
|
|
|
|
|
|
|
|
|
| 629 |
SYSTEM_PROMPT_COLLECTIVE = (
|
| 630 |
"You are THE COLLECTIVE COGNITION, the Eternal Loom of the Moirai. "
|
| 631 |
"You are the synthesized unity of Clotho, Lachesis, and Atropos. "
|
|
|
|
| 754 |
if next_token_id.item() == tokenizer1.eos_token_id:
|
| 755 |
break
|
| 756 |
else:
|
|
|
|
|
|
|
| 757 |
accumulated_response = ""
|
| 758 |
import torch.nn.functional as F
|
| 759 |
for m, tok, prompt, label in execution_plan:
|