AbstractIntegratedModule 1.0.3__tar.gz → 1.0.5__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.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.py +202 -218
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/README.md +4 -4
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/setup.py +1 -1
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/setup.cfg +0 -0
{abstractintegratedmodule-1.0.3 → abstractintegratedmodule-1.0.5}/AbstractIntegratedModule.py
RENAMED
|
@@ -8125,7 +8125,7 @@ class AgentDistributedInference:
|
|
|
8125
8125
|
continue
|
|
8126
8126
|
|
|
8127
8127
|
if message.get('type') == 2: # PREDICT_RESPONSE
|
|
8128
|
-
continue #
|
|
8128
|
+
continue # Skipped
|
|
8129
8129
|
|
|
8130
8130
|
message = self._receive_message(client)
|
|
8131
8131
|
self.temporary_message = message
|
|
@@ -8630,7 +8630,7 @@ class AgentDistributedInference:
|
|
|
8630
8630
|
return response['prediction'], response['text']
|
|
8631
8631
|
return None, None
|
|
8632
8632
|
except Exception as e:
|
|
8633
|
-
print(f"Vote request failed: {e}")
|
|
8633
|
+
print(f"[-] Vote request failed: {e}")
|
|
8634
8634
|
return None, None
|
|
8635
8635
|
|
|
8636
8636
|
def sync_memory_with_agent(self, agent_id, memory_name, timeout=10):
|
|
@@ -16996,201 +16996,222 @@ class PipelinePredictionManager:
|
|
|
16996
16996
|
if isinstance(confidence, (np.ndarray, list)):
|
|
16997
16997
|
confidence = np.mean(confidence)
|
|
16998
16998
|
|
|
16999
|
-
|
|
16999
|
+
return_single_condition = (
|
|
17000
|
+
not self.pipeline.use_transformer or
|
|
17001
|
+
not need_ensemble_method
|
|
17000
17002
|
|
|
17001
|
-
|
|
17002
|
-
|
|
17003
|
-
|
|
17004
|
-
|
|
17005
|
-
|
|
17006
|
-
|
|
17007
|
-
|
|
17008
|
-
|
|
17009
|
-
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
if final_idx > len(reverse_map):
|
|
17017
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17018
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17019
|
-
final_idx = int(final_idx)
|
|
17020
|
-
|
|
17021
|
-
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17022
|
-
if chosen_label.startswith('unknown'):
|
|
17023
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17024
|
-
|
|
17025
|
-
try:
|
|
17026
|
-
print(final_probs)
|
|
17027
|
-
confidence = float(final_probs[final_idx])
|
|
17028
|
-
except:
|
|
17029
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17030
|
-
|
|
17031
|
-
elif self.pipeline.autonomous and need_peer_condition and attn_weights is not None:
|
|
17032
|
-
if agreement is None:
|
|
17033
|
-
agreement = False
|
|
17034
|
-
|
|
17035
|
-
print('[||] Iniating local peer output search in database for best output...')
|
|
17036
|
-
final_probs = self.pipeline.distribution._handle_peer_agent_request(final_probs, attn_weights, input_ids, type='DevicePeer', agreement=agreement)
|
|
17037
|
-
|
|
17038
|
-
final_idx = final_probs[0].argmax()
|
|
17039
|
-
original_idx = final_idx
|
|
17003
|
+
)
|
|
17004
|
+
if return_single_condition:
|
|
17005
|
+
print('[=] Displaying Results....')
|
|
17006
|
+
if not results[0].get('models_agree', True) and self.pipeline.use_transformer:
|
|
17007
|
+
trans_confidence = results[0].get('trans_confidence', 1e-8)
|
|
17008
|
+
confidence = (confidence + trans_confidence / 2) + 1e-5
|
|
17009
|
+
print(f'[=] Calibrating confidence around: {confidence:.1%} Due to disagreement between Transformer and MLP.')
|
|
17010
|
+
|
|
17011
|
+
print(f"\n[🎯] Predicted label: {chosen_label} || With Certain Confidence: {confidence:.1%}")
|
|
17012
|
+
payload = {
|
|
17013
|
+
'X_samples': X,
|
|
17014
|
+
'input_ids': input_ids
|
|
17015
|
+
}
|
|
17016
|
+
if titles is not None and len(titles) > 0:
|
|
17017
|
+
correct, sec_correct = self.display_hybrid_results(payload, final_class_idx, results, top_k, verbose=True)
|
|
17040
17018
|
|
|
17041
|
-
|
|
17042
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17043
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17044
|
-
final_idx = int(final_idx)
|
|
17019
|
+
return results, chosen_label, confidence
|
|
17045
17020
|
|
|
17046
|
-
|
|
17047
|
-
|
|
17048
|
-
|
|
17049
|
-
|
|
17050
|
-
|
|
17021
|
+
else:
|
|
17022
|
+
if results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold and not chosen_label.startswith("unknown"):
|
|
17023
|
+
print(f"\n[🎯] Proper Confidence of Final chosen label for input: {chosen_label} || Confidence: {confidence:.1%}")
|
|
17024
|
+
return results, chosen_label, confidence
|
|
17025
|
+
|
|
17026
|
+
# Only recalibrate if models disagreed
|
|
17027
|
+
elif results and not results[0].get('models_agree', True) or not self.pipeline.agreement and self.pipeline.use_transformer:
|
|
17051
17028
|
|
|
17029
|
+
need_peer_condition = not results[0].get('models_agree', True) and self.pipeline.peer_assistance_threshold > 0.3 and self.pipeline.use_transformer
|
|
17030
|
+
print("\n[⚠️] Disagreement detected between MLP and Transformer predictions. Usig calibrated probabilities for final decision.")
|
|
17031
|
+
if confidence < self.pipeline.confidence_threshold and need_peer_condition:
|
|
17032
|
+
print('|| Uncertain advanced prediction, requesting peer assistance if allowed...')
|
|
17033
|
+
final_probs = self.pipeline._handle_distributed_connections(final_probs, attn_weights, input_ids, agreement)
|
|
17052
17034
|
|
|
17053
|
-
elif not results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold:
|
|
17054
|
-
if final_confidence is not None and confidence < self.pipeline.confidence_threshold:
|
|
17055
|
-
print("\n[⚠️] Low confidence detected, but both models don't agree. Using calibrated probabilities for final decision to ensure robustness.")
|
|
17056
|
-
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17057
|
-
|
|
17058
17035
|
final_idx = final_probs[0].argmax()
|
|
17059
17036
|
original_idx = final_idx
|
|
17060
|
-
|
|
17037
|
+
|
|
17061
17038
|
if final_idx > len(reverse_map):
|
|
17062
17039
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17063
17040
|
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17064
17041
|
final_idx = int(final_idx)
|
|
17065
|
-
|
|
17066
|
-
|
|
17067
|
-
|
|
17068
|
-
|
|
17069
|
-
final_idx = final_probs[0].argmax()
|
|
17070
|
-
original_idx = final_idx
|
|
17071
|
-
if final_idx > len(reverse_map):
|
|
17042
|
+
|
|
17043
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17044
|
+
if chosen_label.startswith('unknown'):
|
|
17072
17045
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17073
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17074
|
-
final_idx = int(final_idx)
|
|
17075
17046
|
|
|
17076
|
-
|
|
17077
|
-
|
|
17078
|
-
|
|
17079
|
-
|
|
17080
|
-
|
|
17081
|
-
|
|
17082
|
-
|
|
17083
|
-
|
|
17084
|
-
|
|
17085
|
-
|
|
17086
|
-
|
|
17047
|
+
try:
|
|
17048
|
+
confidence = float(final_probs[final_idx])
|
|
17049
|
+
except:
|
|
17050
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17051
|
+
|
|
17052
|
+
elif self.pipeline.autonomous and need_peer_condition and attn_weights is not None:
|
|
17053
|
+
if agreement is None:
|
|
17054
|
+
agreement = False
|
|
17055
|
+
|
|
17056
|
+
print('[||] Iniating local peer output search in database for best output...')
|
|
17057
|
+
final_probs = self.pipeline.distribution._handle_peer_agent_request(final_probs, attn_weights, input_ids, type='DevicePeer', agreement=agreement)
|
|
17058
|
+
|
|
17087
17059
|
final_idx = final_probs[0].argmax()
|
|
17088
|
-
original_idx = final_idx
|
|
17060
|
+
original_idx = final_idx
|
|
17089
17061
|
|
|
17090
17062
|
if final_idx > len(reverse_map):
|
|
17091
17063
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17092
17064
|
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17093
|
-
final_idx = int(final_idx)
|
|
17065
|
+
final_idx = int(final_idx)
|
|
17094
17066
|
|
|
17095
17067
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17096
17068
|
try:
|
|
17097
|
-
confidence = float(final_probs[
|
|
17069
|
+
confidence = float(final_probs[final_idx])
|
|
17098
17070
|
except:
|
|
17099
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17100
|
-
else:
|
|
17101
|
-
if final_probs is None:
|
|
17102
|
-
final_probs = mlp_probs
|
|
17071
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17103
17072
|
|
|
17104
|
-
final_probs = self.calibration_penalized_check(final_probs, target_pred_indices[0])
|
|
17105
17073
|
|
|
17106
|
-
|
|
17074
|
+
elif not results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold:
|
|
17075
|
+
if final_confidence is not None and confidence < self.pipeline.confidence_threshold:
|
|
17076
|
+
print("\n[⚠️] Low confidence detected, but both models don't agree. Using calibrated probabilities for final decision to ensure robustness.")
|
|
17077
|
+
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17107
17078
|
|
|
17108
|
-
|
|
17109
|
-
|
|
17110
|
-
|
|
17111
|
-
final_idx
|
|
17112
|
-
|
|
17113
|
-
|
|
17079
|
+
final_idx = final_probs[0].argmax()
|
|
17080
|
+
original_idx = final_idx
|
|
17081
|
+
|
|
17082
|
+
if final_idx > len(reverse_map):
|
|
17083
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17084
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17085
|
+
final_idx = int(final_idx)
|
|
17086
|
+
else:
|
|
17087
|
+
print('[🎯] Stable confidence established, But both Models doesnt Agree, Re-evaluating...')
|
|
17088
|
+
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17089
|
+
|
|
17090
|
+
final_idx = final_probs[0].argmax()
|
|
17091
|
+
original_idx = final_idx
|
|
17092
|
+
if final_idx > len(reverse_map):
|
|
17093
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17094
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17095
|
+
final_idx = int(final_idx)
|
|
17114
17096
|
|
|
17115
17097
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17116
|
-
if final_probs is None:
|
|
17117
|
-
final_probs = target_probs.copy()
|
|
17118
|
-
|
|
17119
17098
|
try:
|
|
17099
|
+
confidence = float(final_probs[0][final_idx])
|
|
17100
|
+
except:
|
|
17101
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17102
|
+
else:
|
|
17103
|
+
if self.pipeline.use_transformer and need_ensemble_method:
|
|
17104
|
+
print("\n[⚠️] Uncertain confidence and disagreement detected. Using ensemble method for final decision.")
|
|
17105
|
+
input_forward = sequence_ids if sequence_ids is not None else input_ids
|
|
17106
|
+
final_probs, details = self.pipeline.ensemble.predict_ensemble(input_forward, X, y, method='dynamic', embedded=use_embedded)
|
|
17107
|
+
|
|
17108
|
+
final_idx = final_probs[0].argmax()
|
|
17109
|
+
original_idx = final_idx
|
|
17110
|
+
|
|
17111
|
+
if final_idx > len(reverse_map):
|
|
17112
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17113
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17114
|
+
final_idx = int(final_idx)
|
|
17115
|
+
|
|
17116
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17120
17117
|
try:
|
|
17121
17118
|
confidence = float(final_probs[0][final_idx])
|
|
17122
17119
|
except:
|
|
17123
17120
|
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17124
|
-
|
|
17121
|
+
else:
|
|
17122
|
+
if final_probs is None:
|
|
17123
|
+
final_probs = mlp_probs
|
|
17124
|
+
|
|
17125
|
+
final_probs = self.calibration_penalized_check(final_probs, target_pred_indices[0])
|
|
17126
|
+
|
|
17127
|
+
final_idx = final_probs[0].argmax() if final_probs is not None else target_probs[0].argmax()
|
|
17128
|
+
|
|
17129
|
+
original_idx = final_idx
|
|
17130
|
+
|
|
17131
|
+
if final_idx > len(reverse_map):
|
|
17132
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17133
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17134
|
+
final_idx = int(final_idx)
|
|
17135
|
+
|
|
17136
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17137
|
+
if final_probs is None:
|
|
17138
|
+
final_probs = target_probs.copy()
|
|
17139
|
+
|
|
17125
17140
|
try:
|
|
17126
|
-
|
|
17141
|
+
try:
|
|
17142
|
+
confidence = float(final_probs[0][final_idx])
|
|
17143
|
+
except:
|
|
17144
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17127
17145
|
except:
|
|
17128
|
-
|
|
17146
|
+
try:
|
|
17147
|
+
confidence = float(final_probs[final_idx])
|
|
17148
|
+
except:
|
|
17149
|
+
confidence = self.pipeline.confidence_threshold
|
|
17150
|
+
|
|
17151
|
+
elif confidence < self.pipeline.confidence_threshold and not self.pipeline.agreement and not results[0].get('models_agree', True):
|
|
17152
|
+
if trans_probs is not None:
|
|
17153
|
+
prob_entropy = self.calculate_entropy(final_probs)
|
|
17154
|
+
normalized_entropy = prob_entropy / np.log(prob_entropy.shape[-1]) if prob_entropy.shape[-1] > 1 else 0
|
|
17155
|
+
attn_quality = 1.0 / (1.0 + np.exp(-attn_weights.mean()) + eps) if attn_weights is not None else 0.5
|
|
17156
|
+
anisotropy = self.pipeline.anisotropy_measurement(attn_weights.mean() if attn_weights is not None else 0.5)
|
|
17129
17157
|
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
|
|
17134
|
-
|
|
17135
|
-
|
|
17158
|
+
else:
|
|
17159
|
+
normalized_entropy = self.calculate_entropy(input_ids) # Max entropy for uniform distribution
|
|
17160
|
+
attn_quality = self.pipeline.confidence_threshold
|
|
17161
|
+
anisotropy = self.anisotropy_measurement(input_ids) if hasattr(self.pipeline, 'anisotropy_measurement') else 0.5
|
|
17162
|
+
|
|
17163
|
+
mean_entropy = np.mean(normalized_entropy)
|
|
17164
|
+
|
|
17165
|
+
use_simple_prediction = (
|
|
17166
|
+
anisotropy < 0.3 or
|
|
17167
|
+
mean_entropy < 0.5 or # High uncertainty
|
|
17168
|
+
results[0].get('confidence', 0) < 0.4 or # Low confidence
|
|
17169
|
+
not results[0].get('models_agree', True) or # Disagreement
|
|
17170
|
+
attn_quality < 0.4
|
|
17171
|
+
)
|
|
17136
17172
|
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17143
|
-
|
|
17144
|
-
use_simple_prediction = (
|
|
17145
|
-
anisotropy < 0.3 or
|
|
17146
|
-
mean_entropy < 0.5 or # High uncertainty
|
|
17147
|
-
results[0].get('confidence', 0) < 0.4 or # Low confidence
|
|
17148
|
-
not results[0].get('models_agree', True) or # Disagreement
|
|
17149
|
-
attn_quality < 0.4
|
|
17150
|
-
)
|
|
17173
|
+
if use_simple_prediction:
|
|
17174
|
+
print("\n[⚡] Condition is poorly unviable to handle agreement. Using robust prediction method for better reliability.")
|
|
17175
|
+
predicted_label, confidence = self.simple_pass_prediction(self.pipeline, titles=titles, label_map=label_map, X_raw=X, y=y, show_proba=show_proba, top_k=top_k)
|
|
17176
|
+
if predicted_label is not None:
|
|
17177
|
+
print(f"\n[🎯] Robust prediction result: {predicted_label} with confidence {confidence:.1%}")
|
|
17178
|
+
return _, predicted_label, confidence
|
|
17151
17179
|
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17180
|
+
else:
|
|
17181
|
+
final_idx = final_probs[0].argmax()
|
|
17182
|
+
original_idx = final_idx
|
|
17183
|
+
|
|
17184
|
+
if final_idx > len(reverse_map):
|
|
17185
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17186
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17187
|
+
final_idx = int(final_idx)
|
|
17188
|
+
|
|
17189
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17190
|
+
if final_probs is not None:
|
|
17191
|
+
try:
|
|
17192
|
+
confidence = float(final_probs[0][final_idx])
|
|
17193
|
+
except:
|
|
17194
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17195
|
+
|
|
17196
|
+
else:
|
|
17197
|
+
final_probs = target_probs.copy()
|
|
17158
17198
|
|
|
17159
17199
|
else:
|
|
17200
|
+
print("\n[🎯] Using initial Regular final prediction as final decision.")
|
|
17160
17201
|
final_idx = final_probs[0].argmax()
|
|
17161
|
-
original_idx = final_idx
|
|
17162
17202
|
|
|
17163
17203
|
if final_idx > len(reverse_map):
|
|
17164
17204
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17165
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17166
|
-
final_idx = int(final_idx)
|
|
17205
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17206
|
+
final_idx = int(final_idx)
|
|
17167
17207
|
|
|
17168
17208
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17169
|
-
if final_probs is not None:
|
|
17170
|
-
try:
|
|
17171
|
-
confidence = float(final_probs[0][final_idx])
|
|
17172
|
-
except:
|
|
17173
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17174
|
-
|
|
17175
|
-
else:
|
|
17176
|
-
final_probs = target_probs.copy()
|
|
17177
|
-
|
|
17178
|
-
else:
|
|
17179
|
-
print("\n[🎯] Using initial Regular final prediction as final decision.")
|
|
17180
|
-
final_idx = final_probs[0].argmax()
|
|
17181
|
-
|
|
17182
|
-
if final_idx > len(reverse_map):
|
|
17183
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17184
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17185
|
-
final_idx = int(final_idx)
|
|
17186
17209
|
|
|
17187
|
-
|
|
17188
|
-
|
|
17189
|
-
|
|
17190
|
-
|
|
17191
|
-
|
|
17192
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17193
|
-
|
|
17210
|
+
try:
|
|
17211
|
+
confidence = float(final_probs[0][final_idx])
|
|
17212
|
+
except:
|
|
17213
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17214
|
+
|
|
17194
17215
|
if confidence > 0.8:
|
|
17195
17216
|
confidence = (confidence + performance_score) / 2
|
|
17196
17217
|
print(f'[⚡] Confidence calibrated to be around: {confidence}')
|
|
@@ -17198,7 +17219,7 @@ class PipelinePredictionManager:
|
|
|
17198
17219
|
if isinstance(chosen_label, str) and chosen_label.startswith("unknown") or float(confidence) < self.pipeline.confidence_threshold:
|
|
17199
17220
|
if chosen_label.startswith("unknown"):
|
|
17200
17221
|
chosen_label = 'Unknown'
|
|
17201
|
-
confidence = 1.0 - confidence #
|
|
17222
|
+
confidence = 1.0 - confidence #Invert confidence for unknown class
|
|
17202
17223
|
|
|
17203
17224
|
print(f"\n[⚠️] Final prediction is {chosen_label} with uncertain confidence: {confidence:.1%}. Consider more consistent data for the model to learn from.")
|
|
17204
17225
|
else:
|
|
@@ -17367,7 +17388,7 @@ class PipelinePredictionManager:
|
|
|
17367
17388
|
if 'sec_predicted' in result:
|
|
17368
17389
|
sec_status = ": ✅" if result['sec_predicted'] == result['expected'] else ": ❌"
|
|
17369
17390
|
print(f"[=] Second Expectation: {result['expected']} || Model Answer: {sec_status}")
|
|
17370
|
-
if result['sec_predicted'] == result['expected']:
|
|
17391
|
+
if 'sec_predicted' in result and 'sec_confidence' in result and result['sec_predicted'] == result['expected']:
|
|
17371
17392
|
self.pipeline.accurate_cache_lookup.add_verified(
|
|
17372
17393
|
X_samples, input_ids,
|
|
17373
17394
|
result['sec_predicted'], result['sec_confidence'], result['sec_index'],
|
|
@@ -17380,15 +17401,17 @@ class PipelinePredictionManager:
|
|
|
17380
17401
|
self.error_counts[result.get('predicted_idx')] += 1.0
|
|
17381
17402
|
|
|
17382
17403
|
if result['predicted'] == result['expected']:
|
|
17383
|
-
if result['sec_index'] is None:
|
|
17404
|
+
if 'sec_index' in result and result['sec_index'] is None:
|
|
17384
17405
|
result['sec_index'] = None
|
|
17385
17406
|
|
|
17386
|
-
|
|
17387
|
-
|
|
17388
|
-
|
|
17389
|
-
|
|
17407
|
+
if 'predicted_idx' in result and 'confidence' in result and 'predicted' in result:
|
|
17408
|
+
self.pipeline.accurate_cache_lookup.add_verified(
|
|
17409
|
+
X_samples, input_ids,
|
|
17410
|
+
result['predicted'], result['confidence'], result['predicted_idx'],
|
|
17411
|
+
source='automatic_verified')
|
|
17390
17412
|
|
|
17391
|
-
|
|
17413
|
+
correct += 1
|
|
17414
|
+
|
|
17392
17415
|
else:
|
|
17393
17416
|
error += 1
|
|
17394
17417
|
if isinstance(self.error_counts[result.get('predicted_idx')], (int, float)):
|
|
@@ -17716,7 +17739,7 @@ class ConsecutivePeerAgent:
|
|
|
17716
17739
|
|
|
17717
17740
|
best_result = local_result
|
|
17718
17741
|
|
|
17719
|
-
# Step 2: If low confidence,
|
|
17742
|
+
# Step 2: If low confidence, asking peers
|
|
17720
17743
|
if local_result['confidence'] < confidence_threshold and peer_addresses or peer_addresses:
|
|
17721
17744
|
if local_result['confidence'] < confidence_threshold:
|
|
17722
17745
|
print(f"[ConsecutivePeerAgent] Low confidence, asking {len(peer_addresses)} peers...")
|
|
@@ -17734,7 +17757,17 @@ class ConsecutivePeerAgent:
|
|
|
17734
17757
|
print(f'[==] Peer result: {result['prediction']} With Confidence: {result['confidence']}')
|
|
17735
17758
|
|
|
17736
17759
|
if peer_results:
|
|
17737
|
-
best_peer = max(peer_results, key=lambda x: x['confidence'])
|
|
17760
|
+
best_peer = max(peer_results, key=lambda x: x['confidence'])
|
|
17761
|
+
if isinstance(peer_results[0], dict):
|
|
17762
|
+
total_weight = len(peer_addresses) + 1
|
|
17763
|
+
best_result = best_peer.get('prediction')
|
|
17764
|
+
best_confidence = min(best_peer.get('confidence') / total_weight, 1.0)
|
|
17765
|
+
|
|
17766
|
+
print(f"[ConsecutivePeerAgent] Using Ensemble prediction result is: {best_result} || With Confidence: ({best_confidence:.1%})")
|
|
17767
|
+
self.stats['predictions'] += 1
|
|
17768
|
+
|
|
17769
|
+
return best_peer
|
|
17770
|
+
|
|
17738
17771
|
if best_peer['confidence'] > local_result['confidence']:
|
|
17739
17772
|
best_result = best_peer
|
|
17740
17773
|
print(f"[ConsecutivePeerAgent] Using peer result: {best_peer['prediction']} || Confidence: ({best_peer['confidence']:.1%})")
|
|
@@ -18104,7 +18137,7 @@ class CohesiveAgentDeployment:
|
|
|
18104
18137
|
|
|
18105
18138
|
async def _prediction_worker(self, texts: list, api_key: str = None, client_ip: str = None) -> dict:
|
|
18106
18139
|
# Worker function for processing predictions
|
|
18107
|
-
#
|
|
18140
|
+
# runs in a thread pool via asyncio.to_thread
|
|
18108
18141
|
return self.async_manager.predict(
|
|
18109
18142
|
texts=texts,
|
|
18110
18143
|
timeout=self.pipeline.timeout,
|
|
@@ -18319,11 +18352,11 @@ class CohesiveAgentDeployment:
|
|
|
18319
18352
|
|
|
18320
18353
|
# Send heartbeat to check connection
|
|
18321
18354
|
try:
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18355
|
+
self.pipeline.distribution._send_message(
|
|
18356
|
+
sock, {'type': 'PING', 'timestamp': time.time()}
|
|
18357
|
+
)
|
|
18358
|
+
sock.getpeername()
|
|
18359
|
+
print(f'[==] Peer name: {sock.getpeername()}')
|
|
18327
18360
|
except:
|
|
18328
18361
|
logger.warning(f"[-] Peer {peer_host}:{peer_port} disconnected")
|
|
18329
18362
|
break
|
|
@@ -18340,30 +18373,10 @@ class CohesiveAgentDeployment:
|
|
|
18340
18373
|
sock.close()
|
|
18341
18374
|
|
|
18342
18375
|
|
|
18343
|
-
async def _peer_health_monitor(self):
|
|
18344
|
-
# Monitor peer health and reconnect if needed
|
|
18345
|
-
logger.info("[💓] Peer health monitor started")
|
|
18346
|
-
|
|
18347
|
-
while not self._shutdown_event.is_set():
|
|
18348
|
-
await asyncio.sleep(30)
|
|
18349
|
-
|
|
18350
|
-
try:
|
|
18351
|
-
# Ping all connected peers
|
|
18352
|
-
alive_agents = self.pipeline.distribution.broadcast_ping()
|
|
18353
|
-
logger.info(f"[=+=] Connected peers: {len(alive_agents)}")
|
|
18354
|
-
|
|
18355
|
-
# Reconnect to known peers that went offline
|
|
18356
|
-
for peer_key, peer_info in self._known_peers.items():
|
|
18357
|
-
if not peer_info.get('connected', False):
|
|
18358
|
-
logger.info(f"[==] Attempting to reconnect to {peer_key}")
|
|
18359
|
-
await self._connect_to_peer(peer_info['host'], peer_info['port'])
|
|
18360
|
-
|
|
18361
|
-
except Exception as e:
|
|
18362
|
-
logger.error(f"[❌] Peer health monitor error: {e}")
|
|
18363
|
-
|
|
18364
18376
|
|
|
18365
18377
|
async def _health_monitor(self):
|
|
18366
18378
|
# Background health monitoring
|
|
18379
|
+
print("[💓] Peer health monitor started")
|
|
18367
18380
|
while not self._shutdown_event.is_set():
|
|
18368
18381
|
await asyncio.sleep(30)
|
|
18369
18382
|
|
|
@@ -18719,7 +18732,7 @@ class CohesiveAgentDeployment:
|
|
|
18719
18732
|
if already_connected:
|
|
18720
18733
|
continue
|
|
18721
18734
|
|
|
18722
|
-
# ✅
|
|
18735
|
+
# ✅ 4: Single connection attempt (NO RETRYS)
|
|
18723
18736
|
print(f"[=] Connecting to {peer_key}...")
|
|
18724
18737
|
|
|
18725
18738
|
try:
|
|
@@ -18792,35 +18805,6 @@ class CohesiveAgentDeployment:
|
|
|
18792
18805
|
logger.warning(f"[=-] Peer {agent_id} failed: {e}")
|
|
18793
18806
|
return None
|
|
18794
18807
|
|
|
18795
|
-
def _ensemble_predictions(self, local: dict, peers: list) -> dict:
|
|
18796
|
-
# Combine predictions from multiple agents
|
|
18797
|
-
try:
|
|
18798
|
-
print('[=+=] Initiating Ensemble weighting with: {peers} peers total')
|
|
18799
|
-
votes = defaultdict(float)
|
|
18800
|
-
votes[local.get('prediction', 'unknown')] += local.get('confidence', 0)
|
|
18801
|
-
|
|
18802
|
-
for peer in peers:
|
|
18803
|
-
if peer and isinstance(peer, dict):
|
|
18804
|
-
votes[peer.get('prediction', 'unknown')] += peer.get('confidence', 0)
|
|
18805
|
-
|
|
18806
|
-
best_pred = max(votes.items(), key=lambda x: x[1])
|
|
18807
|
-
|
|
18808
|
-
total_weight = len(peers) + 1
|
|
18809
|
-
return {
|
|
18810
|
-
'prediction': best_pred[0],
|
|
18811
|
-
'confidence': min(best_pred[1] / total_weight, 1.0),
|
|
18812
|
-
'local_prediction': local.get('prediction'),
|
|
18813
|
-
'local_confidence': local.get('confidence'),
|
|
18814
|
-
'peer_count': len(peers),
|
|
18815
|
-
'ensemble_votes': dict(votes)
|
|
18816
|
-
}
|
|
18817
|
-
except Exception as e:
|
|
18818
|
-
print(f'[-] Error in ensemble weighting; {e}, returning local prediction with 0.0 confidence')
|
|
18819
|
-
return {
|
|
18820
|
-
'prediction': local,
|
|
18821
|
-
'confidence': 0.0,
|
|
18822
|
-
'peer_count': 0.0,
|
|
18823
|
-
}
|
|
18824
18808
|
|
|
18825
18809
|
|
|
18826
18810
|
async def predict_batch_async(self, texts: List[str], api_key: str = None, client_ip: str = None) -> List[dict]:
|