AbstractIntegratedModule 0.5.3__tar.gz → 0.5.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.
Files changed (25) hide show
  1. abstractintegratedmodule-0.5.5/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  2. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so +0 -0
  3. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so +0 -0
  4. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5/AbstractIntegratedModule.egg-info}/PKG-INFO +11 -8
  5. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.py +156 -33
  6. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractOptimizedModules.c +2689 -1307
  7. abstractintegratedmodule-0.5.5/AbstractOptimizedModules.cp313-win_amd64.pyd +0 -0
  8. abstractintegratedmodule-0.5.5/AbstractOptimizedModules.cpython-310-aarch64-linux-gnu.so +0 -0
  9. abstractintegratedmodule-0.5.5/AbstractOptimizedModules.cpython-312-x86_64-linux-gnu.so +0 -0
  10. abstractintegratedmodule-0.5.5/AbstractOptimizedModules.pyx +283 -0
  11. {abstractintegratedmodule-0.5.3/AbstractIntegratedModule.egg-info → abstractintegratedmodule-0.5.5}/PKG-INFO +11 -8
  12. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/README.md +9 -6
  13. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/setup.py +2 -2
  14. abstractintegratedmodule-0.5.3/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  15. abstractintegratedmodule-0.5.3/AbstractOptimizedModules.cp313-win_amd64.pyd +0 -0
  16. abstractintegratedmodule-0.5.3/AbstractOptimizedModules.cpython-310-aarch64-linux-gnu.so +0 -0
  17. abstractintegratedmodule-0.5.3/AbstractOptimizedModules.cpython-312-x86_64-linux-gnu.so +0 -0
  18. abstractintegratedmodule-0.5.3/AbstractOptimizedModules.pyx +0 -197
  19. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
  20. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
  21. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
  22. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
  23. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/MANIFEST.in +0 -0
  24. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/pyproject.toml +0 -0
  25. {abstractintegratedmodule-0.5.3 → abstractintegratedmodule-0.5.5}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 0.5.3
4
- Summary: Framework for Advanced Integrated Non-LLM AI Module library - Backend Framework For Non-LLM AI Agent
3
+ Version: 0.5.5
4
+ Summary: Library for Advanced Integrated Non-LLM AI Models - Optimized Backend Framework For Non-LLM AI Agent
5
5
  Author: Micro-Novelty
6
6
  Author-email: hernikpuspita5@gmail.com
7
7
  License: MIT
@@ -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.5.3.
45
+ - Development Stage: Beta, 0.5.5.
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.
@@ -64,13 +64,16 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
64
64
  - AWE setup Proven Efficient on Hard-uncontrolled dataset such as Activity Recognition from the given Database.
65
65
  - LSTM is Optimized efficiently for scarce data with AWE method.
66
66
  - Robust Advanced prediction capabilities proven effective on ARM64 Using MLP + LSTM Architectures.
67
- - Transformer Optimized using Cython, to reduce Memory overhead and Reduce CPU Usage, With Reduced Training Time.
67
+ - Transformer Modules Optimized using Cython, to reduce Memory overhead and Reduce CPU Usage, With Reduced Training Time.
68
68
  - Changelog:
69
- - v0.5.3:
69
+ - v0.5.5:
70
70
  - [=] New features:
71
- - New cache management system for Transformers Cache
72
- - Optimized Transformer Training time with less Computational overhead.
73
- - Optimized Transformer attention quality computing with more newer Conditional gate for quality computing.
71
+ - Added Anisotropy measurement optimization in Cython to handle complex logic.
72
+ - Added Cython softmax for Transformer to reduce CPU consumption.
73
+ - Added Cython Cosine similarity to reduce ensemble prediction time needed for prediction.
74
+ - Added safety guards for Cosine similarity to prevent string arrays to cause further errors.
75
+
76
+
74
77
  -----
75
78
 
76
79
  <img width="1280" height="600" alt="WhatsApp Image 2026-05-27 at 07 16 32" src="https://github.com/user-attachments/assets/4b58a556-45a3-419b-96fd-9c1b76cac574" />
@@ -50,13 +50,16 @@ try:
50
50
  optimized_tanh_deriv,
51
51
  optimized_lstm_cell_forward,
52
52
  optimized_project_heads,
