AbstractIntegratedModule 1.0.2__tar.gz → 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.py +43 -71
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/README.md +5 -5
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/setup.py +1 -1
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/setup.cfg +0 -0
{abstractintegratedmodule-1.0.2 → abstractintegratedmodule-1.0.4}/AbstractIntegratedModule.py
RENAMED
|
@@ -778,7 +778,8 @@ class Transformer:
|
|
|
778
778
|
def apply_update(self, param, grad, lr):
|
|
779
779
|
# L2 weight decay applied directly at update time
|
|
780
780
|
# equivalent to: grad += weight_decay * param
|
|
781
|
-
|
|
781
|
+
update = param - lr * (grad + self.weight_decay * param)
|
|
782
|
+
return update
|
|
782
783
|
|
|
783
784
|
def dropout(self, x, rate=0.1, training=True, alpha=None):
|
|
784
785
|
if not training or rate == 0.0:
|
|
@@ -796,7 +797,7 @@ class Transformer:
|
|
|
796
797
|
return x * mask / (1.0 - effective_rate), mask
|
|
797
798
|
|
|
798
799
|
def _get_attn_scale(self, d_k):
|
|
799
|
-
"""Cache scale factor — d_k never changes at runtime."""
|
|
800
|
+
"""Cache scale factor — that d_k never changes at runtime."""
|
|
800
801
|
if self._attn_scale is None:
|
|
801
802
|
self._attn_scale = 1.0 / np.sqrt(d_k)
|
|
802
803
|
return self._attn_scale
|
|
@@ -2157,7 +2158,7 @@ class LSTMCell:
|
|
|
2157
2158
|
cs = np.zeros((T, H))
|
|
2158
2159
|
cache = []
|
|
2159
2160
|
|
|
2160
|
-
# preallocate xh buffer once
|
|
2161
|
+
# preallocate xh buffer once only here.
|
|
2161
2162
|
xh = np.empty(expected_input + H)
|
|
2162
2163
|
|
|
2163
2164
|
for t in range(T):
|
|
@@ -2403,7 +2404,7 @@ class LSTMEngine:
|
|
|
2403
2404
|
|
|
2404
2405
|
# confidence error — how wrong was the predicted probability
|
|
2405
2406
|
# correct prediction → low error
|
|
2406
|
-
# wrong prediction → high error
|
|
2407
|
+
# wrong prediction → high error in here.
|
|
2407
2408
|
err = np.abs(pred_prob - true_bin)
|
|
2408
2409
|
confidence_errors.extend(err.tolist())
|
|
2409
2410
|
|
|
@@ -2445,7 +2446,7 @@ class LSTMEngine:
|
|
|
2445
2446
|
b = cell.b
|
|
2446
2447
|
H1, H2, H3 = H, H * 2, H * 3 # slice boundaries precomputed
|
|
2447
2448
|
|
|
2448
|
-
#
|
|
2449
|
+
# Wy check once before loop
|
|
2449
2450
|
if self.model.Wy is None:
|
|
2450
2451
|
self.model.Wy = self.model.weight_shaper.weight_shaping(x_seq)
|
|
2451
2452
|
Wy = self.model.Wy
|
|
@@ -8124,7 +8125,7 @@ class AgentDistributedInference:
|
|
|
8124
8125
|
continue
|
|
8125
8126
|
|
|
8126
8127
|
if message.get('type') == 2: # PREDICT_RESPONSE
|
|
8127
|
-
continue #
|
|
8128
|
+
continue # Skipped
|
|
8128
8129
|
|
|
8129
8130
|
message = self._receive_message(client)
|
|
8130
8131
|
self.temporary_message = message
|
|
@@ -8629,7 +8630,7 @@ class AgentDistributedInference:
|
|
|
8629
8630
|
return response['prediction'], response['text']
|
|
8630
8631
|
return None, None
|
|
8631
8632
|
except Exception as e:
|
|
8632
|
-
print(f"Vote request failed: {e}")
|
|
8633
|
+
print(f"[-] Vote request failed: {e}")
|
|
8633
8634
|
return None, None
|
|
8634
8635
|
|
|
8635
8636
|
def sync_memory_with_agent(self, agent_id, memory_name, timeout=10):
|
|
@@ -9295,8 +9296,16 @@ class IntegratedPipeline:
|
|
|
9295
9296
|
self.error_decay = 0.85
|
|
9296
9297
|
self.performance_result = 1.0
|
|
9297
9298
|
|
|
9299
|
+
# === TRAINING SETUP ===
|
|
9298
9300
|
self.mlp_training_epochs = 2000
|
|
9301
|
+
self.mlp_lr = 0.1
|
|
9302
|
+
self.transformer_lr = 0.1
|
|
9303
|
+
self.transformer_d_model = 32
|
|
9304
|
+
self.transformer_heads = 4
|
|
9299
9305
|
self.transformer_training_epochs = 100
|
|
9306
|
+
self.lstm_training_epochs = 50
|
|
9307
|
+
self.lstm_lr = 5e-2
|
|
9308
|
+
self.lstm_hidden_dim = 64
|
|
9300
9309
|
|
|
9301
9310
|
# Main component setup
|
|
9302
9311
|
self.standard_scaler = StandardScaler()
|
|
@@ -9361,7 +9370,6 @@ class IntegratedPipeline:
|
|
|
9361
9370
|
self._prob_save_count = None
|
|
9362
9371
|
|
|
9363
9372
|
self.temperature = 1.0
|
|
9364
|
-
self.transformer_lr = 0.1
|
|
9365
9373
|
self.max_seq_len = 16
|
|
9366
9374
|
|
|
9367
9375
|
self.memory_name = memory_name
|
|
@@ -9970,8 +9978,8 @@ class IntegratedPipeline:
|
|
|
9970
9978
|
|
|
9971
9979
|
self.model2 = Transformer(
|
|
9972
9980
|
vocab_size=len(self.vocab),
|
|
9973
|
-
d_model=
|
|
9974
|
-
n_heads=
|
|
9981
|
+
d_model=self.transformer_d_model,
|
|
9982
|
+
n_heads=self.transformer_heads,
|
|
9975
9983
|
num_classes=num_classes
|
|
9976
9984
|
)
|
|
9977
9985
|
|
|
@@ -12559,7 +12567,7 @@ class IntegratedPipeline:
|
|
|
12559
12567
|
|
|
12560
12568
|
engine = self.lstm_engine
|
|
12561
12569
|
|
|
12562
|
-
self.lstm_engine.fit_stm(X, Y)
|
|
12570
|
+
self.lstm_engine.fit_stm(X, Y, epochs=self.lstm_training_epochs, hidden=self.lstm_hidden_dim, lr=self.lstm_lr)
|
|
12563
12571
|
engine.calibrate(X_val, Y_val)
|
|
12564
12572
|
|
|
12565
12573
|
print("\n[= LSTM INSIGHT =] Per-sample confidence report:")
|
|
@@ -12591,6 +12599,7 @@ class IntegratedPipeline:
|
|
|
12591
12599
|
print('[=+=] ==== STATUS REPORT ====')
|
|
12592
12600
|
print("\n[=] Confidence breakdown for sample 0:")
|
|
12593
12601
|
r = engine.predict(X_val[0], label_bins=label_bins)
|
|
12602
|
+
|
|
12594
12603
|
print(f" MC mean (last step) : {r['mc_mean'][-1]:+.4f}")
|
|
12595
12604
|
print(f" MC std (last step) : {r['mc_std'][-1]:.4f} "
|
|
12596
12605
|
f"← tight = certain")
|
|
@@ -12658,8 +12667,8 @@ class IntegratedPipeline:
|
|
|
12658
12667
|
num_classes = self._get_num_classes(label_map=label_map)
|
|
12659
12668
|
self.model2 = Transformer(
|
|
12660
12669
|
vocab_size=len(self.vocab),
|
|
12661
|
-
d_model=
|
|
12662
|
-
n_heads=
|
|
12670
|
+
d_model=self.transformer_d_model,
|
|
12671
|
+
n_heads=self.transformer_heads,
|
|
12663
12672
|
num_classes=num_classes
|
|
12664
12673
|
)
|
|
12665
12674
|
|
|
@@ -12691,7 +12700,7 @@ class IntegratedPipeline:
|
|
|
12691
12700
|
(n_samples, T, d_model) that the Transformer can process with
|
|
12692
12701
|
embedded=True.
|
|
12693
12702
|
|
|
12694
|
-
Strategy: split the feature dimension into d_model-sized windows.
|
|
12703
|
+
Strategy used: split the feature dimension into d_model-sized windows.
|
|
12695
12704
|
Each window becomes one timestep. This lets the Transformer's
|
|
12696
12705
|
attention mechanism find relationships BETWEEN feature windows,
|
|
12697
12706
|
not just within them — genuinely useful when X_provided has
|
|
@@ -12900,7 +12909,7 @@ class IntegratedPipeline:
|
|
|
12900
12909
|
|
|
12901
12910
|
self.lstm_setup_inference(X, y)
|
|
12902
12911
|
self.initialize_model_(X, input_dim, n_classes)
|
|
12903
|
-
self.model3.train(X, y, epochs=self.mlp_training_epochs, lr=
|
|
12912
|
+
self.model3.train(X, y, epochs=self.mlp_training_epochs, lr=self.mlp_lr)
|
|
12904
12913
|
|
|
12905
12914
|
if self.lstm_engine:
|
|
12906
12915
|
self.storage.save_weights(self.memory_name, model_type='Pipeline')
|
|
@@ -12927,8 +12936,8 @@ class IntegratedPipeline:
|
|
|
12927
12936
|
|
|
12928
12937
|
self.model2 = Transformer(
|
|
12929
12938
|
vocab_size=1,
|
|
12930
|
-
d_model=
|
|
12931
|
-
n_heads=
|
|
12939
|
+
d_model=self.transformer_d_model,
|
|
12940
|
+
n_heads=self.transformer_heads,
|
|
12932
12941
|
num_classes=num_classes
|
|
12933
12942
|
)
|
|
12934
12943
|
|
|
@@ -12969,6 +12978,8 @@ class IntegratedPipeline:
|
|
|
12969
12978
|
self.utility_MLP_set(self.X, y_true)
|
|
12970
12979
|
print('✅ Done Training MLP Model! ')
|
|
12971
12980
|
|
|
12981
|
+
|
|
12982
|
+
|
|
12972
12983
|
class AccurateAnswerCache:
|
|
12973
12984
|
def __init__(self, pipeline, similarity_threshold=0.85, max_size=500):
|
|
12974
12985
|
self.pipeline = pipeline
|
|
@@ -17356,7 +17367,7 @@ class PipelinePredictionManager:
|
|
|
17356
17367
|
if 'sec_predicted' in result:
|
|
17357
17368
|
sec_status = ": ✅" if result['sec_predicted'] == result['expected'] else ": ❌"
|
|
17358
17369
|
print(f"[=] Second Expectation: {result['expected']} || Model Answer: {sec_status}")
|
|
17359
|
-
if result['sec_predicted'] == result['expected']:
|
|
17370
|
+
if 'sec_predicted' in result and 'sec_confidence' in result and result['sec_predicted'] == result['expected']:
|
|
17360
17371
|
self.pipeline.accurate_cache_lookup.add_verified(
|
|
17361
17372
|
X_samples, input_ids,
|
|
17362
17373
|
result['sec_predicted'], result['sec_confidence'], result['sec_index'],
|
|
@@ -17723,7 +17734,17 @@ class ConsecutivePeerAgent:
|
|
|
17723
17734
|
print(f'[==] Peer result: {result['prediction']} With Confidence: {result['confidence']}')
|
|
17724
17735
|
|
|
17725
17736
|
if peer_results:
|
|
17726
|
-
best_peer = max(peer_results, key=lambda x: x['confidence'])
|
|
17737
|
+
best_peer = max(peer_results, key=lambda x: x['confidence'])
|
|
17738
|
+
if isinstance(peer_results[0], dict):
|
|
17739
|
+
total_weight = len(peer_addresses) + 1
|
|
17740
|
+
best_result = best_peer.get('prediction')
|
|
17741
|
+
best_confidence = min(best_peer.get('confidence') / total_weight, 1.0)
|
|
17742
|
+
|
|
17743
|
+
print(f"[ConsecutivePeerAgent] Using Ensemble prediction result is: {best_result} || With Confidence: ({best_confidence:.1%})")
|
|
17744
|
+
self.stats['predictions'] += 1
|
|
17745
|
+
|
|
17746
|
+
return best_peer
|
|
17747
|
+
|
|
17727
17748
|
if best_peer['confidence'] > local_result['confidence']:
|
|
17728
17749
|
best_result = best_peer
|
|
17729
17750
|
print(f"[ConsecutivePeerAgent] Using peer result: {best_peer['prediction']} || Confidence: ({best_peer['confidence']:.1%})")
|
|
@@ -18093,7 +18114,7 @@ class CohesiveAgentDeployment:
|
|
|
18093
18114
|
|
|
18094
18115
|
async def _prediction_worker(self, texts: list, api_key: str = None, client_ip: str = None) -> dict:
|
|
18095
18116
|
# Worker function for processing predictions
|
|
18096
|
-
#
|
|
18117
|
+
# runs in a thread pool via asyncio.to_thread
|
|
18097
18118
|
return self.async_manager.predict(
|
|
18098
18119
|
texts=texts,
|
|
18099
18120
|
timeout=self.pipeline.timeout,
|
|
@@ -18329,30 +18350,10 @@ class CohesiveAgentDeployment:
|
|
|
18329
18350
|
sock.close()
|
|
18330
18351
|
|
|
18331
18352
|
|
|
18332
|
-
async def _peer_health_monitor(self):
|
|
18333
|
-
# Monitor peer health and reconnect if needed
|
|
18334
|
-
logger.info("[💓] Peer health monitor started")
|
|
18335
|
-
|
|
18336
|
-
while not self._shutdown_event.is_set():
|
|
18337
|
-
await asyncio.sleep(30)
|
|
18338
|
-
|
|
18339
|
-
try:
|
|
18340
|
-
# Ping all connected peers
|
|
18341
|
-
alive_agents = self.pipeline.distribution.broadcast_ping()
|
|
18342
|
-
logger.info(f"[=+=] Connected peers: {len(alive_agents)}")
|
|
18343
|
-
|
|
18344
|
-
# Reconnect to known peers that went offline
|
|
18345
|
-
for peer_key, peer_info in self._known_peers.items():
|
|
18346
|
-
if not peer_info.get('connected', False):
|
|
18347
|
-
logger.info(f"[==] Attempting to reconnect to {peer_key}")
|
|
18348
|
-
await self._connect_to_peer(peer_info['host'], peer_info['port'])
|
|
18349
|
-
|
|
18350
|
-
except Exception as e:
|
|
18351
|
-
logger.error(f"[❌] Peer health monitor error: {e}")
|
|
18352
|
-
|
|
18353
18353
|
|
|
18354
18354
|
async def _health_monitor(self):
|
|
18355
18355
|
# Background health monitoring
|
|
18356
|
+
print("[💓] Peer health monitor started")
|
|
18356
18357
|
while not self._shutdown_event.is_set():
|
|
18357
18358
|
await asyncio.sleep(30)
|
|
18358
18359
|
|
|
@@ -18708,7 +18709,7 @@ class CohesiveAgentDeployment:
|
|
|
18708
18709
|
if already_connected:
|
|
18709
18710
|
continue
|
|
18710
18711
|
|
|
18711
|
-
# ✅
|
|
18712
|
+
# ✅ 4: Single connection attempt (NO RETRYS)
|
|
18712
18713
|
print(f"[=] Connecting to {peer_key}...")
|
|
18713
18714
|
|
|
18714
18715
|
try:
|
|
@@ -18781,35 +18782,6 @@ class CohesiveAgentDeployment:
|
|
|
18781
18782
|
logger.warning(f"[=-] Peer {agent_id} failed: {e}")
|
|
18782
18783
|
return None
|
|
18783
18784
|
|
|
18784
|
-
def _ensemble_predictions(self, local: dict, peers: list) -> dict:
|
|
18785
|
-
# Combine predictions from multiple agents
|
|
18786
|
-
try:
|
|
18787
|
-
print('[=+=] Initiating Ensemble weighting with: {peers} peers total')
|
|
18788
|
-
votes = defaultdict(float)
|
|
18789
|
-
votes[local.get('prediction', 'unknown')] += local.get('confidence', 0)
|
|
18790
|
-
|
|
18791
|
-
for peer in peers:
|
|
18792
|
-
if peer and isinstance(peer, dict):
|
|
18793
|
-
votes[peer.get('prediction', 'unknown')] += peer.get('confidence', 0)
|
|
18794
|
-
|
|
18795
|
-
best_pred = max(votes.items(), key=lambda x: x[1])
|
|
18796
|
-
|
|
18797
|
-
total_weight = len(peers) + 1
|
|
18798
|
-
return {
|
|
18799
|
-
'prediction': best_pred[0],
|
|
18800
|
-
'confidence': min(best_pred[1] / total_weight, 1.0),
|
|
18801
|
-
'local_prediction': local.get('prediction'),
|
|
18802
|
-
'local_confidence': local.get('confidence'),
|
|
18803
|
-
'peer_count': len(peers),
|
|
18804
|
-
'ensemble_votes': dict(votes)
|
|
18805
|
-
}
|
|
18806
|
-
except Exception as e:
|
|
18807
|
-
print(f'[-] Error in ensemble weighting; {e}, returning local prediction with 0.0 confidence')
|
|
18808
|
-
return {
|
|
18809
|
-
'prediction': local,
|
|
18810
|
-
'confidence': 0.0,
|
|
18811
|
-
'peer_count': 0.0,
|
|
18812
|
-
}
|
|
18813
18785
|
|
|
18814
18786
|
|
|
18815
18787
|
async def predict_batch_async(self, texts: List[str], api_key: str = None, client_ip: str = None) -> List[dict]:
|