AbstractIntegratedModule 0.8.7__tar.gz → 0.8.8__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.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.egg-info/PKG-INFO +5 -3
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.py +253 -109
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/PKG-INFO +5 -3
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/README.md +4 -2
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/setup.py +1 -1
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/MANIFEST.in +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/pyproject.toml +0 -0
- {abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.8
|
|
4
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
|
|
@@ -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: 0.8.
|
|
45
|
+
- Development Stage: 0.8.8 Official Release.
|
|
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.
|
|
@@ -80,10 +80,12 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
80
80
|
- Transformer Optimized using Cython, to reduce Memory overhead and Reduce CPU Usage, With Reduced Training Time.
|
|
81
81
|
______________
|
|
82
82
|
- Changelog:
|
|
83
|
-
- v0.8.
|
|
83
|
+
- v0.8.8:
|
|
84
84
|
- [=] New features:
|
|
85
85
|
- Added new continuos predictive correction for MLP class to reduce inflated confidence despite outputting wrong answer.
|
|
86
86
|
- Reduced the frequency of penalty based calibration in advanced prediction method to prevent the models from being too conservative.
|
|
87
|
+
- Fixed Aggressive Memory deletion capability bug to prevent Careless memory deletion because of tuple type variables wrapping the probability after its saved to the memory.
|
|
88
|
+
- added robustness for Memory corruption check and sanity.
|
|
87
89
|
- Fixed P2P Vulnerabilities:
|
|
88
90
|
- Empty allowed_ips in PRODUCTION/HARDENED mode now DENIES external IPs instead of allowing all
|
|
89
91
|
- Startup validation warns about dangerous config combinations
|
{abstractintegratedmodule-0.8.7 → abstractintegratedmodule-0.8.8}/AbstractIntegratedModule.py
RENAMED
|
@@ -2487,6 +2487,8 @@ class LSTMEngine:
|
|
|
2487
2487
|
|
|
2488
2488
|
print("[=] Training complete!")
|
|
2489
2489
|
print(f"[=] Final val loss: {val_loss:.6f}")
|
|
2490
|
+
|
|
2491
|
+
|
|
2490
2492
|
print('===== CALIBRATION METHOD =====')
|
|
2491
2493
|
self.calibrate_residual(X_te, Y_te)
|
|
2492
2494
|
|
|
@@ -8637,111 +8639,237 @@ class IntegratedPipeline:
|
|
|
8637
8639
|
|
|
8638
8640
|
def is_memory_corrupted(self, memory, num_classes: int = None) -> tuple:
|
|
8639
8641
|
"""
|
|
8640
|
-
Robust memory corruption detection.
|
|
8641
|
-
|
|
8642
|
+
Robust memory corruption detection here.
|
|
8643
|
+
|
|
8642
8644
|
Returns:
|
|
8643
8645
|
(is_corrupted: bool, reason: str, suggested_fix: str)
|
|
8644
8646
|
"""
|
|
8645
8647
|
if num_classes is None:
|
|
8646
|
-
num_classes = self._get_num_classes()
|
|
8647
|
-
|
|
8648
|
-
# Case 1:
|
|
8648
|
+
num_classes = self._get_num_classes() or 0
|
|
8649
|
+
|
|
8650
|
+
# ── Case 1: None ──────────────────────────────────────────────
|
|
8649
8651
|
if memory is None:
|
|
8650
8652
|
return (True, "Memory is None", "Initialize new memory dict")
|
|
8651
|
-
|
|
8652
|
-
# Case 2:
|
|
8653
|
+
|
|
8654
|
+
# ── Case 2: numpy array ───────────────────────────────────────
|
|
8653
8655
|
if isinstance(memory, np.ndarray):
|
|
8654
|
-
# Valid probability array
|
|
8655
8656
|
if memory.ndim == 1 and memory.shape[0] == num_classes:
|
|
8656
8657
|
return (False, "Valid probability array", None)
|
|
8657
|
-
|
|
8658
|
-
# Valid probability matrix (batch)
|
|
8659
8658
|
if memory.ndim == 2 and memory.shape[1] == num_classes:
|
|
8660
8659
|
return (False, "Valid probability matrix", None)
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
"Clear and retrain
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8660
|
+
if memory.shape[0] == 0:
|
|
8661
|
+
return (True, "Empty array", "Clear and reinitialize")
|
|
8662
|
+
return (True,
|
|
8663
|
+
f"Unexpected array shape: {memory.shape} for {num_classes} classes",
|
|
8664
|
+
"Clear memory and retrain model")
|
|
8665
|
+
|
|
8666
|
+
# ── Case 3: tuple ─────────────────────────────────────────────
|
|
8667
|
+
# tuples are valid memory entries — (input, output) pairs
|
|
8668
|
+
# only corrupt if: single element, or contains non-serializable types
|
|
8669
|
+
if isinstance(memory, tuple):
|
|
8670
|
+
return self._validate_tuple_memory(memory, num_classes)
|
|
8671
|
+
|
|
8672
|
+
# ── Case 4: list ──────────────────────────────────────────────
|
|
8672
8673
|
if isinstance(memory, list):
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8674
|
+
return self._validate_list_memory(memory, num_classes)
|
|
8675
|
+
|
|
8676
|
+
# ── Case 5: dict ──────────────────────────────────────────────
|
|
8677
|
+
if isinstance(memory, dict):
|
|
8678
|
+
return self._validate_dict_memory(memory, num_classes)
|
|
8679
|
+
|
|
8680
|
+
# ── Case 6: scalar numbers — sometimes stored as cached probs ──
|
|
8681
|
+
if isinstance(memory, (int, float, np.integer, np.floating)):
|
|
8682
|
+
if 0.0 <= float(memory) <= 1.0:
|
|
8683
|
+
return (False, "Valid scalar probability", None)
|
|
8684
|
+
return (True,
|
|
8685
|
+
f"Scalar value {memory} out of [0,1] range",
|
|
8686
|
+
"Clear and reinitialize")
|
|
8687
|
+
|
|
8688
|
+
return (True,
|
|
8689
|
+
f"Unexpected memory type: {type(memory).__name__}",
|
|
8690
|
+
"Clear and reinitialize memory")
|
|
8691
|
+
|
|
8692
|
+
|
|
8693
|
+
def _validate_tuple_memory(self, memory: tuple, num_classes: int) -> tuple:
|
|
8694
|
+
"""
|
|
8695
|
+
Validate tuple memory entry.
|
|
8696
|
+
Valid: (input, output), (input, label), (features, probs)
|
|
8697
|
+
Invalid: single-element, or contains obviously corrupt values
|
|
8698
|
+
"""
|
|
8699
|
+
# single element tuple — almost always a mistake since prob is never single
|
|
8700
|
+
if len(memory) < 2:
|
|
8701
|
+
return (True,
|
|
8702
|
+
f"Single-element tuple — likely wrapping error",
|
|
8703
|
+
"Unwrap or clear entry")
|
|
8704
|
+
|
|
8705
|
+
# check each element for validity here
|
|
8706
|
+
for element_idx, element in enumerate(memory[:4]): # check first 4 elements max first
|
|
8707
|
+
|
|
8708
|
+
# None elements in a tuple are suspicious
|
|
8709
|
+
if element is None:
|
|
8710
|
+
return (True,
|
|
8711
|
+
f"Tuple contains None at position {element_idx}",
|
|
8712
|
+
"Clear this memory entry")
|
|
8713
|
+
|
|
8714
|
+
# string elements — check for weird symbols that may appearr here
|
|
8715
|
+
if isinstance(element, str):
|
|
8716
|
+
# allow normal text but flag obviously corrupted strings
|
|
8717
|
+
if len(element) == 0:
|
|
8718
|
+
return (True,
|
|
8719
|
+
f"Tuple contains empty string at position {element_idx}",
|
|
8720
|
+
"Clear this memory entry")
|
|
8721
|
+
# check for non-printable / control characters hiding
|
|
8722
|
+
non_printable = sum(1 for c in element if ord(c) < 32 and c not in '\n\t\r')
|
|
8723
|
+
if non_printable > 0:
|
|
8724
|
+
return (True,
|
|
8725
|
+
f"Tuple string at position {element_idx} contains "
|
|
8726
|
+
f"{non_printable} non-printable characters",
|
|
8727
|
+
"Clear this memory entry")
|
|
8728
|
+
# suspiciously long string — likely serialization artifact from pickle
|
|
8729
|
+
if len(element) > 2000:
|
|
8730
|
+
return (True,
|
|
8731
|
+
f"Tuple string at position {element_idx} is "
|
|
8732
|
+
f"suspiciously long ({len(element)} chars)",
|
|
8733
|
+
"Clear this memory entry")
|
|
8734
|
+
|
|
8735
|
+
# numpy array elements — check shape sanity first
|
|
8736
|
+
elif isinstance(element, np.ndarray):
|
|
8737
|
+
if element.size == 0:
|
|
8738
|
+
return (True,
|
|
8739
|
+
f"Tuple contains empty array at position {element_idx}",
|
|
8740
|
+
"Clear this memory entry")
|
|
8741
|
+
if not np.isfinite(element).all():
|
|
8742
|
+
return (True,
|
|
8743
|
+
f"Tuple array at position {element_idx} contains "
|
|
8744
|
+
f"NaN or Inf values",
|
|
8745
|
+
"Clear this memory entry")
|
|
8746
|
+
|
|
8747
|
+
# numeric scalars — sanity check
|
|
8748
|
+
elif isinstance(element, (int, float, np.integer, np.floating)):
|
|
8749
|
+
if not np.isfinite(float(element)):
|
|
8750
|
+
return (True,
|
|
8751
|
+
f"Tuple contains non-finite scalar at position {element_idx}",
|
|
8752
|
+
"Clear this memory entry")
|
|
8753
|
+
|
|
8754
|
+
# nested tuple/list — valid.
|
|
8755
|
+
elif isinstance(element, (tuple, list)):
|
|
8756
|
+
if len(element) == 0:
|
|
8757
|
+
return (True,
|
|
8758
|
+
f"Tuple contains empty sequence at position {element_idx}",
|
|
8759
|
+
"Clear this memory entry")
|
|
8760
|
+
|
|
8761
|
+
# other types — flag as suspicious, can be deleted.
|
|
8762
|
+
else:
|
|
8763
|
+
type_name = type(element).__name__
|
|
8764
|
+
if type_name not in ('bool', 'bool_', 'datetime'):
|
|
8765
|
+
return (True,
|
|
8766
|
+
f"Tuple contains unexpected type {type_name} "
|
|
8767
|
+
f"at position {element_idx}",
|
|
8768
|
+
"Need to Clear this memory entry")
|
|
8769
|
+
|
|
8770
|
+
return (False, f"Valid tuple memory entry (len={len(memory)})", None)
|
|
8771
|
+
|
|
8772
|
+
|
|
8773
|
+
def _validate_list_memory(self, memory: list, num_classes: int) -> tuple:
|
|
8774
|
+
"""Validate list memory — probability lists, entry lists, feature lists."""
|
|
8775
|
+
if not memory:
|
|
8776
|
+
return (True, "Empty list", "Initialize new memory dict")
|
|
8777
|
+
|
|
8778
|
+
# probability list — exact class count, all numeric
|
|
8779
|
+
if len(memory) == num_classes:
|
|
8780
|
+
sample = memory[:min(5, len(memory))]
|
|
8781
|
+
if all(isinstance(x, (int, float, np.integer, np.floating)) for x in sample):
|
|
8782
|
+
vals = [float(x) for x in sample]
|
|
8783
|
+
if all(0.0 <= v <= 1.0 for v in vals):
|
|
8784
|
+
return (False, "Valid probability list", None)
|
|
8785
|
+
|
|
8786
|
+
# list of valid memory entries — tuples or lists of length >= 2
|
|
8787
|
+
sample = memory[:min(5, len(memory))]
|
|
8788
|
+
if all(isinstance(item, (tuple, list)) and len(item) >= 2 for item in sample):
|
|
8789
|
+
# need to validate each tuple entry
|
|
8790
|
+
for item in sample:
|
|
8791
|
+
corrupted, reason, fix = self._validate_tuple_memory(
|
|
8792
|
+
tuple(item) if isinstance(item, list) else item,
|
|
8793
|
+
num_classes
|
|
8794
|
+
)
|
|
8795
|
+
if corrupted:
|
|
8796
|
+
return (True,
|
|
8797
|
+
f"List contains corrupted entry: {reason}",
|
|
8798
|
+
fix)
|
|
8799
|
+
return (False, "Valid memory entries list", None)
|
|
8800
|
+
|
|
8801
|
+
# numpy arrays in list
|
|
8802
|
+
if any(isinstance(item, np.ndarray) for item in sample):
|
|
8803
|
+
arrays = [item for item in memory if isinstance(item, np.ndarray)]
|
|
8804
|
+
if all(a.shape[0] == num_classes or
|
|
8805
|
+
(a.ndim > 1 and a.shape[1] == num_classes) for a in arrays):
|
|
8806
|
+
return (False, "Valid list of probability arrays", None)
|
|
8807
|
+
return (True,
|
|
8808
|
+
f"List contains arrays with mismatched shapes",
|
|
8809
|
+
"Clear and retrain")
|
|
8810
|
+
|
|
8811
|
+
# hybrid feature list — wrong type for memory storage
|
|
8812
|
+
if len(memory) != num_classes:
|
|
8813
|
+
return (True,
|
|
8814
|
+
f"Hybrid feature list (length {len(memory)}, "
|
|
8815
|
+
f"expected {num_classes}) stored as memory",
|
|
8685
8816
|
"Clear memory and retrain")
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
return (False, "[=] Valid memory entries list", None)
|
|
8690
|
-
|
|
8691
|
-
# Check for numpy arrays in list
|
|
8692
|
-
if any(isinstance(item, np.ndarray) for item in memory):
|
|
8693
|
-
arrays = [item.shape for item in memory if isinstance(item, np.ndarray)]
|
|
8694
|
-
if any(shape[0] == num_classes for shape in arrays):
|
|
8695
|
-
return (False, "[=] Valid with numpy arrays", None)
|
|
8696
|
-
|
|
8697
|
-
return (True, f"[=] Suspicious list length: {len(memory)}",
|
|
8817
|
+
|
|
8818
|
+
return (True,
|
|
8819
|
+
f"Suspicious list contents — type: {type(memory[0]).__name__}",
|
|
8698
8820
|
"Inspect memory contents")
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
# Suspicious key
|
|
8715
|
-
if isinstance(key, (int, float)):
|
|
8716
|
-
return (True, f"[=] Dict has numeric key: {key}",
|
|
8821
|
+
|
|
8822
|
+
|
|
8823
|
+
def _validate_dict_memory(self, memory: dict, num_classes: int) -> tuple:
|
|
8824
|
+
"""Validate dict memory — expected primary format."""
|
|
8825
|
+
if not memory:
|
|
8826
|
+
return (False, "Empty dict (no memory yet)", None)
|
|
8827
|
+
|
|
8828
|
+
valid_keys = {'TW', 'MW', 'TP', 'MP', 'TA', 'local',
|
|
8829
|
+
'_cached_probs', '_data'}
|
|
8830
|
+
|
|
8831
|
+
for key, value in memory.items():
|
|
8832
|
+
# numeric keys — deserialization artifact
|
|
8833
|
+
if isinstance(key, (int, float)):
|
|
8834
|
+
return (True,
|
|
8835
|
+
f"Dict has numeric key: {key}",
|
|
8717
8836
|
"Likely deserialization error, clear memory")
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8837
|
+
|
|
8838
|
+
# suspiciously long key
|
|
8839
|
+
if len(str(key)) > 100:
|
|
8840
|
+
return (True,
|
|
8841
|
+
f"Dict has very long key ({len(str(key))} chars)",
|
|
8721
8842
|
"Possible corruption, clear memory")
|
|
8722
|
-
|
|
8723
|
-
#
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
return (True,
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8843
|
+
|
|
8844
|
+
# validate array values
|
|
8845
|
+
if isinstance(value, np.ndarray):
|
|
8846
|
+
if num_classes > 0 and value.ndim > 0:
|
|
8847
|
+
if value.shape[0] != num_classes and \
|
|
8848
|
+
(value.ndim < 2 or value.shape[1] != num_classes):
|
|
8849
|
+
return (True,
|
|
8850
|
+
f"Array shape {value.shape} doesn't match "
|
|
8851
|
+
f"{num_classes} classes in key '{key}'",
|
|
8852
|
+
"Hybrid feature stored incorrectly, clear entry")
|
|
8853
|
+
if value.size == 0:
|
|
8854
|
+
return (True,
|
|
8855
|
+
f"Empty array in key '{key}'",
|
|
8733
8856
|
"Corrupted array, clear entry")
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
8742
|
-
|
|
8743
|
-
|
|
8744
|
-
|
|
8857
|
+
if not np.isfinite(value).all():
|
|
8858
|
+
return (True,
|
|
8859
|
+
f"NaN/Inf values in array at key '{key}'",
|
|
8860
|
+
"Corrupted values, clear entry")
|
|
8861
|
+
|
|
8862
|
+
# validate tuple values in dict
|
|
8863
|
+
elif isinstance(value, tuple):
|
|
8864
|
+
corrupted, reason, fix = self._validate_tuple_memory(
|
|
8865
|
+
value, num_classes
|
|
8866
|
+
)
|
|
8867
|
+
if corrupted:
|
|
8868
|
+
return (True,
|
|
8869
|
+
f"Corrupted tuple value at key '{key}': {reason}",
|
|
8870
|
+
fix)
|
|
8871
|
+
|
|
8872
|
+
return (False, "Valid dict structure", None)
|
|
8745
8873
|
|
|
8746
8874
|
|
|
8747
8875
|
def initialize_fitting(self, text):
|
|
@@ -9503,8 +9631,7 @@ class IntegratedPipeline:
|
|
|
9503
9631
|
|
|
9504
9632
|
def model_memory_gate(self, x, x2):
|
|
9505
9633
|
memory = self.memory
|
|
9506
|
-
is_corrupted, reason, _ = self.is_memory_corrupted(memory)
|
|
9507
|
-
|
|
9634
|
+
is_corrupted, reason, _ = self.is_memory_corrupted(memory)
|
|
9508
9635
|
|
|
9509
9636
|
if isinstance(memory, np.ndarray):
|
|
9510
9637
|
if self._get_num_classes() and memory.shape[-1] == self._get_num_classes():
|
|
@@ -9566,8 +9693,8 @@ class IntegratedPipeline:
|
|
|
9566
9693
|
print(f'[!] Removing corrupted entry {key}: {reason}')
|
|
9567
9694
|
del memory[key]
|
|
9568
9695
|
|
|
9569
|
-
cache_trans_memory = [key for key, (inp) in memory.items() if key.startswith('TW') and (isinstance(inp, np.ndarray) or isinstance(inp, list)) and self.cosine_robust_similarity(x, inp) >= 0.
|
|
9570
|
-
cache_mlp_memory = [key for key, (inp2) in memory.items() if key.startswith('MW') and (isinstance(inp2, np.ndarray) or isinstance(inp2, list)) and self.cosine_similarity(x2, inp2) >= 0.
|
|
9696
|
+
cache_trans_memory = [key for key, (inp) in memory.items() if key.startswith('TW') and (isinstance(inp, np.ndarray) or isinstance(inp, list)) and self.cosine_robust_similarity(x, inp) >= 0.8]
|
|
9697
|
+
cache_mlp_memory = [key for key, (inp2) in memory.items() if key.startswith('MW') and (isinstance(inp2, np.ndarray) or isinstance(inp2, list)) and self.cosine_similarity(x2, inp2) >= 0.8]
|
|
9571
9698
|
|
|
9572
9699
|
if cache_mlp_memory and cache_trans_memory:
|
|
9573
9700
|
for memo in cache_trans_memory:
|
|
@@ -9582,7 +9709,7 @@ class IntegratedPipeline:
|
|
|
9582
9709
|
output = out.copy()
|
|
9583
9710
|
return output
|
|
9584
9711
|
else:
|
|
9585
|
-
if cache_mlp_memory:
|
|
9712
|
+
if len(cache_mlp_memory) > 0:
|
|
9586
9713
|
print('[+] Found matching memory from mlp past memory!')
|
|
9587
9714
|
for memo in cache_mlp_memory:
|
|
9588
9715
|
_, out = memory[memo]
|
|
@@ -9592,7 +9719,7 @@ class IntegratedPipeline:
|
|
|
9592
9719
|
output = out.copy()
|
|
9593
9720
|
return output
|
|
9594
9721
|
|
|
9595
|
-
elif cache_trans_memory:
|
|
9722
|
+
elif len(cache_trans_memory) > 0:
|
|
9596
9723
|
print('[+] Found matching memory from transformer past memory!')
|
|
9597
9724
|
for memo in cache_trans_memory:
|
|
9598
9725
|
_, out = memory[memo]
|
|
@@ -9604,9 +9731,7 @@ class IntegratedPipeline:
|
|
|
9604
9731
|
|
|
9605
9732
|
else:
|
|
9606
9733
|
print('🔄 No Matching Memory!')
|
|
9607
|
-
return None
|
|
9608
|
-
|
|
9609
|
-
|
|
9734
|
+
return None
|
|
9610
9735
|
else:
|
|
9611
9736
|
print('[!] No matching memory types!')
|
|
9612
9737
|
return None
|
|
@@ -9696,10 +9821,13 @@ class IntegratedPipeline:
|
|
|
9696
9821
|
print(f'[!] Cannot convert to array: {type(value)}')
|
|
9697
9822
|
return None
|
|
9698
9823
|
|
|
9699
|
-
|
|
9700
9824
|
|
|
9701
9825
|
|
|
9702
9826
|
def model_probability_gate(self, x, x2):
|
|
9827
|
+
output_trans = None
|
|
9828
|
+
output_mlp = None
|
|
9829
|
+
out = None
|
|
9830
|
+
|
|
9703
9831
|
memory = self.memory
|
|
9704
9832
|
is_corrupted, reason, _ = self.is_memory_corrupted(memory)
|
|
9705
9833
|
|
|
@@ -9707,7 +9835,7 @@ class IntegratedPipeline:
|
|
|
9707
9835
|
if self._get_num_classes() and not memory.shape[-1] == self._get_num_classes():
|
|
9708
9836
|
if is_corrupted:
|
|
9709
9837
|
print('[!] Memory corruption detected, Trying possible conversion to extract memory...')
|
|
9710
|
-
print(f'[REASON]: {reason}')
|
|
9838
|
+
print(f'[MEMORY FAULT REASON]: {reason}')
|
|
9711
9839
|
else:
|
|
9712
9840
|
print('[+] Memory is a direct probability, converting...')
|
|
9713
9841
|
|
|
@@ -9760,21 +9888,34 @@ class IntegratedPipeline:
|
|
|
9760
9888
|
print(f'[!] Removing corrupted entry {key}: {reason}')
|
|
9761
9889
|
del memory[key]
|
|
9762
9890
|
|
|
9763
|
-
cache_trans_memory = [key for key, (inp) in memory.items() if key.startswith('TP') and (isinstance(inp, np.ndarray) or isinstance(inp, list)) and self.cosine_robust_similarity(x, inp) >= 0.
|
|
9764
|
-
cache_mlp_memory = [key for key, (inp2) in memory.items() if key.startswith('MP') and (isinstance(inp2, np.ndarray) or isinstance(inp2, list)) and self.cosine_similarity(x2, inp2) >= 0.
|
|
9891
|
+
cache_trans_memory = [key for key, (inp) in memory.items() if key.startswith('TP') and (isinstance(inp, np.ndarray) or isinstance(inp, list)) and self.cosine_robust_similarity(x, inp) >= 0.85]
|
|
9892
|
+
cache_mlp_memory = [key for key, (inp2) in memory.items() if key.startswith('MP') and (isinstance(inp2, np.ndarray) or isinstance(inp2, list)) and self.cosine_similarity(x2, inp2) >= 0.85]
|
|
9765
9893
|
|
|
9766
|
-
if cache_mlp_memory
|
|
9767
|
-
|
|
9768
|
-
|
|
9894
|
+
if len(cache_mlp_memory) > 0 or len(cache_trans_memory) > 0:
|
|
9895
|
+
print('[+] Memory length found:')
|
|
9896
|
+
print(f'[=] MLP Memory length: {len(cache_mlp_memory)}')
|
|
9897
|
+
print(f'[=] Transformer Memory length: {len(cache_trans_memory)}')
|
|
9769
9898
|
|
|
9770
|
-
|
|
9771
|
-
|
|
9899
|
+
if cache_trans_memory is not None:
|
|
9900
|
+
for memo in cache_trans_memory:
|
|
9901
|
+
_, output_trans = memory[memo]
|
|
9902
|
+
if cache_mlp_memory is not None:
|
|
9903
|
+
for memo2 in cache_mlp_memory:
|
|
9904
|
+
_, output_mlp = memory[memo2]
|
|
9905
|
+
|
|
9906
|
+
if output_trans is not None:
|
|
9907
|
+
out = output_trans.copy()
|
|
9908
|
+
elif output_mlp is not None:
|
|
9909
|
+
out = output_mlp.copy()
|
|
9910
|
+
else:
|
|
9911
|
+
print('[!] No matched memory from given samples.')
|
|
9772
9912
|
|
|
9773
|
-
if isinstance(out, str):
|
|
9913
|
+
if out is not None and isinstance(out, str):
|
|
9774
9914
|
out = np.array([float(x) for x in out.strip('[]').split(',')]) # Convert string to numpy array
|
|
9775
9915
|
|
|
9776
|
-
output = out
|
|
9777
|
-
return output
|
|
9916
|
+
output = out if out is not None else None
|
|
9917
|
+
return output
|
|
9918
|
+
|
|
9778
9919
|
else:
|
|
9779
9920
|
print('🔄 No Matching Probability!')
|
|
9780
9921
|
return None
|
|
@@ -10624,6 +10765,7 @@ class IntegratedPipeline:
|
|
|
10624
10765
|
|
|
10625
10766
|
def _calibrate_probs(self, probs, target_preds, attn_weights, input_ids):
|
|
10626
10767
|
calibrated = probs.copy()
|
|
10768
|
+
mlp_target_int = None
|
|
10627
10769
|
|
|
10628
10770
|
if isinstance(input_ids, list):
|
|
10629
10771
|
input_ids = np.array(input_ids)
|
|
@@ -10692,6 +10834,8 @@ class IntegratedPipeline:
|
|
|
10692
10834
|
|
|
10693
10835
|
# bounds guard before indexing
|
|
10694
10836
|
if 0 <= mlp_target < n_classes and i < calibrated.shape[0]:
|
|
10837
|
+
if mlp_target_int is None:
|
|
10838
|
+
mlp_target_int = int(mlp_target.flat[0])
|
|
10695
10839
|
calibrated[i, mlp_target_int] = min(
|
|
10696
10840
|
calibrated[i, mlp_target_int] * (1.5 * (1.0 - abstract_score)), 0.95
|
|
10697
10841
|
)
|