53
- optimized_ame_encoder
53
+ optimized_ame_encoder,
54
+ optimized_anisotropy,
55
+ optimized_cosine_similarity,
56
+ optimized_softmax_2d
54
57
  )
55
58
  _OPT_AVAILABLE = True
56
59
  print('[=] Cython acceleration loaded ✅')
57
- except ImportError:
60
+ except ImportError as e:
58
61
  _OPT_AVAILABLE = False
59
- print('[=] Cython not available, using numpy fallback')
62
+ print(f'[=] Cython not available: {e}, using numpy fallback')
60
63
 
61
64
  # initial Setup logging for AgentDistributedInference and ModelStorage class logger and security logger
62
65
  logger = logging.getLogger(__name__)
@@ -383,6 +386,9 @@ class GeometricWeightShaping:
383
386
  # abstract modelling error provides the model how to better process weights when the data complexity has little geometric complexity
384
387
  def AME_Encoder(self, x):
385
388
  X = np.asarray(x)
389
+ if _OPT_AVAILABLE and np.asarray(X).ndim == 2:
390
+ return optimized_ame_encoder(np.asarray(X, dtype=np.float64))
391
+
386
392
  try:
387
393
  gradient = np.gradient(x)
388
394
  except:
@@ -400,6 +406,10 @@ class GeometricWeightShaping:
400
406
  # anisotropy provides the model the standard complexity of the data geometry, allowing it to know how complex the data needs to be processed.
401
407
  def anisotropy_measurement(self, x):
402
408
  eps = 1e-5
409
+ if _OPT_AVAILABLE:
410
+ x = x.reshape(x.shape[0], -1)
411
+ return optimized_anisotropy(np.asarray(x, dtype=np.float64))
412
+
403
413
  try:
404
414
  gradient = np.gradient(x)
405
415
  except:
@@ -496,6 +506,8 @@ class Activation:
496
506
 
497
507
  @staticmethod
498
508
  def softmax(x):
509
+ if _OPT_AVAILABLE:
510
+ return optimized_softmax_2d(np.asarray(x, dtype=np.float64))
499
511
  # numerical stability
500
512
  if x.ndim > 1:
501
513
  exp_x = np.exp(x - np.max(x, axis=1, keepdims=True))
@@ -691,6 +703,9 @@ class Transformer:
691
703
 
692
704
 
693
705
  def softmax(self, x):
706
+ if _OPT_AVAILABLE:
707
+ return optimized_softmax_2d(np.asarray(x, dtype=np.float64))
708
+
694
709
  if x.ndim == 3:
695
710
  shifted = x - np.max(x, axis=-1, keepdims=True)
696
711
  else:
@@ -1166,6 +1181,7 @@ class Transformer:
1166
1181
 
1167
1182
  return grads, total_norm
1168
1183
 
1184
+
1169
1185
  def batch_padding_utility(self, sequences, pad_token_id=0):
1170
1186
  # sequences: list of 1-D np arrays of varying length
1171
1187
  max_len = max(len(s) for s in sequences)
@@ -1353,6 +1369,10 @@ class Transformer:
1353
1369
 
1354
1370
  def anisotropy_measurement(self, x):
1355
1371
  eps = 1e-5
1372
+ if _OPT_AVAILABLE:
1373
+ x = x.reshape(x.shape[0], -1)
1374
+ return optimized_anisotropy(np.asarray(x, dtype=np.float64))
1375
+
1356
1376
  try:
1357
1377
  gradient = np.gradient(x)
1358
1378
  except:
@@ -1637,6 +1657,8 @@ class MLP:
1637
1657
 
1638
1658
  def AME_Encoder(self, x):
1639
1659
  X = np.asarray(x)
1660
+ if _OPT_AVAILABLE and np.asarray(X).ndim == 2:
1661
+ return optimized_ame_encoder(np.asarray(X, dtype=np.float64))
1640
1662
 
1641
1663
  if x.shape[1] == 1:
1642
1664
  x = x.T
@@ -1652,6 +1674,10 @@ class MLP:
1652
1674
 
1653
1675
  def anisotropy_measurement(self, x):
1654
1676
  eps = 1e-5
1677
+ if _OPT_AVAILABLE:
1678
+ x = x.reshape(x.shape[0], -1)
1679
+ return optimized_anisotropy(np.asarray(x, dtype=np.float64))
1680
+
1655
1681
  try:
1656
1682
  gradient = np.gradient(x)
