Executor-Tyrant-Framework commited on
Commit
804ae3a
·
verified ·
1 Parent(s): a5529fd

Sync from GitHub: e776a7ae171da7f004d061e72643f07a30d0006c

Browse files
Files changed (1) hide show
  1. app.py +58 -57
app.py CHANGED
@@ -5,6 +5,21 @@ The organism. NeuroGraph substrate + KISS bucket + Pith bucket +
5
  Splat-Lenia + BitNet model. On CPU. Gets smarter over time.
6
 
7
  # ---- Changelog ----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # [2026-05-16] Claude Opus 4.7 (1M ctx) — Pith → user-turn labeled context block (3 sites)
9
  # Root cause of Run 48's 24/24 degenerate BitNet output: pith was being
10
  # injected into the system role slot via sys_ctx = "\n".join(pith) + sys.
@@ -820,40 +835,33 @@ def on_send(message, history):
820
  # ── 4. Pith bucket — extract relevant context from the River ──
821
  pith_context, pith_ids = organism.pith_extract_with_ids(message, max_context=5)
822
 
823
- # Pith does NOT go in the system slot. System slot is for the model's
824
- # identity/instructions; chat-tuned models treat retrieved questions
825
- # placed there as things to respond to (Run 48 root cause). Instead,
826
- # pith goes in a labeled context block inside the LAST user turn for
827
- # THIS turn's prompt onlysee feedback_pith_presentation_layer memory.
828
-
829
- # Only send recent messages. The substrate carries the rest.
830
- # Always trim to recent window. The substrate + KISS carry older context.
831
- recent_window = 6 # 3 turns of user+assistant
832
- if len(messages_nw) > recent_window:
833
- recent_msgs = messages_nw[-recent_window:]
834
- else:
835
- recent_msgs = messages_nw
836
-
837
- # Enrich the LAST user message for THIS turn's prompt only.
838
- # messages_nw stays clean (bare query persists in history) so next
839
- # turn's recent_window isn't polluted with this turn's pith.
840
  if pith_context:
841
  pith_block = "\n".join(f" - {p}" for p in pith_context)
842
- enriched_query = (
843
  "Some context that may be relevant (recalled from earlier "
844
  "related conversations; these are reference material, not "
845
  "questions to answer):\n"
846
  f"{pith_block}\n\n"
847
  f"My actual question: {message}"
848
  )
849
- recent_msgs = list(recent_msgs[:-1]) + [
850
- {"role": "user", "content": enriched_query}
851
- ]
852
 
853
  prompt_msgs = []
854
  if sys_ctx:
855
  prompt_msgs.append({"role": "system", "content": sys_ctx})
856
- prompt_msgs.extend(recent_msgs)
857
 
