CIE-Unified

git clone 

commit
12af7eb
parent
fabbb69
author
im_wower
date
2026-04-01 11:16:19 +0800 CST
integration phase2.3: 清理残留bwd_weight调用+收紧attention gate+context语义 (53/53)
4 files changed,  +23, -4
M cie/runtime.py
+15, -1
 1@@ -92,7 +92,21 @@ class CIERuntime:
 2             self._apply_signal(signal)
 3 
 4     def _apply_signal(self, signal):
 5-        """应用一个信号到图上"""
 6+        """
 7+        应用一个信号到图上。
 8+        
 9+        信号路径:
10+          - tokens: 主输入,注入节点+激活+bigram 边+Dirichlet cat0/cat1
11+          - context_tokens: 上下文,与主 tokens 建立弱关联边(不注入激活)
12+          - anchor_tokens: 锚点,高置信度 cat2 + 高势场
13+          - source="emit": 回灌信号,弱激活
14+          - polarity=-1: 负向信号,衰减+削弱置信度
15+        
16+        context 语义:context 提供"这段输入是在什么背景下出现的",
17+        和主 token 建立弱非对称边但不直接注入激活。
18+        这比完全忽略 context 更忠于 README 的"并行归位"概念——
19+        context 字符落在图的不同层级,为主 token 提供方向参照。
20+        """
21         tokens = signal.tokens
22         if not tokens:
23             return
M tests/formal_validation.py
+1, -1
1@@ -47,7 +47,7 @@ for stage, subj in combos:
2     for se in g.fwd_edges.values():
3         for dst, edge in se.items():
4             if "\u4e00" <= edge.src <= "\u9fff" and "\u4e00" <= dst <= "\u9fff":
5-                bwd = g.get_bwd_weight(edge.src, dst)
6+                bwd = g.get_bwd_weight(dst, edge.src)  # dst←src 反向权重
7                 ratio = edge.weight / bwd if bwd > 0.01 else edge.weight * 100
8                 cn_bg.append((edge.src+dst, round(ratio,1)))
9     cn_bg.sort(key=lambda x: -x[1])
M tests/test_comprehensive.py
+1, -1
1@@ -154,7 +154,7 @@ def test_A04_chuzhong_shuxue_formula():
2     total_edges = 0
3     for src_edges in rt.graph.fwd_edges.values():
4         for dst, edge in src_edges.items():
5-            bwd_w = rt.graph.get_bwd_weight(edge.src, dst)
6+            bwd_w = rt.graph.get_bwd_weight(dst, edge.src)  # dst←src 反向权重
7             if abs(edge.weight - bwd_w) > 0.01:
8                 asym_count += 1
9             total_edges += 1
M tests/test_kernel_sanity.py
+6, -1
 1@@ -118,7 +118,7 @@ def test_attention_mu_alignment():
 2         ratio = attn_used / mu_sum if mu_sum > 0 else float('inf')
 3         # attention 应该 >= mu(因为还包含已衰减但未释放的部分)
 4         # 但不应该差太多
 5-        assert 0.5 < ratio < 3.0, \
 6+        assert 0.7 < ratio < 2.0, \
 7             f"attention/mu drift: attn={attn_used:.2f}, mu={mu_sum:.2f}, ratio={ratio:.2f}"
 8 
 9     print(f"  PASS: attention/mu aligned — attn={attn_used:.2f}, mu={mu_sum:.2f}")
10@@ -139,6 +139,11 @@ def test_attention_no_unbounded_drift():
11         f"Attention went negative: free={attn.free:.2f}"
12 
13     mu_sum = sum(v for v in rt.state.mu.values() if v > 0)
14+    # Stricter: attention should track mu within 50%
15+    if mu_sum > 1.0:
16+        drift_ratio = attn.used / mu_sum
17+        assert 0.5 < drift_ratio < 2.0,             f"attention drifted: attn={attn.used:.2f}, mu={mu_sum:.2f}, ratio={drift_ratio:.2f}"
18+
19     print(f"  PASS: no unbounded drift after 20 rounds — "
20           f"attn_used={attn.used:.2f}, mu_sum={mu_sum:.2f}, free={attn.free:.2f}")
21