1657
1683
  except:
@@ -2771,6 +2797,10 @@ class WeightedEnsemblePredictor:
2771
2797
 
2772
2798
  def anisotropy_measurement(self, x):
2773
2799
  eps = 1e-5
2800
+ if _OPT_AVAILABLE:
2801
+ x = x.reshape(x.shape[0], -1)
2802
+ return optimized_anisotropy(np.asarray(x, dtype=np.float64))
2803
+
2774
2804
  try:
2775
2805
  try:
2776
2806
  grads = np.gradient(x)
@@ -3671,6 +3701,9 @@ class ExplainabilityModule:
3671
3701
 
3672
3702
  def AME_Encoder(self, x):
3673
3703
  X = np.asarray(x)
3704
+ if _OPT_AVAILABLE and np.asarray(X).ndim == 2:
3705
+ return optimized_ame_encoder(np.asarray(X, dtype=np.float64))
3706
+
3674
3707
 
3675
3708
  try:
3676
3709
  gradient = np.gradient(x, axis=-1)
@@ -8099,6 +8132,26 @@ class IntegratedPipeline:
8099
8132
  print('[!] Value is single scalar! returning 0.0 similarity')
8100
8133
  return 0.0
8101
8134
 
8135
+ if isinstance(a, (str, np.str_)):
8136
+ clean_str = str(a).replace('[', '').replace(']', '')
8137
+ a = np.fromstring(clean_str, sep=' ')
8138
+ if isinstance(a, np.ndarray) and np.issubdtype(a.dtype, np.character):
8139
+ # catches arrays filled with string text
8140
+ clean_str = ' '.join(a.astype(str).flatten()).replace('[', '').replace(']', '')
8141
+ a = np.fromiter(
8142
+ (v for v in clean_str.split() if a != "..."), dtype=float
8143
+ )
8144
+
8145
+ if isinstance(b, (str, np.str_)):
8146
+ clean_str = str(b).replace('[', '').replace(']', '')
8147
+ b = np.fromstring(clean_str, sep=' ')
8148
+ if isinstance(b, np.ndarray) and np.issubdtype(b.dtype, np.character):
8149
+ # catches arrays filled with string text
8150
+ clean_str = ' '.join(b.astype(str).flatten()).replace('[', '').replace(']', '')
8151
+ b = np.fromiter(
8152
+ (v for v in clean_str.split() if b != "..."), dtype=float
8153
+ )
8154
+
8102
8155
  if isinstance(a[0], (np.ndarray, list)):
8103
8156
  norm_a = np.linalg.norm(a[0])
8104
8157
  else:
@@ -8108,7 +8161,16 @@ class IntegratedPipeline:
8108
8161
  norm_b = np.linalg.norm(b[0])
8109
8162
  else:
8110
8163
  norm_b = np.linalg.norm(b)
8111
-
8164
+
8165
+ if _OPT_AVAILABLE:
8166
+ if len(a.shape) > 1:
8167
+ a = np.asarray(a)
8168
+ a = a.reshape(-1)
8169
+ if len(b.shape) > 1:
8170
+ b = np.asarray(b)
8171
+ b = b.reshape(-1)
8172
+ return optimized_cosine_similarity(np.asarray(a, dtype=np.float64), np.asarray(b, dtype=np.float64))
8173
+
8112
8174
  try:
8113
8175
  dot_product = np.dot(a, b)
8114
8176
  except:
@@ -8316,12 +8378,42 @@ class IntegratedPipeline:
8316
8378
 
8317
8379
  def cosine_similarity(self, a, b):
8318
8380
  eps = 1e-5
8381
+ if isinstance(a, (str, np.str_)):
8382
+ clean_str = str(a).replace('[', '').replace(']', '')
8383
+ a = np.fromstring(clean_str, sep=' ')
8384
+ if isinstance(a, np.ndarray) and np.issubdtype(a.dtype, np.character):
8385
+ # catches arrays filled with string text
8386
+ clean_str = ' '.join(a.astype(str).flatten()).replace('[', '').replace(']', '')
8387
+ a = np.fromiter(
8388
+ (v for v in clean_str.split() if a != "..."), dtype=float
8389
+ )
8390
+
8391
+ if isinstance(b, (str, np.str_)):
8392
+ clean_str = str(b).replace('[', '').replace(']', '')
8393
+ b = np.fromstring(clean_str, sep=' ')
8394
+ if isinstance(b, np.ndarray) and np.issubdtype(b.dtype, np.character):
8395
+ # catches arrays filled with string text
8396
+ clean_str = ' '.join(b.astype(str).flatten()).replace('[', '').replace(']', '')
8397
+ b = np.fromiter(
8398
+ (v for v in clean_str.split() if b != "..."), dtype=float
8399
+ )
8400
+
8319
8401
  if isinstance(b, (float, int)) or isinstance(a, (float, int)):