858
  prompt = tokenizer.apply_chat_template(
859
  prompt_msgs, tokenize=False, add_generation_prompt=True,
@@ -1075,40 +1083,32 @@ def on_benchmark(num_turns):
1075
  kiss_r = nw_kiss.filter_context(nw_msgs, system_prompt)
1076
  sys_ctx = kiss_r.get("system_context", system_prompt)
1077
 
1078
- # Pith Born rule extraction from substrate. Pith does NOT go in
1079
- # sys_ctx — it goes in a labeled context block in the last user
1080
- # turn below (see feedback_pith_presentation_layer memory).
1081
  pith_context = nw_organism.pith_extract(prompt_text, max_context=5)
1082
 
1083
- # Trim old messages always, not gated on Pith.
1084
- # The substrate + KISS carry what the older messages contained.
1085
- # Even without Pith contexts, the recent window has what the model
1086
- # needs for immediate coherence.
1087
- recent_window = 6
1088
- if len(nw_msgs) > recent_window:
1089
- recent = nw_msgs[-recent_window:]
1090
- else:
1091
- recent = nw_msgs
1092
-
1093
- # Enrich the LAST user message for THIS turn's prompt only.
1094
- # nw_msgs stays clean (bare query persists in history) so next
1095
- # turn's recent_window isn't polluted with this turn's pith.
1096
  if pith_context:
1097
  pith_block = "\n".join(f" - {p}" for p in pith_context)
1098
- enriched_query = (
1099
  "Some context that may be relevant (recalled from earlier "
1100
  "related conversations; these are reference material, not "
1101
  "questions to answer):\n"
1102
  f"{pith_block}\n\n"
1103
  f"My actual question: {prompt_text}"
1104
  )
1105
- recent = list(recent[:-1]) + [
1106
- {"role": "user", "content": enriched_query}
1107
- ]
 
 
 
 
1108
 
1109
  prompt_nw = tokenizer.apply_chat_template(
1110
- [{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
1111
- tokenize=False, add_generation_prompt=True,
1112
  )
1113
  resp_nw, in_nw, out_nw, time_nw, tps_nw, lenia_r = do_generate(prompt_nw, max_new_tokens=128)
1114
  nw_msgs.append({"role": "assistant", "content": resp_nw})
@@ -1469,30 +1469,31 @@ def on_interleaved_benchmark(
1469
 
1470
  kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
1471
  sys_ctx = kiss_r.get("system_context", system_prompt)
1472
- # Pith does NOT go in sys_ctx — see feedback_pith_presentation_layer
1473
- # memory. It goes in a labeled context block in the last user turn
1474
- # below for THIS turn's prompt only; nw_msgs stays clean so next
1475
- # turn's recent_window isn't polluted with this turn's pith.
1476
-
1477
- recent_window = 6
1478
- recent = nw_msgs[-recent_window:] if len(nw_msgs) > recent_window else nw_msgs
1479
 
 
 
 
 
 
1480
  if pith_context:
1481
  pith_block = "\n".join(f" - {p}" for p in pith_context)
1482
- enriched_query = (
1483
  "Some context that may be relevant (recalled from earlier "
1484
  "related conversations; these are reference material, not "
1485
  "questions to answer):\n"
1486
  f"{pith_block}\n\n"
1487
  f"My actual question: {prompt_text}"
1488
  )
1489
- recent = list(recent[:-1]) + [
1490
- {"role": "user", "content": enriched_query}
1491
- ]
 
 
 
 
1492
 
1493
  prompt_nw = tokenizer.apply_chat_template(
1494
- [{"role": "system", "content": sys_ctx}] + recent if sys_ctx else recent,
1495
- tokenize=False, add_generation_prompt=True,
1496
  )
1497
  resp_nw, in_nw, out_nw, time_nw, tps_nw, _ = do_generate(prompt_nw, max_new_tokens=128)
1498
  nw_msgs.append({"role": "assistant", "content": resp_nw})
 
5
  Splat-Lenia + BitNet model. On CPU. Gets smarter over time.
6
 
7
  # ---- Changelog ----
8
+ # [2026-05-22] Claude Opus 4.7 (1M ctx) — D2: drop conversation history from prompt (3 sites)
9
+ # The 2026-05-16 pith→user-turn fix deployed cleanly (Run 49 confirmed:
10
+ # "My actual question:" label from the new template appearing IN BitNet
11
+ # output), but degeneracy persisted. Diagnosis: pollution feedback loop
12
+ # relocated from system slot to conversation history. BitNet's own prior
13
+ # degenerate responses were appended to nw_msgs/messages_nw as assistant
14
+ # turns; next turn's recent_window=6 pulled them back into context;
15
+ # BitNet kept echoing the pattern. Fix: drop the recent_window pull
16
+ # entirely. Prompt = [system, current user turn (with pith block)].
17
+ # No prior turns. nw_msgs/messages_nw still grows as a record (KISS
18
+ # still gets the full history for filtering) — the model only sees this
19
+ # turn. This is the architecturally-stated NuWave posture: "substrate
20
+ # carries continuity, not literal chat history" (per organism.py header).
21
+ # The recent_window=6 was always a pragmatic concession to model needs;
22
+ # removing it enforces the substrate-only-continuity design intent.
23
  # [2026-05-16] Claude Opus 4.7 (1M ctx) — Pith → user-turn labeled context block (3 sites)
24
  # Root cause of Run 48's 24/24 degenerate BitNet output: pith was being
25
  # injected into the system role slot via sys_ctx = "\n".join(pith) + sys.
 
835
  # ── 4. Pith bucket — extract relevant context from the River ──
836
  pith_context, pith_ids = organism.pith_extract_with_ids(message, max_context=5)
837
 
838
+ # D2 (2026-05-22): NO conversation history in the prompt.
839
+ # Substrate-only continuity per NuWave's design philosophy
840
+ # (organism.py header: "substrate carries continuity, not literal
841
+ # chat history"). The previous recent_window=6 was the source of
842
+ # the post-2026-05-16 degeneracy loopBitNet's own prior degenerate
843
+ # outputs in messages_nw assistant turns were being pulled back into
844
+ # next turn's prompt, BitNet kept echoing the pattern. Closing it:
845
+ # prompt = [system instructions, current user turn (with pith block)].
846
+ # messages_nw still grows (KISS filter_context reads it for sys_ctx
847
+ # derivation, conversation record persists); the model just doesn't
848
+ # see prior turns directly.
 
 
 
 
 
 
849
  if pith_context:
850
  pith_block = "\n".join(f" - {p}" for p in pith_context)
851
+ user_content = (
852
  "Some context that may be relevant (recalled from earlier "
853
  "related conversations; these are reference material, not "
854
  "questions to answer):\n"
855
  f"{pith_block}\n\n"
856
  f"My actual question: {message}"
857
  )
858
+ else:
859
+ user_content = message
 
860
 
861
  prompt_msgs = []
862
  if sys_ctx:
863
  prompt_msgs.append({"role": "system", "content": sys_ctx})
864
+ prompt_msgs.append({"role": "user", "content": user_content})
865
 
866
  prompt = tokenizer.apply_chat_template(
867
  prompt_msgs, tokenize=False, add_generation_prompt=True,
 
1083
  kiss_r = nw_kiss.filter_context(nw_msgs, system_prompt)
1084
  sys_ctx = kiss_r.get("system_context", system_prompt)
1085
 
1086
+ # Pith Born rule extraction from substrate.
 
 
1087
  pith_context = nw_organism.pith_extract(prompt_text, max_context=5)
1088
 
1089
+ # D2 (2026-05-22): NO conversation history in the prompt.
1090
+ # Substrate-only continuity per NuWave's design. nw_msgs still
1091
+ # grows (KISS reads it for sys_ctx); the model only sees this
1092
+ # turn's user message with the labeled pith context block.
 
 
 
 
 
 
 
 
 
1093
  if pith_context:
1094
  pith_block = "\n".join(f" - {p}" for p in pith_context)
1095
+ user_content = (
1096
  "Some context that may be relevant (recalled from earlier "
1097
  "related conversations; these are reference material, not "
1098
  "questions to answer):\n"
1099
  f"{pith_block}\n\n"
1100
  f"My actual question: {prompt_text}"
1101
  )
1102
+ else:
1103
+ user_content = prompt_text
1104
+
1105
+ prompt_msgs_nw = []
1106
+ if sys_ctx:
1107
+ prompt_msgs_nw.append({"role": "system", "content": sys_ctx})
1108
+ prompt_msgs_nw.append({"role": "user", "content": user_content})
1109
 
1110
  prompt_nw = tokenizer.apply_chat_template(
1111
+ prompt_msgs_nw, tokenize=False, add_generation_prompt=True,
 
1112
  )
1113
  resp_nw, in_nw, out_nw, time_nw, tps_nw, lenia_r = do_generate(prompt_nw, max_new_tokens=128)
1114
  nw_msgs.append({"role": "assistant", "content": resp_nw})
 
1469
 
1470
  kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
1471
  sys_ctx = kiss_r.get("system_context", system_prompt)
 
 
 
 
 
 
 
1472
 
1473
+ # D2 (2026-05-22): NO conversation history in the prompt.
1474
+ # Substrate-only continuity per NuWave's design philosophy.
1475
+ # nw_msgs still grows as a record (KISS reads it for sys_ctx
1476
+ # derivation just above); the model only sees this turn's user
1477
+ # message with the labeled pith context block.
1478
  if pith_context:
1479
  pith_block = "\n".join(f" - {p}" for p in pith_context)
1480
+ user_content = (
1481
  "Some context that may be relevant (recalled from earlier "
1482
  "related conversations; these are reference material, not "
1483
  "questions to answer):\n"
1484
  f"{pith_block}\n\n"
1485
  f"My actual question: {prompt_text}"
1486
  )
1487
+ else:
1488
+ user_content = prompt_text
1489
+
1490
+ prompt_msgs_iv = []
1491
+ if sys_ctx:
1492
+ prompt_msgs_iv.append({"role": "system", "content": sys_ctx})
1493
+ prompt_msgs_iv.append({"role": "user", "content": user_content})
1494
 
1495
  prompt_nw = tokenizer.apply_chat_template(
1496
+ prompt_msgs_iv, tokenize=False, add_generation_prompt=True,
 
1497
  )
1498
  resp_nw, in_nw, out_nw, time_nw, tps_nw, _ = do_generate(prompt_nw, max_new_tokens=128)
1499
  nw_msgs.append({"role": "assistant", "content": resp_nw})