AbstractIntegratedModule 0.4.5__tar.gz → 0.4.6__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-0.4.6/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6/AbstractIntegratedModule.egg-info}/PKG-INFO +12 -5
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.py +267 -147
- {abstractintegratedmodule-0.4.5/AbstractIntegratedModule.egg-info → abstractintegratedmodule-0.4.6}/PKG-INFO +12 -5
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/README.md +11 -4
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/setup.py +1 -1
- abstractintegratedmodule-0.4.5/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/MANIFEST.in +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/pyproject.toml +0 -0
- {abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/setup.cfg +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.6
|
|
4
4
|
Summary: Framework for Advanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: hernikpuspita5@gmail.com
|
|
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
42
42
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
43
43
|
|
|
44
44
|
### Library Short Description:
|
|
45
|
-
- Development Stage: Beta, 0.4.
|
|
45
|
+
- Development Stage: Beta, 0.4.6.
|
|
46
46
|
- Maintainer: Micro-Novelty.
|
|
47
47
|
- library Source-Code is Open-sourced on github.
|
|
48
48
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
@@ -379,6 +379,10 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP + LSTM usin
|
|
|
379
379
|
|
|
380
380
|
### Both performance Overview
|
|
381
381
|
<img width="1536" height="1024" alt="WhatsApp Image 2026-05-24 at 10 27 00" src="https://github.com/user-attachments/assets/9404277f-281f-4893-8367-e494833230ea" />
|
|
382
|
+
_______________________________________
|
|
383
|
+
- Note:
|
|
384
|
+
- This performance metric was calculated in older versions, With newer Transformers that has more, newer modules, The resulting cpu consumed may Increase 1.5 - 2x much more in Docker ARM64 Environment + QEMU,
|
|
385
|
+
MLP And LSTM stays the same and still fully optimized.
|
|
382
386
|
|
|
383
387
|
## Source code of AbstractIntegratedModule
|
|
384
388
|
- Note: The source code is provided in the repository.
|
|
@@ -650,7 +654,8 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
650
654
|
|
|
651
655
|
async_manager.start(method='Transformer_included', bootstrap_token=None) # boothstrap token is optional for better security
|
|
652
656
|
|
|
653
|
-
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'use_transformer': True}
|
|
657
|
+
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'X': None, 'y':None, 'use_transformer': True} # all samples needed for advanced prediction method. (X and y are optional samples)
|
|
658
|
+
|
|
654
659
|
regular_predict = async_manager.predict(
|
|
655
660
|
texts=texts,
|
|
656
661
|
timeout=60,
|
|
@@ -660,7 +665,9 @@ regular_predict = async_manager.predict(
|
|
|
660
665
|
# with retries: async_manager.predict(texts, timeout=60, retries=5, api_key=secret_key) # 5 times retry if failed
|
|
661
666
|
|
|
662
667
|
print('[==] Initiating advanced batch prediction')
|
|
663
|
-
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
668
|
+
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
669
|
+
X=None, y=None, # provide your initialized X and y samples (Also Optional, can be set to None)
|
|
670
|
+
secret_key=secret_key, client_ip=None) # you can add client_ip to provide a robust authentication paired with secret_key
|
|
664
671
|
# for better and faster advanced prediction, consider using advanced batch prediction like in the above example
|
|
665
672
|
|
|
666
673
|
```
|
|
@@ -766,7 +773,7 @@ try:
|
|
|
766
773
|
api_key = agent1.get_api_key()
|
|
767
774
|
print(f"\n🔑 Using API Key: {api_key[:20]}...")
|
|
768
775
|
|
|
769
|
-
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
776
|
+
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, 'X': None, "y":None, "use_transformer": True, "agent_id": agent_id} # (X and y are optional samples here too)
|
|
770
777
|
|
|
771
778
|
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
772
779
|
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
{abstractintegratedmodule-0.4.5 → abstractintegratedmodule-0.4.6}/AbstractIntegratedModule.py
RENAMED
|
@@ -388,10 +388,11 @@ class GeometricWeightShaping:
|
|
|
388
388
|
gradient = np.gradient(x)
|
|
389
389
|
except:
|
|
390
390
|
subnet = x[:min(10, x.shape[0]), :min(10, x.shape[1])]
|
|
391
|
-
gradient = np.gradient(subnet.flatten())
|
|
392
|
-
|
|
391
|
+
gradient = np.gradient(subnet.flatten())
|
|
392
|
+
|
|
393
393
|
val = [np.linalg.norm(v) for v in gradient]
|
|
394
394
|
anisotropy = np.std(val) / np.mean(val) + eps
|
|
395
|
+
|
|
395
396
|
return anisotropy
|
|
396
397
|
|
|
397
398
|
# weight shaping provides directional context in which how the data should be processed in order to align with the data geometry
|
|
@@ -859,8 +860,10 @@ class Transformer:
|
|
|
859
860
|
d_ffn1 = np.sum(np.matmul(self.cache['ffn_input'].transpose(0, 2, 1), d_ffn_pre), axis=0)
|
|
860
861
|
|
|
861
862
|
# Layer norm 1 gradient
|
|
862
|
-
d_ln1 = self.layer_norm_backward(
|
|
863
|
-
|
|
863
|
+
d_ln1 = self.layer_norm_backward(
|
|
864
|
+
d_prev, self.cache['x_ln1_input'], self.ln1_scale, self.ln1_shift
|
|
865
|
+
)
|
|
866
|
+
|
|
864
867
|
d_residual = d_ln1
|
|
865
868
|
d_attn = d_ln1
|
|
866
869
|
dx = d_prev + d_residual
|
|
@@ -950,7 +953,12 @@ class Transformer:
|
|
|
950
953
|
|
|
951
954
|
def smoothing_labels_utility(self, y_true, smoothing=0.1):
|
|
952
955
|
# y_true: (B, num_classes) one-hot
|
|
953
|
-
|
|
956
|
+
try:
|
|
957
|
+
num_classes = y_true.shape[1]
|
|
958
|
+
except:
|
|
959
|
+
y_true_2d = y_true.reshape(-1, 1)
|
|
960
|
+
num_classes = y_true_2d.shape[1]
|
|
961
|
+
|
|
954
962
|
return y_true * (1.0 - smoothing) + smoothing / num_classes
|
|
955
963
|
|
|
956
964
|
def learning_rate_warm_up(self, epoch, epochs, lr_base, schedule='cosine_warmup', warmup_frac=0.1):
|
|
@@ -997,6 +1005,10 @@ class Transformer:
|
|
|
997
1005
|
|
|
998
1006
|
|
|
999
1007
|
def train_step(self, input_ids, epoch, y_true, lr=0.01, mode=None, embedded=False, max_norm=1.0, pad_token_id=0):
|
|
1008
|
+
y_true = np.asarray(y_true)
|
|
1009
|
+
if len(y_true.shape) < 2:
|
|
1010
|
+
y_true = y_true.reshape(-1, 1)
|
|
1011
|
+
|
|
1000
1012
|
if not embedded and input_ids.ndim == 1:
|
|
1001
1013
|
input_ids = input_ids[np.newaxis, :] # (1, T), single sample
|
|
1002
1014
|
if y_true.ndim == 1:
|
|
@@ -1138,13 +1150,13 @@ class Transformer:
|
|
|
1138
1150
|
def anisotropy_measurement(self, x):
|
|
1139
1151
|
eps = 1e-5
|
|
1140
1152
|
try:
|
|
1141
|
-
gradient = np.gradient(x
|
|
1153
|
+
gradient = np.gradient(x)
|
|
1142
1154
|
except:
|
|
1143
|
-
|
|
1144
|
-
gradient = np.gradient(
|
|
1155
|
+
subnet = x[:min(10, x.shape[0]), :min(10, x.shape[1])]
|
|
1156
|
+
gradient = np.gradient(subnet.flatten())
|
|
1145
1157
|
|
|
1146
1158
|
val = [np.linalg.norm(v) for v in gradient]
|
|
1147
|
-
anisotropy = np.std(val) / np.mean(val) + eps
|
|
1159
|
+
anisotropy = np.std(val) / np.mean(val) + eps
|
|
1148
1160
|
|
|
1149
1161
|
return anisotropy
|
|
1150
1162
|
|
|
@@ -1379,14 +1391,13 @@ class MLP:
|
|
|
1379
1391
|
def anisotropy_measurement(self, x):
|
|
1380
1392
|
eps = 1e-5
|
|
1381
1393
|
try:
|
|
1382
|
-
gradient = np.gradient(x
|
|
1394
|
+
gradient = np.gradient(x)
|
|
1383
1395
|
except:
|
|
1384
|
-
|
|
1385
|
-
gradient = np.gradient(
|
|
1396
|
+
subnet = x[:min(10, x.shape[0]), :min(10, x.shape[1])]
|
|
1397
|
+
gradient = np.gradient(subnet.flatten())
|
|
1386
1398
|
|
|
1387
1399
|
val = [np.linalg.norm(v) for v in gradient]
|
|
1388
1400
|
anisotropy = np.std(val) / np.mean(val) + eps
|
|
1389
|
-
|
|
1390
1401
|
return anisotropy
|
|
1391
1402
|
|
|
1392
1403
|
|
|
@@ -2484,10 +2495,40 @@ class WeightedEnsemblePredictor:
|
|
|
2484
2495
|
|
|
2485
2496
|
def anisotropy_measurement(self, x):
|
|
2486
2497
|
eps = 1e-5
|
|
2487
|
-
|
|
2498
|
+
try:
|
|
2499
|
+
try:
|
|
2500
|
+
grads = np.gradient(x)
|
|
2501
|
+
# Stack gradients into a single array of vectors and find the norm of each
|
|
2502
|
+
# automatically handles multi-dimensional arrays (e.g., 2D, 3D volumes)
|
|
2503
|
+
stacked_grads = np.stack(grads, axis=-1)
|
|
2504
|
+
norms = np.linalg.norm(stacked_grads, axis=-1)
|
|
2505
|
+
|
|
2506
|
+
# Safely filter out potential NaNs or infs (common at array boundaries)
|
|
2507
|
+
valid_norms = norms[np.isfinite(norms)]
|
|
2508
|
+
|
|
2509
|
+
if len(valid_norms) == 0:
|
|
2510
|
+
return 0.0 # Return zero or appropriate default if no valid values exist
|
|
2511
|
+
|
|
2512
|
+
# Calculate statistics using the clean data
|
|
2513
|
+
std_val = np.std(valid_norms)
|
|
2514
|
+
mean_val = np.mean(valid_norms)
|
|
2515
|
+
|
|
2516
|
+
anisotropy = std_val / (mean_val + eps)
|
|
2517
|
+
if np.isnan(anisotropy) or np.isinf(anisotropy):
|
|
2518
|
+
anisotropy = self.pipeline.confidence_threshold
|
|
2519
|
+
except:
|
|
2520
|
+
try:
|
|
2521
|
+
gradient = np.gradient(x)
|
|
2522
|
+
except:
|
|
2523
|
+
subnet = x[:min(10, x.shape[0]), :min(10, x.shape[1])]
|
|
2524
|
+
gradient = np.gradient(subnet.flatten())
|
|
2525
|
+
|
|
2526
|
+
val = [np.linalg.norm(v) for v in gradient]
|
|
2527
|
+
anisotropy = np.std(val) / np.mean(val) + eps
|
|
2528
|
+
except Exception as e:
|
|
2529
|
+
print(f'[!] Cant calculate anisotropy due to: {e}')
|
|
2530
|
+
anisotropy = self.pipeline.confidence_threshold
|
|
2488
2531
|
|
|
2489
|
-
val = [np.linalg.norm(v) for v in gradient]
|
|
2490
|
-
anisotropy = np.std(val) / np.mean(val) + eps
|
|
2491
2532
|
return anisotropy
|
|
2492
2533
|
|
|
2493
2534
|
def _dynamic_weighted_ensemble(self, trans_probs, mlp_probs, attn_weights, input_ids, lstm_probs,
|
|
@@ -5776,6 +5817,8 @@ class AgentDistributedInference:
|
|
|
5776
5817
|
test_titles = None
|
|
5777
5818
|
label_map = None
|
|
5778
5819
|
rules = None
|
|
5820
|
+
X = None
|
|
5821
|
+
y = None
|
|
5779
5822
|
|
|
5780
5823
|
# ✅ Check payload (which is a dict), not the message itself
|
|
5781
5824
|
if isinstance(payload, dict):
|
|
@@ -5783,6 +5826,8 @@ class AgentDistributedInference:
|
|
|
5783
5826
|
test_titles = payload.get('test_titles')
|
|
5784
5827
|
label_map = payload.get('label_map')
|
|
5785
5828
|
rules = payload.get('rules')
|
|
5829
|
+
X = payload.get('X')
|
|
5830
|
+
y = payload.get('y')
|
|
5786
5831
|
|
|
5787
5832
|
# Sanitize if needed
|
|
5788
5833
|
if test_titles:
|
|
@@ -5791,9 +5836,15 @@ class AgentDistributedInference:
|
|
|
5791
5836
|
label_map = self._sanitize_structured(label_map)
|
|
5792
5837
|
if rules:
|
|
5793
5838
|
rules = self._sanitize_structured(rules)
|
|
5839
|
+
if X is not None:
|
|
5840
|
+
X = self._sanitize_structured(X)
|
|
5841
|
+
if y is not None:
|
|
5842
|
+
y = self._sanitize_structured(y)
|
|
5794
5843
|
|
|
5795
|
-
|
|
5796
|
-
|
|
5844
|
+
if X is None or y is None:
|
|
5845
|
+
print('[=] Got necessary titles, label_map and rules.')
|
|
5846
|
+
else:
|
|
5847
|
+
print('[=] Got necessary titles, label_map, rules and X And Y samples.')
|
|
5797
5848
|
else:
|
|
5798
5849
|
text = payload.get('text')
|
|
5799
5850
|
if text:
|
|
@@ -5819,7 +5870,7 @@ class AgentDistributedInference:
|
|
|
5819
5870
|
if self.predict_manager is not None:
|
|
5820
5871
|
result = await asyncio.to_thread(
|
|
5821
5872
|
self.predict_manager.advanced_prediction_method,
|
|
5822
|
-
test_titles, label_map, rules,
|
|
5873
|
+
test_titles, label_map, rules, X=X, y=y,
|
|
5823
5874
|
show_proba=True,
|
|
5824
5875
|
use_transformer=self.pipeline.use_transformer
|
|
5825
5876
|
)
|
|
@@ -5879,6 +5930,8 @@ class AgentDistributedInference:
|
|
|
5879
5930
|
test_titles = message.get('test_titles')
|
|
5880
5931
|
label_map = message.get('label_map')
|
|
5881
5932
|
rules = message.get('rules')
|
|
5933
|
+
X = message.get('X')
|
|
5934
|
+
y = message.get('y')
|
|
5882
5935
|
|
|
5883
5936
|
test_titles = self._sanitize_input(test_titles)
|
|
5884
5937
|
label_map = self._sanitize_input(label_map)
|
|
@@ -5898,7 +5951,7 @@ class AgentDistributedInference:
|
|
|
5898
5951
|
if method != 'basic_prediction' or predict_manager:
|
|
5899
5952
|
result = await asyncio.to_thread(
|
|
5900
5953
|
predict_manager.advanced_prediction_method,
|
|
5901
|
-
test_titles, label_map, rules, show_proba=False, use_transformer=self.pipeline.use_transformer
|
|
5954
|
+
test_titles, label_map, rules, X=X, y=y, show_proba=False, use_transformer=self.pipeline.use_transformer
|
|
5902
5955
|
)
|
|
5903
5956
|
else:
|
|
5904
5957
|
print('[=] basic prediction method')
|
|
@@ -5964,13 +6017,13 @@ class AgentDistributedInference:
|
|
|
5964
6017
|
finally:
|
|
5965
6018
|
loop.close()
|
|
5966
6019
|
|
|
5967
|
-
async def request_advanced_prediction_async(self, manager: Any, use_transformer: bool=False, agent_id: str=None, test_titles: List[tuple]=None, label_map: Dict[str, int]=None, rules: List[tuple]=None, timeout: float = 30.0, callback: Optional[Callable] = None):
|
|
6020
|
+
async def request_advanced_prediction_async(self, manager: Any, use_transformer: bool=False, agent_id: str=None, test_titles: List[tuple]=None, label_map: Dict[str, int]=None, rules: List[tuple]=None, X: np.ndarray=None, y: np.ndarray=None, timeout: float = 30.0, callback: Optional[Callable] = None):
|
|
5968
6021
|
# Asynchronous prediction request
|
|
5969
6022
|
# Local bypass - NO QUEUE
|
|
5970
6023
|
if agent_id == 'local':
|
|
5971
6024
|
logger.info(f"[=] Local request - direct execution")
|
|
5972
6025
|
# Run sync prediction in thread pool
|
|
5973
|
-
result = await asyncio.to_thread(manager.advanced_prediction_method, test_titles, label_map, rules, show_proba=True, use_transformer=use_transformer)
|
|
6026
|
+
result = await asyncio.to_thread(manager.advanced_prediction_method, test_titles, label_map, rules, X=X, y=y, show_proba=True, use_transformer=use_transformer)
|
|
5974
6027
|
logger.info(f"[=] Local result: {result[1]} || confidence: {result[2]}")
|
|
5975
6028
|
return result
|
|
5976
6029
|
|
|
@@ -5980,7 +6033,7 @@ class AgentDistributedInference:
|
|
|
5980
6033
|
type='predict_request',
|
|
5981
6034
|
sender=self.temporary_agent_id,
|
|
5982
6035
|
recipient=agent_id,
|
|
5983
|
-
payload={'test_titles': test_titles, 'label_map': label_map, 'rules': rules},
|
|
6036
|
+
payload={'test_titles': test_titles, 'label_map': label_map, 'rules': rules, 'X':X, 'y':y},
|
|
5984
6037
|
timestamp=datetime.now(),
|
|
5985
6038
|
timeout=timeout,
|
|
5986
6039
|
callback=callback,
|
|
@@ -6457,7 +6510,8 @@ class AgentDistributedInference:
|
|
|
6457
6510
|
n_classes = probs.shape[0]
|
|
6458
6511
|
|
|
6459
6512
|
batch_size = len(target_preds)
|
|
6460
|
-
anisotropy = self.pipeline.anisotropy_measurement(attn_weights)
|
|
6513
|
+
anisotropy = self.pipeline.anisotropy_measurement(attn_weights)
|
|
6514
|
+
|
|
6461
6515
|
|
|
6462
6516
|
if isinstance(attn_weights, (str, np.str_)):
|
|
6463
6517
|
clean_str = str(attn_weights).replace('[', '').replace(']', '')
|
|
@@ -6465,7 +6519,9 @@ class AgentDistributedInference:
|
|
|
6465
6519
|
elif isinstance(attn_weights, np.ndarray) and np.issubdtype(attn_weights.dtype, np.character):
|
|
6466
6520
|
# catches arrays filled with string text
|
|
6467
6521
|
clean_str = ' '.join(attn_weights.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
6468
|
-
attn_weights = np.
|
|
6522
|
+
attn_weights = np.fromiter(
|
|
6523
|
+
(x for x in clean_str.split() if x != "..."), dtype=float
|
|
6524
|
+
)
|
|
6469
6525
|
else:
|
|
6470
6526
|
# Ensure standard float array if it was integers or objects
|
|
6471
6527
|
attn_weights = np.asarray(attn_weights, dtype=float)
|
|
@@ -6503,14 +6559,14 @@ class AgentDistributedInference:
|
|
|
6503
6559
|
|
|
6504
6560
|
consensus = np.allclose(target_prob_indices, target_attn_indices, atol=eps)
|
|
6505
6561
|
|
|
6506
|
-
justified = (1.0 - AEL)
|
|
6507
|
-
boost = (1.0
|
|
6562
|
+
justified = (1.0 - AEL) * consensus + eps
|
|
6563
|
+
boost = (1.0 + justified) * attn_quality + eps
|
|
6508
6564
|
|
|
6509
|
-
|
|
6510
|
-
self.query_node.peer_trust =
|
|
6565
|
+
abstract_error_quality_score = (1.0 - attn_quality) * anisotropy + eps
|
|
6566
|
+
self.query_node.peer_trust = (1.0 - abstract_error_quality_score) + boost * justified
|
|
6511
6567
|
|
|
6512
6568
|
try:
|
|
6513
|
-
calibrated[i, mlp_target] = min(calibrated[i, mlp_target] * (1.5 *
|
|
6569
|
+
calibrated[i, mlp_target] = min(calibrated[i, mlp_target] * (1.5 * (1.0 - abstract_error_quality_score)), 0.95)
|
|
6514
6570
|
except:
|
|
6515
6571
|
return calibrated
|
|
6516
6572
|
|
|
@@ -6539,18 +6595,20 @@ class AgentDistributedInference:
|
|
|
6539
6595
|
attn_weights = np.array(attn_weights)
|
|
6540
6596
|
|
|
6541
6597
|
batch_similarity = self.pipeline.cosine_similarity(attn_weights, self_attn_weights)
|
|
6542
|
-
|
|
6598
|
+
|
|
6543
6599
|
anisotropy = self.pipeline.anisotropy_measurement(attn_weights)
|
|
6544
6600
|
AME = self.pipeline.AME_Encoder(attn_weights)
|
|
6545
6601
|
AMR = 1.0 / (1.0 + np.exp(-AME))
|
|
6546
|
-
weighted_similarity = batch_similarity * (1.0 - AMR) * anisotropy
|
|
6547
6602
|
|
|
6548
|
-
|
|
6603
|
+
weighted_quality_rate = (1.0 - AMR) * anisotropy
|
|
6604
|
+
|
|
6605
|
+
print(f'[=] Batch similarity: {batch_similarity} With quality rate of attention: {weighted_quality_rate}')
|
|
6606
|
+
if weighted_quality_rate > 0.75 and batch_similarity > 0.75:
|
|
6549
6607
|
return self.process_peer_request(probs, target_preds, attn_weights, input_ids)
|
|
6550
6608
|
else:
|
|
6551
|
-
print('[
|
|
6609
|
+
print('[!] Low uncertainty, normalizing with local agent data...')
|
|
6552
6610
|
|
|
6553
|
-
AEL =
|
|
6611
|
+
AEL = self.pipeline.confidence_threshold + weighted_quality_rate + (1.0 - AMR) * anisotropy
|
|
6554
6612
|
calibrated = self._calibrate_peer_probs(probs, target_preds, self_attn_weights, attn_weights, input_ids, AEL)
|
|
6555
6613
|
return calibrated
|
|
6556
6614
|
|
|
@@ -6623,18 +6681,22 @@ class AgentDistributedInference:
|
|
|
6623
6681
|
titles = message.get('test_titles')
|
|
6624
6682
|
label_map = message.get('label_map')
|
|
6625
6683
|
rules = message.get('rules')
|
|
6684
|
+
X = message.get('X')
|
|
6685
|
+
y = message.get('y')
|
|
6626
6686
|
if not titles and label_map and rules:
|
|
6627
6687
|
return {'type': self.MSG_TYPES['PREDICT_RESPONSE'], 'error': 'No test titles provided'}
|
|
6628
6688
|
|
|
6629
6689
|
titles = self._sanitize_arrays_and_dicts(titles)
|
|
6630
6690
|
label_map = self._sanitize_arrays_and_dicts(label_map)
|
|
6631
6691
|
rules = self._sanitize_arrays_and_dicts(rules)
|
|
6692
|
+
X = self._sanitize_arrays_and_dicts(X)
|
|
6693
|
+
y = self._sanitize_arrays_and_dicts(y)
|
|
6632
6694
|
|
|
6633
6695
|
if not self._check_rate_limit(sender_id):
|
|
6634
6696
|
return {'type': self.MSG_TYPES['PREDICT_RESPONSE'], 'error': 'Rate limit exceeded'}
|
|
6635
6697
|
|
|
6636
6698
|
try:
|
|
6637
|
-
result, chosen_label, confidence = self.predict_manager.advanced_prediction_method(titles, label_map, rules, show_proba=True, use_transformer=self.pipeline.use_transformer)
|
|
6699
|
+
result, chosen_label, confidence = self.predict_manager.advanced_prediction_method(titles, label_map, rules, X=X, y=y, show_proba=True, use_transformer=self.pipeline.use_transformer)
|
|
6638
6700
|
|
|
6639
6701
|
# Log the interaction
|
|
6640
6702
|
self._log_interaction(sender_id, 'prediction', confidence)
|
|
@@ -7788,92 +7850,131 @@ class IntegratedPipeline:
|
|
|
7788
7850
|
def cosine_similarity(self, a, b):
|
|
7789
7851
|
eps = 1e-5
|
|
7790
7852
|
b = b[0]
|
|
7853
|
+
|
|
7854
|
+
try:
|
|
7855
|
+
# Handle variable b
|
|
7856
|
+
if isinstance(b, (str, np.str_)):
|
|
7857
|
+
clean_str = str(b).replace('[', '').replace(']', '')
|
|
7858
|
+
b = np.fromstring(clean_str, sep=' ')
|
|
7859
|
+
elif isinstance(b, np.ndarray) and np.issubdtype(b.dtype, np.character):
|
|
7860
|
+
clean_str = ' '.join(b.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
7861
|
+
b = np.fromstring(clean_str, sep=' ')
|
|
7862
|
+
else:
|
|
7863
|
+
b = np.asarray(b, dtype=float)
|
|
7791
7864
|
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
elif isinstance(a, np.ndarray) and np.issubdtype(a.dtype, np.character):
|
|
7796
|
-
# catches arrays filled with string text
|
|
7797
|
-
clean_str = ' '.join(a.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
7798
|
-
try:
|
|
7865
|
+
# handle variable a
|
|
7866
|
+
if isinstance(a, (str, np.str_)):
|
|
7867
|
+
clean_str = str(a).replace('[', '').replace(']', '')
|
|
7799
7868
|
a = np.fromstring(clean_str, sep=' ')
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
b = np.fromstring(clean_str, sep=' ')
|
|
7814
|
-
else:
|
|
7815
|
-
b = np.asarray(b, dtype=float)
|
|
7869
|
+
elif isinstance(a, np.ndarray) and np.issubdtype(a.dtype, np.character):
|
|
7870
|
+
# catches arrays filled with string text
|
|
7871
|
+
clean_str = ' '.join(a.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
7872
|
+
try:
|
|
7873
|
+
a = np.fromstring(clean_str, sep=' ')
|
|
7874
|
+
except:
|
|
7875
|
+
clean_string = clean_str.strip(",")
|
|
7876
|
+
a = np.fromiter(
|
|
7877
|
+
(x for x in clean_string.split() if x != "..."), dtype=float
|
|
7878
|
+
)
|
|
7879
|
+
else:
|
|
7880
|
+
# Ensure standard float array if it was integers or objects
|
|
7881
|
+
a = np.asarray(a, dtype=float)
|
|
7816
7882
|
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7883
|
+
norm_a = np.linalg.norm(a)
|
|
7884
|
+
norm_b = np.linalg.norm(b)
|
|
7885
|
+
|
|
7886
|
+
if len(a.shape) > 1 and len(b.shape) > 1 and a.shape[1] != b.shape[0]:
|
|
7887
|
+
a = np.asarray(a)
|
|
7888
|
+
b = np.asarray(b)
|
|
7889
|
+
subset_a = a[0, :b.shape[0]]
|
|
7890
|
+
subset_b = a[:subset_a.shape[0], 0]
|
|
7825
7891
|
|
|
7826
|
-
try:
|
|
7827
7892
|
try:
|
|
7828
|
-
|
|
7893
|
+
try:
|
|
7894
|
+
dot_product = np.dot(subset_a, subset_b)
|
|
7895
|
+
except:
|
|
7896
|
+
dot_product = np.dot(subset_a[0, :min(subset_a.shape[1], subset_b.shape[0])], subset_b[:min(subset_a.shape[1], subset_b.shape[0])])
|
|
7829
7897
|
except:
|
|
7830
|
-
|
|
7831
|
-
|
|
7898
|
+
try:
|
|
7899
|
+
dot_product = np.dot(a.flatten(), b[:a.flatten().shape[0]])
|
|
7900
|
+
except:
|
|
7901
|
+
try:
|
|
7902
|
+
dot_product = np.dot(a[:b.shape[0]], b.flatten()[:a.shape[0]])
|
|
7903
|
+
except:
|
|
7904
|
+
print('[-] No similarity due to inhomogenous shapes and failed attempts to find subsets, returning low similarity score.')
|
|
7905
|
+
return 0.1
|
|
7906
|
+
|
|
7907
|
+
else:
|
|
7908
|
+
subset_a = a[:a.shape[0]]
|
|
7909
|
+
subset_b = b[:subset_a.shape[0]]
|
|
7910
|
+
|
|
7832
7911
|
try:
|
|
7833
|
-
dot_product = np.dot(
|
|
7912
|
+
dot_product = np.dot(subset_a, subset_b)
|
|
7834
7913
|
except:
|
|
7835
7914
|
try:
|
|
7836
|
-
|
|
7915
|
+
subset_b_2 = subset_b[:subset_a.shape[1], :subset_a.shape[0]]
|
|
7916
|
+
dot_product = np.dot(subset_a, subset_b_2)
|
|
7917
|
+
|
|
7837
7918
|
except:
|
|
7838
7919
|
print('[-] No similarity due to inhomogenous shapes and failed attempts to find subsets, returning low similarity score.')
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
else:
|
|
7842
|
-
subset_a = a[:a.shape[0]]
|
|
7843
|
-
subset_b = b[:subset_a.shape[0]]
|
|
7844
|
-
|
|
7845
|
-
try:
|
|
7846
|
-
dot_product = np.dot(subset_a, subset_b)
|
|
7847
|
-
except:
|
|
7848
|
-
try:
|
|
7849
|
-
subset_b_2 = subset_b[:subset_a.shape[1], :subset_a.shape[0]]
|
|
7850
|
-
dot_product = np.dot(subset_a, subset_b_2)
|
|
7920
|
+
|
|
7921
|
+
return 0.0
|
|
7851
7922
|
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
return 0.0
|
|
7923
|
+
cosine = dot_product / (norm_a * norm_b)
|
|
7924
|
+
cosine = np.clip(cosine, -1.0, 1.0)
|
|
7856
7925
|
|
|
7857
|
-
|
|
7858
|
-
|
|
7926
|
+
except Exception as e:
|
|
7927
|
+
print(f'[!] Cant calculate cosine similarity: {e}')
|
|
7928
|
+
cosine = 0.0
|
|
7859
7929
|
|
|
7860
7930
|
return cosine
|
|
7861
7931
|
|
|
7862
7932
|
def anisotropy_measurement(self, x):
|
|
7863
7933
|
eps = 1e-5
|
|
7934
|
+
|
|
7864
7935
|
if isinstance(x, list):
|
|
7865
7936
|
print(f'[=] Converting list to array with shape: {len(x)}')
|
|
7866
7937
|
x = np.array(x)
|
|
7867
7938
|
x = x.reshape(x.shape[0], -1) # Flatten if necessary
|
|
7939
|
+
|
|
7868
7940
|
try:
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7941
|
+
try:
|
|
7942
|
+
grads = np.gradient(x)
|
|
7943
|
+
# Stack gradients into a single array of vectors and find the norm of each
|
|
7944
|
+
# automatically handles multi-dimensional arrays (e.g., 2D, 3D volumes)
|
|
7945
|
+
stacked_grads = np.stack(grads, axis=-1)
|
|
7946
|
+
norms = np.linalg.norm(stacked_grads, axis=-1)
|
|
7947
|
+
|
|
7948
|
+
# Safely filter out potential NaNs or infs (common at array boundaries)
|
|
7949
|
+
valid_norms = norms[np.isfinite(norms)]
|
|
7950
|
+
|
|
7951
|
+
if len(valid_norms) == 0:
|
|
7952
|
+
return 0.0 # Return zero or appropriate default if no valid values exist
|
|
7953
|
+
|
|
7954
|
+
# Calculate statistics using the clean data
|
|
7955
|
+
std_val = np.std(valid_norms)
|
|
7956
|
+
mean_val = np.mean(valid_norms)
|
|
7957
|
+
|
|
7958
|
+
anisotropy = std_val / (mean_val + eps)
|
|
7959
|
+
if np.isnan(anisotropy) or np.isinf(anisotropy):
|
|
7960
|
+
anisotropy = self.pipeline.confidence_threshold
|
|
7961
|
+
except:
|
|
7962
|
+
try:
|
|
7963
|
+
gradient = np.gradient(x)
|
|
7964
|
+
except:
|
|
7965
|
+
subnet = x[:min(10, x.shape[0]), :min(10, x.shape[1])]
|
|
7966
|
+
gradient = np.gradient(subnet.flatten())
|
|
7873
7967
|
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7968
|
+
val = [np.linalg.norm(v) for v in gradient]
|
|
7969
|
+
anisotropy = np.std(val) / np.mean(val) + eps
|
|
7970
|
+
except Exception as e:
|
|
7971
|
+
print(f'[!] Cant calculate anisotropy due to: {e}')
|
|
7972
|
+
anisotropy = self.confidence_threshold
|
|
7973
|
+
|
|
7974
|
+
if np.isnan(anisotropy) or np.isinf(anisotropy):
|
|
7975
|
+
anisotropy = self.confidence_threshold
|
|
7976
|
+
|
|
7977
|
+
return anisotropy
|
|
7877
7978
|
|
|
7878
7979
|
def modular_prediction_saving(self, X, X2, output):
|
|
7879
7980
|
memory_name = self.memory_name
|
|
@@ -9173,7 +9274,9 @@ class IntegratedPipeline:
|
|
|
9173
9274
|
if isinstance(X, np.ndarray) and np.issubdtype(X.dtype, np.character):
|
|
9174
9275
|
# catches arrays filled with string text
|
|
9175
9276
|
clean_str = ' '.join(X.astype(str).flatten()).replace('[', '').replace(']', '')
|
|
9176
|
-
X = np.
|
|
9277
|
+
X = np.fromiter(
|
|
9278
|
+
(x for x in clean_str.split() if x != "..."), dtype=float
|
|
9279
|
+
)
|
|
9177
9280
|
|
|
9178
9281
|
X = np.squeeze(X)
|
|
9179
9282
|
if X.ndim == 1:
|
|
@@ -10739,7 +10842,7 @@ class PipelineAsyncManager:
|
|
|
10739
10842
|
# Input validation
|
|
10740
10843
|
try:
|
|
10741
10844
|
try:
|
|
10742
|
-
if not 'test_titles' in texts and 'label_map' in texts and 'rules' in texts:
|
|
10845
|
+
if not 'test_titles' in texts and 'label_map' in texts and 'rules' in texts and 'X' in texts and 'y' in texts:
|
|
10743
10846
|
for i in range(len(texts)):
|
|
10744
10847
|
if isinstance(texts[i], tuple):
|
|
10745
10848
|
texts[i] = texts[i][0] # Extract text from tuple if needed
|
|
@@ -10788,8 +10891,8 @@ class PipelineAsyncManager:
|
|
|
10788
10891
|
|
|
10789
10892
|
result = self._predict_sync(texts, timeout)
|
|
10790
10893
|
else:
|
|
10791
|
-
if 'test_titles' in texts and 'label_map' in texts and 'rules' in texts:
|
|
10792
|
-
result = self._advanced_predict_sync(texts['test_titles'], texts['label_map'], texts['rules'], texts.get('agent_id', 'default'), texts.get('use_transformer', False), timeout)
|
|
10894
|
+
if 'test_titles' in texts and 'label_map' in texts and 'rules' in texts and 'X' in texts and 'y' in texts:
|
|
10895
|
+
result = self._advanced_predict_sync(texts['test_titles'], texts['label_map'], texts['rules'], texts['X'], texts['y'], texts.get('agent_id', 'default'), texts.get('use_transformer', False), timeout)
|
|
10793
10896
|
else:
|
|
10794
10897
|
if isinstance(texts, tuple):
|
|
10795
10898
|
texts = texts[0]
|
|
@@ -10853,7 +10956,7 @@ class PipelineAsyncManager:
|
|
|
10853
10956
|
finally:
|
|
10854
10957
|
self._remove_task(task_id)
|
|
10855
10958
|
|
|
10856
|
-
def _advanced_predict_sync(self, test_titles, label_map, rules, agent_id: str, use_transformer: bool=False, timeout: float = 30.0) -> Any:
|
|
10959
|
+
def _advanced_predict_sync(self, test_titles, label_map, rules, X=None, y=None, agent_id: str=None, use_transformer: bool=False, timeout: float = 30.0) -> Any:
|
|
10857
10960
|
# Internal synchronous prediction.
|
|
10858
10961
|
|
|
10859
10962
|
if not self._loop or not self._loop.is_running():
|
|
@@ -10861,7 +10964,7 @@ class PipelineAsyncManager:
|
|
|
10861
10964
|
|
|
10862
10965
|
|
|
10863
10966
|
future = asyncio.run_coroutine_threadsafe(
|
|
10864
|
-
self.advanced_predict_async_await(test_titles, label_map, rules, use_transformer, agent_id, timeout),
|
|
10967
|
+
self.advanced_predict_async_await(test_titles, label_map, rules, X=X, y=y, use_transformer=use_transformer, agent_id=agent_id, timeout=timeout),
|
|
10865
10968
|
self._loop
|
|
10866
10969
|
)
|
|
10867
10970
|
|
|
@@ -10884,7 +10987,7 @@ class PipelineAsyncManager:
|
|
|
10884
10987
|
except asyncio.TimeoutError:
|
|
10885
10988
|
raise FutureTimeoutError(f"[-] Prediction timed out after {timeout}s")
|
|
10886
10989
|
|
|
10887
|
-
async def advanced_predict_async_await(self, test_titles: list[tuple], label_map: dict, rules: list[tuple], use_transformer: bool=False, agent_id: str=None, timeout: float = 30.0):
|
|
10990
|
+
async def advanced_predict_async_await(self, test_titles: list[tuple], label_map: dict, rules: list[tuple], X: np.ndarray=None, y: np.ndarray=None, use_transformer: bool=False, agent_id: str=None, timeout: float = 30.0):
|
|
10888
10991
|
# Async advanced prediction with await support.
|
|
10889
10992
|
try:
|
|
10890
10993
|
return await asyncio.wait_for(
|
|
@@ -10895,6 +10998,7 @@ class PipelineAsyncManager:
|
|
|
10895
10998
|
test_titles=test_titles,
|
|
10896
10999
|
label_map=label_map,
|
|
10897
11000
|
rules=rules,
|
|
11001
|
+
X=X, y=y,
|
|
10898
11002
|
timeout=timeout
|
|
10899
11003
|
),
|
|
10900
11004
|
timeout=timeout+5
|
|
@@ -11106,7 +11210,7 @@ class PipelineAsyncManager:
|
|
|
11106
11210
|
self._save_state()
|
|
11107
11211
|
|
|
11108
11212
|
|
|
11109
|
-
def advanced_batch_prediction(self, test_titles, label_map, rules, api_key, client_ip):
|
|
11213
|
+
def advanced_batch_prediction(self, test_titles, label_map, rules, X=None, y=None, api_key=None, client_ip=None):
|
|
11110
11214
|
try:
|
|
11111
11215
|
reverse_label_map = {v: k for k, v in label_map.items()}
|
|
11112
11216
|
|
|
@@ -11115,29 +11219,29 @@ class PipelineAsyncManager:
|
|
|
11115
11219
|
expected_labels = [text[1] for text in test_titles] # Your ground truth
|
|
11116
11220
|
predicted_output = []
|
|
11117
11221
|
|
|
11118
|
-
text = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True}
|
|
11222
|
+
text = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "X":X, "y":y, "use_transformer": True}
|
|
11119
11223
|
|
|
11120
11224
|
if not self.pipeline.intents:
|
|
11121
11225
|
advanced_result = self.predict(
|
|
11122
11226
|
text,
|
|
11123
|
-
timeout=
|
|
11227
|
+
timeout=120,
|
|
11124
11228
|
retries=None,
|
|
11125
11229
|
api_key=api_key,
|
|
11126
11230
|
client_ip=client_ip,
|
|
11127
11231
|
) # regular predict to populate pipelines data
|
|
11128
11232
|
else:
|
|
11129
11233
|
advanced_result = self.advanced_prediction_method(self.prediction_manager
|
|
11130
|
-
, test_titles, label_map, rules, method='Transformer_included')
|
|
11234
|
+
, test_titles, label_map, rules, X=X, y=y, method='Transformer_included')
|
|
11131
11235
|
|
|
11132
|
-
print(f'[=+=] Local advanced Prediction result: {advanced_result}')
|
|
11236
|
+
print(f'[=+=] Local single advanced Prediction result: {advanced_result}')
|
|
11133
11237
|
|
|
11134
11238
|
print('[=] Initiating Batch prediction for multiple texts...')
|
|
11135
11239
|
results = self.predict_batch(
|
|
11136
11240
|
texts=texts,
|
|
11137
|
-
timeout=
|
|
11241
|
+
timeout=120,
|
|
11138
11242
|
api_key=api_key)
|
|
11139
11243
|
|
|
11140
|
-
print("
|
|
11244
|
+
print("========📊 PREDICTION RESULTS============")
|
|
11141
11245
|
|
|
11142
11246
|
for text, expected, probs in zip(texts, expected_labels, results):
|
|
11143
11247
|
# probs is an array of 8 probability values
|
|
@@ -11167,6 +11271,7 @@ class PipelineAsyncManager:
|
|
|
11167
11271
|
print(f"[❌] INCORRECT LABEL (expected: {expected})")
|
|
11168
11272
|
|
|
11169
11273
|
predicted_output.append(predicted_label)
|
|
11274
|
+
predicted_output.append(advanced_result)
|
|
11170
11275
|
|
|
11171
11276
|
# Get stats
|
|
11172
11277
|
print(f"[=] Stats: {self.get_stats()}")
|
|
@@ -11198,7 +11303,7 @@ class PipelineAsyncManager:
|
|
|
11198
11303
|
results.append(result)
|
|
11199
11304
|
return results
|
|
11200
11305
|
|
|
11201
|
-
def advanced_prediction_method(self, manager, test_titles, label_map, rules, method='Transformer_included'):
|
|
11306
|
+
def advanced_prediction_method(self, manager, test_titles, label_map, rules, X=None, y=None, method='Transformer_included'):
|
|
11202
11307
|
# starting PredictionManager for advanced prediction
|
|
11203
11308
|
try:
|
|
11204
11309
|
if method == 'Transformer_included':
|
|
@@ -11207,6 +11312,7 @@ class PipelineAsyncManager:
|
|
|
11207
11312
|
test_titles, # Titles with expected labels
|
|
11208
11313
|
label_map,
|
|
11209
11314
|
rules,
|
|
11315
|
+
X=X, y=y,
|
|
11210
11316
|
show_proba=True,
|
|
11211
11317
|
top_k=4,
|
|
11212
11318
|
use_transformer=self.pipeline.use_transformer,
|
|
@@ -11219,6 +11325,7 @@ class PipelineAsyncManager:
|
|
|
11219
11325
|
[t[0] for t in test_titles], # Just titles
|
|
11220
11326
|
label_map,
|
|
11221
11327
|
rules,
|
|
11328
|
+
X=X, y=y,
|
|
11222
11329
|
show_proba=True
|
|
11223
11330
|
)
|
|
11224
11331
|
except Exception as e:
|
|
@@ -11286,6 +11393,8 @@ class PipelineAsyncManager:
|
|
|
11286
11393
|
test_titles=request['test_titles'],
|
|
11287
11394
|
label_map=request['label_map'],
|
|
11288
11395
|
rules=request['rules'],
|
|
11396
|
+
X=request['X'],
|
|
11397
|
+
y=request['y'],
|
|
11289
11398
|
timeout=self.default_timeout
|
|
11290
11399
|
),
|
|
11291
11400
|
self._loop
|
|
@@ -11485,7 +11594,7 @@ class PipelinePredictionManager:
|
|
|
11485
11594
|
reverse_map = {v: k for k, v in label_map.items()}
|
|
11486
11595
|
num_classes = len(label_map)
|
|
11487
11596
|
|
|
11488
|
-
if X and y is None or X is None or y is None:
|
|
11597
|
+
if X is None and y is None or X is None or y is None:
|
|
11489
11598
|
print('[🔄] Creating automatic X samples because X is not provided manually.')
|
|
11490
11599
|
dataset, X = self.pipeline.data_preparation(titles, label_map)
|
|
11491
11600
|
_, y, _, _ = self.pipeline.mlp_training_features(rules, dataset)
|
|
@@ -11766,6 +11875,7 @@ class PipelinePredictionManager:
|
|
|
11766
11875
|
|
|
11767
11876
|
except Exception as e:
|
|
11768
11877
|
print(f"[=] Error during prediction: {e}")
|
|
11878
|
+
traceback.print_exc()
|
|
11769
11879
|
results = []
|
|
11770
11880
|
|
|
11771
11881
|
return results
|
|
@@ -11785,7 +11895,7 @@ class PipelinePredictionManager:
|
|
|
11785
11895
|
|
|
11786
11896
|
try:
|
|
11787
11897
|
|
|
11788
|
-
if X_raw and y is None or X_raw is None or y is None:
|
|
11898
|
+
if X_raw is None and y is None or X_raw is None or y is None:
|
|
11789
11899
|
print('[🔄] Creating automatic X samples because X is not provided manually.')
|
|
11790
11900
|
datasets, X_raw = self.pipeline.data_preparation(titles, label_map)
|
|
11791
11901
|
else:
|
|
@@ -12006,7 +12116,7 @@ class PipelinePredictionManager:
|
|
|
12006
12116
|
self.pipeline.titles = titles
|
|
12007
12117
|
self.pipeline.labels = label_map
|
|
12008
12118
|
|
|
12009
|
-
if X and y is None or X is None or y is None:
|
|
12119
|
+
if X is None and y is None or X is None or y is None:
|
|
12010
12120
|
print('[🔄] Creating automatic X samples because X is not provided manually.')
|
|
12011
12121
|
dataset, X = self.pipeline.data_preparation(titles, label_map)
|
|
12012
12122
|
_, y, _, _ = self.pipeline.mlp_training_features(rules, dataset)
|
|
@@ -12028,16 +12138,16 @@ class PipelinePredictionManager:
|
|
|
12028
12138
|
input_ids_list.append(np.array(ids))
|
|
12029
12139
|
|
|
12030
12140
|
input_ids = np.array(input_ids_list)
|
|
12031
|
-
|
|
12032
|
-
|
|
12033
|
-
|
|
12034
|
-
print("[⚡] Low anisotropy detected on input, relying on sequence encoding for input...")
|
|
12035
|
-
sequence_ids = self.pipeline.sequence_encoding(dataset)
|
|
12036
|
-
use_embedded = True
|
|
12037
|
-
trans_probs, attn_weights = self.pipeline.model2.forward(sequence_ids, embedded=use_embedded)
|
|
12141
|
+
sequence_ids = self.pipeline.sequence_encoding(dataset)
|
|
12142
|
+
if X is not None:
|
|
12143
|
+
anisotropy = self.pipeline.anisotropy_measurement(X)
|
|
12038
12144
|
else:
|
|
12039
|
-
|
|
12040
|
-
|
|
12145
|
+
anisotropy = self.pipeline.anisotropy_measurement(sequence_ids)
|
|
12146
|
+
|
|
12147
|
+
# Get transformer predictions with attention
|
|
12148
|
+
print(f"[⚡] anisotropy rate detected on input: {anisotropy:.1%}.")
|
|
12149
|
+
use_embedded = True
|
|
12150
|
+
trans_probs, attn_weights = self.pipeline.model2.forward(sequence_ids, embedded=use_embedded)
|
|
12041
12151
|
|
|
12042
12152
|
else:
|
|
12043
12153
|
print("\n[⚡] Running MLP-only predictions")
|
|
@@ -12483,12 +12593,14 @@ class PipelinePredictionManager:
|
|
|
12483
12593
|
|
|
12484
12594
|
except Exception as e:
|
|
12485
12595
|
print(f"[!] Error in advanced prediction method: {e}, Initiating regular prediction method...")
|
|
12596
|
+
traceback.print_exc()
|
|
12486
12597
|
try:
|
|
12487
12598
|
results = self.regular_prediction_method(titles, label_map, rules, X=X, y=y, show_proba=False, top_k=3, batch_size=2,use_transformer=True)
|
|
12488
12599
|
chosen_label = results[0]['predicted']
|
|
12489
12600
|
confidence = results[0]['confidence']
|
|
12490
12601
|
except Exception as error:
|
|
12491
12602
|
print(f'[= ! =] Error in all prediction method: {error}')
|
|
12603
|
+
traceback.print_exc()
|
|
12492
12604
|
results, chosen_label, confidence = None, None, 0.0
|
|
12493
12605
|
time.sleep(5)
|
|
12494
12606
|
|
|
@@ -12663,10 +12775,13 @@ class ConsecutivePeerAgent:
|
|
|
12663
12775
|
test_titles = text['test_titles']
|
|
12664
12776
|
label_map = text['label_map']
|
|
12665
12777
|
rules = text['rules']
|
|
12778
|
+
X = text['X']
|
|
12779
|
+
y = text['y']
|
|
12666
12780
|
result, chosen_label, confidence = self.manager.advanced_prediction_method(
|
|
12667
12781
|
test_titles,
|
|
12668
12782
|
label_map,
|
|
12669
12783
|
rules,
|
|
12784
|
+
X=X, y=y,
|
|
12670
12785
|
show_proba=False,
|
|
12671
12786
|
use_transformer=self.pipeline.use_transformer
|
|
12672
12787
|
)
|
|
@@ -13212,7 +13327,7 @@ class CohesiveAgentDeployment:
|
|
|
13212
13327
|
# This runs in a thread pool via asyncio.to_thread
|
|
13213
13328
|
return self.async_manager.predict(
|
|
13214
13329
|
texts=texts,
|
|
13215
|
-
timeout=
|
|
13330
|
+
timeout=120,
|
|
13216
13331
|
retries=None,
|
|
13217
13332
|
api_key=api_key,
|
|
13218
13333
|
client_ip=client_ip,
|
|
@@ -13545,7 +13660,7 @@ class CohesiveAgentDeployment:
|
|
|
13545
13660
|
|
|
13546
13661
|
result = await asyncio.wait_for(
|
|
13547
13662
|
self.predict_with_peers(texts, api_key, method, disable_sync=disable_sync),
|
|
13548
|
-
timeout=
|
|
13663
|
+
timeout=120.0
|
|
13549
13664
|
)
|
|
13550
13665
|
|
|
13551
13666
|
# Check if result is valid
|
|
@@ -13973,11 +14088,14 @@ class CohesiveAgentDeployment:
|
|
|
13973
14088
|
test_titles = texts['test_titles']
|
|
13974
14089
|
label_map = texts['label_map']
|
|
13975
14090
|
rules = texts['rules']
|
|
14091
|
+
X = texts['X']
|
|
14092
|
+
y = texts['y']
|
|
13976
14093
|
|
|
13977
14094
|
result, chosen_label, confidence = self.manager.advanced_prediction_method(
|
|
13978
14095
|
test_titles,
|
|
13979
14096
|
label_map,
|
|
13980
14097
|
rules,
|
|
14098
|
+
X=X, y=y,
|
|
13981
14099
|
show_proba=True,
|
|
13982
14100
|
use_transformer=self.pipeline.use_transformer
|
|
13983
14101
|
)
|
|
@@ -14227,7 +14345,7 @@ class CohesiveAgentDeployment:
|
|
|
14227
14345
|
|
|
14228
14346
|
|
|
14229
14347
|
# ============ EXAMPLE: SECURE PEER-TO-PEER CLUSTER ============
|
|
14230
|
-
async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
14348
|
+
async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, X=None, y=None, agent_id=None, filename=None, title_name=None, label_name=None, manager=None):
|
|
14231
14349
|
"""
|
|
14232
14350
|
Run multiple agents that securely communicate.
|
|
14233
14351
|
Stops retrying once connected successfully.
|
|
@@ -14288,7 +14406,7 @@ async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, agent
|
|
|
14288
14406
|
api_key = agent1.get_api_key()
|
|
14289
14407
|
print(f"\n🔑 Using API Key: {api_key[:20]}...")
|
|
14290
14408
|
|
|
14291
|
-
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
14409
|
+
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "X":X, "y":y, "use_transformer": True, "agent_id": agent_id}
|
|
14292
14410
|
|
|
14293
14411
|
# Make prediction with peer ensemble
|
|
14294
14412
|
# Peer Connection will be ensured successful during P2P
|
|
@@ -14331,7 +14449,7 @@ async def run_secure_agent_cluster(pipeline,test_titles, label_map, rules, agent
|
|
|
14331
14449
|
|
|
14332
14450
|
|
|
14333
14451
|
|
|
14334
|
-
async def example_async_with_result_queue(pipeline, test_titles, label_map, rules, agent_id, filename, title_name, label_name):
|
|
14452
|
+
async def example_async_with_result_queue(pipeline, test_titles, label_map, rules, X=None, y=None,agent_id=None, filename=None, title_name=None, label_name=None):
|
|
14335
14453
|
# Example using the proper result queue
|
|
14336
14454
|
|
|
14337
14455
|
agent = CohesiveAgentDeployment(
|
|
@@ -14346,7 +14464,7 @@ async def example_async_with_result_queue(pipeline, test_titles, label_map, rule
|
|
|
14346
14464
|
await agent.start()
|
|
14347
14465
|
|
|
14348
14466
|
api_key = agent.get_api_key()
|
|
14349
|
-
payloads = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
14467
|
+
payloads = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "X":X, "y":y, "use_transformer": True, "agent_id": agent_id}
|
|
14350
14468
|
|
|
14351
14469
|
# Single async prediction
|
|
14352
14470
|
print('[==] Single sync prediction: (using single text: "Opening Thesis.docx")')
|
|
@@ -14396,45 +14514,45 @@ async def example_async_with_result_queue(pipeline, test_titles, label_map, rule
|
|
|
14396
14514
|
|
|
14397
14515
|
|
|
14398
14516
|
|
|
14399
|
-
def initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, agent_id, filename, title_name, label_name, manager):
|
|
14517
|
+
def initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, X, y, agent_id, filename, title_name, label_name, manager):
|
|
14400
14518
|
print("\n" + "="*60)
|
|
14401
14519
|
print("🔮 = TESTING COHESIVE AGENT DEPLOYMENT WITH ASYNC MANAGER = ")
|
|
14402
14520
|
|
|
14403
14521
|
print('Test 1 of Multi agent cluster')
|
|
14404
|
-
asyncio.run(run_secure_agent_cluster(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name, manager=manager))
|
|
14522
|
+
asyncio.run(run_secure_agent_cluster(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, X=X, y=y, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name, manager=manager))
|
|
14405
14523
|
|
|
14406
14524
|
print("\n1. Basic async with result queue")
|
|
14407
|
-
asyncio.run(example_async_with_result_queue(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name))
|
|
14525
|
+
asyncio.run(example_async_with_result_queue(pipeline=pipeline, test_titles=test_titles, label_map=label_map, rules=rules, X=X,y=y, agent_id=agent_id, filename=filename, title_name=title_name, label_name=label_name))
|
|
14408
14526
|
|
|
14409
14527
|
|
|
14410
14528
|
# async manager setup examples
|
|
14411
|
-
def initiate_prediction_usage(pipeline, manager, predict_wrapper, test_titles, label_map, rules):
|
|
14529
|
+
def initiate_prediction_usage(pipeline, manager, predict_wrapper, test_titles, label_map, rules, X, y):
|
|
14412
14530
|
"""Basic synchronous usage."""
|
|
14413
14531
|
# Use context manager (auto start/stop)
|
|
14414
14532
|
api_key = 'my-ultra-safe-secret-key-for-authentication'
|
|
14415
14533
|
|
|
14416
14534
|
with predict_wrapper as wrapper:
|
|
14417
14535
|
print('[==] Initiating regular prediction')
|
|
14418
|
-
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': rules, 'use_transformer': True}
|
|
14536
|
+
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': rules, "X":X, "y":y,'use_transformer': True}
|
|
14419
14537
|
regular_predict = wrapper.predict(
|
|
14420
14538
|
texts=texts,
|
|
14421
|
-
timeout=
|
|
14539
|
+
timeout=120,
|
|
14422
14540
|
retries=None,
|
|
14423
14541
|
api_key=api_key,
|
|
14424
14542
|
client_ip=None)
|
|
14425
14543
|
|
|
14426
14544
|
print('[==] Initiating advanced batch prediction')
|
|
14427
|
-
predicted_output = wrapper.advanced_batch_prediction(test_titles, label_map, rules, api_key, client_ip=None)
|
|
14545
|
+
predicted_output = wrapper.advanced_batch_prediction(test_titles, label_map, rules, X=None, y=None, api_key=api_key, client_ip=None)
|
|
14428
14546
|
|
|
14429
14547
|
|
|
14430
|
-
def initiate_with_retries(pipeline, manager, wrapper, test_titles, label_map, rules):
|
|
14548
|
+
def initiate_with_retries(pipeline, manager, wrapper, test_titles, label_map, rules, X, y):
|
|
14431
14549
|
"""Example with retry logic."""
|
|
14432
14550
|
|
|
14433
14551
|
try:
|
|
14434
14552
|
# Will retry up to 5 times
|
|
14435
|
-
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True}
|
|
14553
|
+
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "X":X, 'y':y, "use_transformer": True}
|
|
14436
14554
|
result = wrapper.predict(texts, timeout=60, retries=None, api_key=None)
|
|
14437
|
-
advanced_result, chosen_label, confidence = wrapper.advanced_prediction_method(manager, test_titles, label_map, rules, method='Transformer_included')
|
|
14555
|
+
advanced_result, chosen_label, confidence = wrapper.advanced_prediction_method(manager, test_titles, label_map, rules, X=X, y=y, method='Transformer_included')
|
|
14438
14556
|
print(f"[=] Result after retries: {result}")
|
|
14439
14557
|
print(f"[=] Advanced Result: {chosen_label} || ({confidence:.1%})")
|
|
14440
14558
|
|
|
@@ -14460,7 +14578,7 @@ def initiate_graceful_shutdown(pipeline, wrapper):
|
|
|
14460
14578
|
# Graceful shutdown
|
|
14461
14579
|
wrapper.stop()
|
|
14462
14580
|
|
|
14463
|
-
def AsyncWrappertest(pipeline, prediction_manager, test_titles, label_map, rules):
|
|
14581
|
+
def AsyncWrappertest(pipeline, prediction_manager, test_titles, label_map, rules, X, y):
|
|
14464
14582
|
print("\n" + "="*60)
|
|
14465
14583
|
print("🔮 = TESTING ASYNCHRONOUS PREDICTION WRAPPER = ")
|
|
14466
14584
|
print("="*60)
|
|
@@ -14496,8 +14614,8 @@ def AsyncWrappertest(pipeline, prediction_manager, test_titles, label_map, rules
|
|
|
14496
14614
|
logging.basicConfig(level=logging.INFO)
|
|
14497
14615
|
|
|
14498
14616
|
# Run examples
|
|
14499
|
-
initiate_prediction_usage(pipeline, prediction_manager, wrapper, test_titles, label_map, rules)
|
|
14500
|
-
initiate_with_retries(pipeline, prediction_manager, wrapper, test_titles, label_map, rules)
|
|
14617
|
+
initiate_prediction_usage(pipeline, prediction_manager, wrapper, test_titles, label_map, rules, X, y)
|
|
14618
|
+
initiate_with_retries(pipeline, prediction_manager, wrapper, test_titles, label_map, rules, X, y)
|
|
14501
14619
|
initiate_graceful_shutdown(pipeline, wrapper)
|
|
14502
14620
|
|
|
14503
14621
|
print("\n✅ Asynchronous prediction wrapper test completed successfully.")
|
|
@@ -14628,6 +14746,7 @@ def PermissiveTest():
|
|
|
14628
14746
|
]
|
|
14629
14747
|
|
|
14630
14748
|
running = True
|
|
14749
|
+
X, y = None, None
|
|
14631
14750
|
while running:
|
|
14632
14751
|
permission = input('|| Allow Hybrid prediction test? [Y/N]: ')
|
|
14633
14752
|
|
|
@@ -14637,6 +14756,7 @@ def PermissiveTest():
|
|
|
14637
14756
|
[t[0] for t in test_titles], # Just titles
|
|
14638
14757
|
label_map,
|
|
14639
14758
|
rules,
|
|
14759
|
+
X=X, y=y,
|
|
14640
14760
|
show_proba=True
|
|
14641
14761
|
)
|
|
14642
14762
|
time.sleep(5)
|
|
@@ -14671,16 +14791,16 @@ def PermissiveTest():
|
|
|
14671
14791
|
|
|
14672
14792
|
permission_continue = input('|| Do you want to test the Asynchronous wrapper for multiple predictions? [Y/N]: ')
|
|
14673
14793
|
if permission_continue == 'Y' or permission_continue == 'y':
|
|
14674
|
-
AsyncWrappertest(pipeline, manager, test_titles, label_map, rules)
|
|
14794
|
+
AsyncWrappertest(pipeline, manager, test_titles, label_map, rules, X, y)
|
|
14675
14795
|
print('== Asynchronous wrapper Successfully tested! ==')
|
|
14676
14796
|
|
|
14677
14797
|
cohesive_permission = input('|| Do you want to test the Cohesive Agent Deployment with Async Manager? [Y/N]: ')
|
|
14678
14798
|
if cohesive_permission == 'Y' or cohesive_permission == 'y':
|
|
14679
14799
|
if not (filename and title and label and filename != 'N'):
|
|
14680
14800
|
print('[=] Searching fallback filename: ManualsTraining.txt, window_title, label')
|
|
14681
|
-
initiate_cohesive_agent_deployment_test(pipeline,test_titles, label_map, rules, agent_id, 'ManualsTraining.txt', 'window_title', 'label', manager)
|
|
14801
|
+
initiate_cohesive_agent_deployment_test(pipeline,test_titles, label_map, rules, X, y, agent_id, 'ManualsTraining.txt', 'window_title', 'label', manager)
|
|
14682
14802
|
else:
|
|
14683
|
-
initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, agent_id, filename, title, label, manager)
|
|
14803
|
+
initiate_cohesive_agent_deployment_test(pipeline, test_titles, label_map, rules, X, y, agent_id, filename, title, label, manager)
|
|
14684
14804
|
print('== Cohesive Agent Deployment Successfully tested! ==')
|
|
14685
14805
|
|
|
14686
14806
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.6
|
|
4
4
|
Summary: Framework for Advanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: hernikpuspita5@gmail.com
|
|
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
42
42
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
43
43
|
|
|
44
44
|
### Library Short Description:
|
|
45
|
-
- Development Stage: Beta, 0.4.
|
|
45
|
+
- Development Stage: Beta, 0.4.6.
|
|
46
46
|
- Maintainer: Micro-Novelty.
|
|
47
47
|
- library Source-Code is Open-sourced on github.
|
|
48
48
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
@@ -379,6 +379,10 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP + LSTM usin
|
|
|
379
379
|
|
|
380
380
|
### Both performance Overview
|
|
381
381
|
<img width="1536" height="1024" alt="WhatsApp Image 2026-05-24 at 10 27 00" src="https://github.com/user-attachments/assets/9404277f-281f-4893-8367-e494833230ea" />
|
|
382
|
+
_______________________________________
|
|
383
|
+
- Note:
|
|
384
|
+
- This performance metric was calculated in older versions, With newer Transformers that has more, newer modules, The resulting cpu consumed may Increase 1.5 - 2x much more in Docker ARM64 Environment + QEMU,
|
|
385
|
+
MLP And LSTM stays the same and still fully optimized.
|
|
382
386
|
|
|
383
387
|
## Source code of AbstractIntegratedModule
|
|
384
388
|
- Note: The source code is provided in the repository.
|
|
@@ -650,7 +654,8 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
650
654
|
|
|
651
655
|
async_manager.start(method='Transformer_included', bootstrap_token=None) # boothstrap token is optional for better security
|
|
652
656
|
|
|
653
|
-
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'use_transformer': True}
|
|
657
|
+
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'X': None, 'y':None, 'use_transformer': True} # all samples needed for advanced prediction method. (X and y are optional samples)
|
|
658
|
+
|
|
654
659
|
regular_predict = async_manager.predict(
|
|
655
660
|
texts=texts,
|
|
656
661
|
timeout=60,
|
|
@@ -660,7 +665,9 @@ regular_predict = async_manager.predict(
|
|
|
660
665
|
# with retries: async_manager.predict(texts, timeout=60, retries=5, api_key=secret_key) # 5 times retry if failed
|
|
661
666
|
|
|
662
667
|
print('[==] Initiating advanced batch prediction')
|
|
663
|
-
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
668
|
+
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
669
|
+
X=None, y=None, # provide your initialized X and y samples (Also Optional, can be set to None)
|
|
670
|
+
secret_key=secret_key, client_ip=None) # you can add client_ip to provide a robust authentication paired with secret_key
|
|
664
671
|
# for better and faster advanced prediction, consider using advanced batch prediction like in the above example
|
|
665
672
|
|
|
666
673
|
```
|
|
@@ -766,7 +773,7 @@ try:
|
|
|
766
773
|
api_key = agent1.get_api_key()
|
|
767
774
|
print(f"\n🔑 Using API Key: {api_key[:20]}...")
|
|
768
775
|
|
|
769
|
-
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
776
|
+
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, 'X': None, "y":None, "use_transformer": True, "agent_id": agent_id} # (X and y are optional samples here too)
|
|
770
777
|
|
|
771
778
|
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
772
779
|
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
|
@@ -10,7 +10,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
10
10
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
11
11
|
|
|
12
12
|
### Library Short Description:
|
|
13
|
-
- Development Stage: Beta, 0.4.
|
|
13
|
+
- Development Stage: Beta, 0.4.6.
|
|
14
14
|
- Maintainer: Micro-Novelty.
|
|
15
15
|
- library Source-Code is Open-sourced on github.
|
|
16
16
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
|
@@ -347,6 +347,10 @@ B. [=] Advanced Prediction without Transformer, Only Specialized MLP + LSTM usin
|
|
|
347
347
|
|
|
348
348
|
### Both performance Overview
|
|
349
349
|
<img width="1536" height="1024" alt="WhatsApp Image 2026-05-24 at 10 27 00" src="https://github.com/user-attachments/assets/9404277f-281f-4893-8367-e494833230ea" />
|
|
350
|
+
_______________________________________
|
|
351
|
+
- Note:
|
|
352
|
+
- This performance metric was calculated in older versions, With newer Transformers that has more, newer modules, The resulting cpu consumed may Increase 1.5 - 2x much more in Docker ARM64 Environment + QEMU,
|
|
353
|
+
MLP And LSTM stays the same and still fully optimized.
|
|
350
354
|
|
|
351
355
|
## Source code of AbstractIntegratedModule
|
|
352
356
|
- Note: The source code is provided in the repository.
|
|
@@ -618,7 +622,8 @@ async_manager = PipelineAsyncManager(main_model,
|
|
|
618
622
|
|
|
619
623
|
async_manager.start(method='Transformer_included', bootstrap_token=None) # boothstrap token is optional for better security
|
|
620
624
|
|
|
621
|
-
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'use_transformer': True}
|
|
625
|
+
texts = {'test_titles': test_titles, 'label_map': label_map, 'rules': example_rules, 'X': None, 'y':None, 'use_transformer': True} # all samples needed for advanced prediction method. (X and y are optional samples)
|
|
626
|
+
|
|
622
627
|
regular_predict = async_manager.predict(
|
|
623
628
|
texts=texts,
|
|
624
629
|
timeout=60,
|
|
@@ -628,7 +633,9 @@ regular_predict = async_manager.predict(
|
|
|
628
633
|
# with retries: async_manager.predict(texts, timeout=60, retries=5, api_key=secret_key) # 5 times retry if failed
|
|
629
634
|
|
|
630
635
|
print('[==] Initiating advanced batch prediction')
|
|
631
|
-
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
636
|
+
predicted_output = async_manager.advanced_batch_prediction(test_titles, label_map, example_rules,
|
|
637
|
+
X=None, y=None, # provide your initialized X and y samples (Also Optional, can be set to None)
|
|
638
|
+
secret_key=secret_key, client_ip=None) # you can add client_ip to provide a robust authentication paired with secret_key
|
|
632
639
|
# for better and faster advanced prediction, consider using advanced batch prediction like in the above example
|
|
633
640
|
|
|
634
641
|
```
|
|
@@ -734,7 +741,7 @@ try:
|
|
|
734
741
|
api_key = agent1.get_api_key()
|
|
735
742
|
print(f"\n🔑 Using API Key: {api_key[:20]}...")
|
|
736
743
|
|
|
737
|
-
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, "use_transformer": True, "agent_id": agent_id}
|
|
744
|
+
texts = {"test_titles": test_titles, "label_map": label_map, "rules": rules, 'X': None, "y":None, "use_transformer": True, "agent_id": agent_id} # (X and y are optional samples here too)
|
|
738
745
|
|
|
739
746
|
# texts dictionary must contain test_titles, label_map, and rules that you can assign,
|
|
740
747
|
# agent ID can be strings, int, or floats, recommendded to make it long for better security.
|
|
@@ -8,7 +8,7 @@ class BinaryDistribution(Distribution):
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="AbstractIntegratedModule",
|
|
11
|
-
version="0.4.
|
|
11
|
+
version="0.4.6",
|
|
12
12
|
description="Framework for Advanced Integrated Non-LLM AI Module library - Backend Framework for Non-LLM AI Agent Framework",
|
|
13
13
|
long_description=open("README.md", encoding="utf-8").read(),
|
|
14
14
|
long_description_content_type="text/markdown",
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|