8320
8402
  print('[!] Value is single scalar! returning 0.0 similarity')
8321
8403
  return 0.0
8322
8404
 
8323
8405
  b = b[0]
8324
-
8406
+
8407
+ if _OPT_AVAILABLE:
8408
+ if len(a.shape) > 1:
8409
+ a = np.asarray(a)
8410
+ a = a.reshape(-1)
8411
+ if len(b.shape) > 1:
8412
+ b = np.asarray(b)
8413
+ b = b.reshape(-1)
8414
+
8415
+ return optimized_cosine_similarity(np.asarray(a, dtype=np.float64), np.asarray(b, dtype=np.float64))
8416
+
8325
8417
  try:
8326
8418
  # Handle variable b
8327
8419
  if isinstance(b, (str, np.str_)):
@@ -8402,12 +8494,27 @@ class IntegratedPipeline:
8402
8494
 
8403
8495
  def anisotropy_measurement(self, x):
8404
8496
  eps = 1e-5
8497
+
8498
+ if isinstance(x, (str, np.str_)):
8499
+ clean_str = str(x).replace('[', '').replace(']', '')
8500
+ x = np.fromstring(clean_str, sep=' ')
8501
+ if isinstance(x, np.ndarray) and np.issubdtype(x.dtype, np.character):
8502
+ # catches arrays filled with string text
8503
+ clean_str = ' '.join(x.astype(str).flatten()).replace('[', '').replace(']', '')
8504
+ x = np.fromiter(
8505
+ (v for v in clean_str.split() if x != "..."), dtype=float
8506
+ )
8507
+
8508
+ if _OPT_AVAILABLE:
8509
+ x = x.reshape(-1, 1)
8510
+ return optimized_anisotropy(np.asarray(x, dtype=np.float64))
8405
8511
 
8406
8512
  if isinstance(x, list):
8407
8513
  print(f'[=] Converting list to array with shape: {len(x)}')
8408
8514
  x = np.array(x)
8409
8515
  x = x.reshape(x.shape[0], -1) # Flatten if necessary
8410
8516
 
8517
+
8411
8518
  try:
8412
8519
  try:
8413
8520
  grads = np.gradient(x)
@@ -9524,37 +9631,46 @@ class IntegratedPipeline:
9524
9631
  batch_size = len(target_preds)
9525
9632
  eps = 1e-5
9526
9633
 
9527
- for i in range(batch_size):
9528
- mlp_target = target_preds[i]
9634
+ try:
9635
+ for i in range(batch_size):
9636
+ mlp_target = target_preds[i]
9529
9637
 
9530
- if attn_weights is None:
9531
- anisotropy = self.anisotropy_measurement(mlp_target)
9532
- else:
9533
- anisotropy = self.anisotropy_measurement(attn_weights[i])
9534
- if attn_weights is not None and i < len(attn_weights):
9535
- attn = attn_weights[i]
9536
-
9537
- score_quality = np.std(attn) if attn.size > 0 else self.confidence_threshold
9538
- abstract_score = self.confidence_threshold + score_quality * anisotropy
9638
+ if attn_weights is None:
9639
+ anisotropy = self.anisotropy_measurement(mlp_target)
9640
+ else:
9641
+ try:
9642
+ anisotropy = self.anisotropy_measurement(attn_weights[i])
9643
+ except:
9644
+ anisotropy = self.anisotropy_measurement(attn_weights)
9645
+
9646
+ if attn_weights is not None and i < len(attn_weights):
9647
+ attn = attn_weights[i]
9648
+
9649
+ score_quality = np.std(attn) if attn.size > 0 else self.confidence_threshold
9650
+ abstract_score = self.confidence_threshold + score_quality * anisotropy
9539
9651
 
9540
- else:
9541
- if attn_weights is not None:
9542
- score_quality = 1.0 / (1.0 + np.exp(-attn_weights[i]))
9543
9652
  else:
9544
- score_quality = 1.0 / (1.0 + np.exp(-mlp_target))
9653
+ if attn_weights is not None:
9654
+ score_quality = 1.0 / (1.0 + np.exp(-attn_weights[i]))
9655
+ else:
9656
+ score_quality = 1.0 / (1.0 + np.exp(-mlp_target))
9545
9657
 
9546
- abstract_score = (1.0 - score_quality) + eps
9658
+ abstract_score = (1.0 - score_quality) + eps
9547
9659
 
9548
- self.temperature = (1.0 - abstract_score) + score_quality * anisotropy
9549
- if isinstance(self.temperature, np.ndarray):
9550
- self.temperature = np.clip(np.mean(self.temperature), 1e-5, 5.0)
9660
+ self.temperature = (1.0 - abstract_score) + score_quality * anisotropy
9661
+ if isinstance(self.temperature, np.ndarray):
9662
+ self.temperature = np.clip(np.mean(self.temperature), 1e-5, 5.0)
9551
9663
 
9552
- try:
9553
- calibrated[i, mlp_target] = min(calibrated[i, mlp_target] * (1.5 * (1.0 - abstract_score)), 0.95)
9554
- except:
9555
- return calibrated
9664
+ try:
9665
+ calibrated[i, mlp_target] = min(calibrated[i, mlp_target] * (1.5 * (1.0 - abstract_score)), 0.95)
9666
+ except:
9667
+ return calibrated
9668
+
9669
+ calibrated[i] /= calibrated[i].sum()
9670
+ except Exception as e:
9671
+ print(f'[!] cant calibrate probability due to: {e}, returning regular probability.')
9672
+ calibrated = calibrated.copy()
9556
9673
 
9557
- calibrated[i] /= calibrated[i].sum()
9558
9674
  return calibrated
9559
9675
 
9560
9676
  def _softmax(self, x):
@@ -9778,6 +9894,8 @@ class IntegratedPipeline:
9778
9894
  X = np.fromiter(
9779
9895
  (x for x in clean_str.split() if x != "..."), dtype=float
9780
9896
  )
9897
+ if _OPT_AVAILABLE and np.asarray(X).ndim == 2:
9898
+ return optimized_ame_encoder(np.asarray(X, dtype=np.float64))
9781
9899
 
9782
9900
  X = np.squeeze(X)
9783
9901
  if X.ndim == 1:
@@ -13131,6 +13249,10 @@ class PipelinePredictionManager:
13131
13249
  if self.pipeline.autonomous and sec_confidence > self.pipeline.confidence_threshold:
13132
13250
  print(f'[⚡] Autonomous Prediction used second predicted label: {sec_chosen_label}')
13133
13251
  chosen_label = sec_chosen_label
13252
+
13253
+ # delete pipelines cache
13254
+ print('[🔍] Pipelines Cache Cleaned!')
13255
+ self.pipeline.cache.clear()
13134
13256
 
13135
13257
  return results, chosen_label, confidence
13136
13258
 
@@ -13150,14 +13272,15 @@ class PipelinePredictionManager:
13150
13272
  if result.get('expected'):
13151
13273
  total_with_expected += 1
13152
13274
  status = ": ✅" if result['predicted'] == result['expected'] else ": ❌"
13153
- sec_status = ": ✅" if result['sec_predicted'] == result['expected'] else ": ❌"
13154
13275
  print(f"[=] First Expectation: {result['expected']} || Model Answer: {status}")
13155
- print(f"[=] Second Expectation: {result['expected']} || Model Answer: {sec_status}")
13276
+ if 'sec_predicted' in result:
13277
+ sec_status = ": ✅" if result['sec_predicted'] == result['expected'] else ": ❌"
13278
+ print(f"[=] Second Expectation: {result['expected']} || Model Answer: {sec_status}")
13279
+ if result['sec_predicted'] == result['expected']:
13280
+ sec_correct += 1
13156
13281
 
13157
13282
  if result['predicted'] == result['expected']:
13158
13283
  correct += 1
13159
- if result['sec_predicted'] == result['expected']:
13160
- sec_correct += 1
13161
13284
 
13162
13285
  # Agreement indicator
13163
13286
  agree_symbol = "✓" if result.get('models_agree', True) else "⚠️"