AbstractIntegratedModule 1.1.7.5__tar.gz → 1.1.9__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 (23) hide show
  1. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
  2. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.py +118 -56
  3. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractOptimizedModules.c +200 -200
  4. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/PKG-INFO +1 -1
  5. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/README.md +7 -7
  6. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/pyproject.toml +1 -1
  7. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/setup.py +1 -1
  8. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
  9. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
  10. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
  11. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
  12. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/AbstractOptimizedModules.pyx +0 -0
  13. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/MANIFEST.in +0 -0
  14. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/Cargo.toml +0 -0
  15. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/pyproject.toml +0 -0
  16. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/src/lib.rs +0 -0
  17. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
  18. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
  19. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
  20. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
  21. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
  22. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
  23. {abstractintegratedmodule-1.1.7.5 → abstractintegratedmodule-1.1.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 1.1.7.5
3
+ Version: 1.1.9
4
4
  Summary: Integrated Pipeline with Specialized Non-LLM AI Agent Framework for ARM64 architecture
5
5
  Author: Micro-Novelty
6
6
  Author-email: Micro-Novelty <hernikpuspita5@gmail.com>
@@ -730,6 +730,8 @@ class Transformer:
730
730
 
731
731
  self.cache = {}
732
732
 
733
+
734
+
733
735
  def _clear_forward_cache(self, keep_essential=True, max_age_forward_passes=5):
734
736
  """Clear cache entries older than max_age_forward_passes."""
735
737
 
@@ -1755,11 +1757,19 @@ class Transformer:
1755
1757
 
1756
1758
  class Dense:
1757
1759
  def __init__(self, x, input_size, output_size, activation=None):
1758
-
1759
1760
  self.special_weight = GeometricWeightShaping(input_size, output_size)
1760
1761
  self.W = self.special_weight.weight_shaping(x)
1761
-
1762
1762
  self.b = np.zeros((1, output_size))
1763
+
1764
+ self.params_shape = {
1765
+ 'W1': self.W.shape,
1766
+ 'b1': self.b.shape
1767
+ }
1768
+ self.params = {
1769
+ 'W1': self.W,
1770
+ 'b1': self.b
1771
+ }
1772
+ self.opt = AdamOptimizer(self.params_shape, lr=0.001, weight_decay=1e-4)
1763
1773
  self.activation_name = activation
1764
1774
 
1765
1775
 
@@ -1870,8 +1880,9 @@ class Dense:
1870
1880
 
1871
1881
  self.W -= (lr * dW)
1872
1882
  self.b -= (lr * db) + (1.0 + perf_score) * 1e-5 # small bias regularization
1873
-
1874
- return dx
1883
+
1884
+ key_grads = {'W1': dW, 'b1': db}
1885
+ return dx, key_grads
1875
1886
 
1876
1887
 
1877
1888
 
@@ -1887,6 +1898,85 @@ class SoftmaxOutput:
1887
1898
  return dL_dZ
1888
1899
 
1889
1900
 
1901
+
1902
+
1903
+ class AdamOptimizer:
1904
+ def __init__(self, params_shapes, lr=0.001, beta1=0.9, beta2=0.999,
1905
+ eps=1e-8, weight_decay=0.0, amsgrad=False):
1906
+ """
1907
+ params_shapes: dict of {param_name: shape} for every trainable param
1908
+ e.g. {'W1': (20,64), 'b1': (64,), 'W2': (64,3), 'b2': (3,)}
1909
+ weight_decay: decoupled weight decay coefficient (AdamW-style, 0 = off)
1910
+ amsgrad: if True, use the AMSGrad variant (max of v_hat history)
1911
+ """
1912
+ self.lr = lr
1913
+ self.beta1 = beta1
1914
+ self.beta2 = beta2
1915
+ self.eps = eps
1916
+ self.weight_decay = weight_decay
1917
+ self.amsgrad = amsgrad
1918
+ self.t = 0
1919
+
1920
+ self.m = {k: np.zeros(shape) for k, shape in params_shapes.items()}
1921
+ self.v = {k: np.zeros(shape) for k, shape in params_shapes.items()}
1922
+ if self.amsgrad:
1923
+ self.v_max = {k: np.zeros(shape) for k, shape in params_shapes.items()}
1924
+
1925
+ def step(self, params, grads, lr=None, clip_norm=None):
1926
+ self.t += 1
1927
+ lr = self.lr if lr is None else lr
1928
+ bc1 = 1 - self.beta1 ** self.t
1929
+ bc2 = 1 - self.beta2 ** self.t
1930
+
1931
+ for key in grads:
1932
+ g = grads[key]
1933
+ g_shape = np.asarray(g).shape
1934
+
1935
+ # reinitialize any moment buffer whose shape has
1936
+ # drifted from the current gradient,
1937
+ for buf_name, buf_dict in (('m', self.m), ('v', self.v)):
1938
+ if key not in buf_dict or np.asarray(buf_dict[key]).shape != g_shape:
1939
+ if key in buf_dict:
1940
+ print(f'[⚠️] Adam: "{buf_name}" buffer for "{key}" stale '
1941
+ f'shape {np.asarray(buf_dict[key]).shape} != '
1942
+ f'expected {g_shape} — reinitializing to zeros')
1943
+ buf_dict[key] = np.zeros(g_shape)
1944
+
1945
+ if self.amsgrad and (key not in self.v_max or
1946
+ np.asarray(self.v_max[key]).shape != g_shape):
1947
+ self.v_max[key] = np.zeros(g_shape)
1948
+
1949
+ if clip_norm is not None:
1950
+ norm = np.linalg.norm(g)
1951
+ if norm > clip_norm:
1952
+ g = g * (clip_norm / norm)
1953
+
1954
+ if self.weight_decay > 0:
1955
+ params[key] -= lr * self.weight_decay * params[key]
1956
+
1957
+ self.m[key] = self.beta1 * self.m[key] + (1 - self.beta1) * g
1958
+ self.v[key] = self.beta2 * self.v[key] + (1 - self.beta2) * (g ** 2)
1959
+ m_hat = self.m[key] / bc1
1960
+
1961
+ if self.amsgrad:
1962
+ self.v_max[key] = np.maximum(self.v_max[key], self.v[key])
1963
+ v_hat = self.v_max[key] / bc2
1964
+ else:
1965
+ v_hat = self.v[key] / bc2
1966
+
1967
+ # distinguish "params also disagree" (a real backward()
1968
+ # bug) from the moment-buffer case.
1969
+ if np.asarray(params[key]).shape != g_shape:
1970
+ raise ValueError(
1971
+ f'[!] params["{key}"] shape {np.asarray(params[key]).shape} '
1972
+ f'!= grads["{key}"] shape {g_shape} — trace backward() '
1973
+ f'for key "{key}", this is not a stale-buffer issue.'
1974
+ )
1975
+
1976
+ params[key] -= lr * m_hat / (np.sqrt(v_hat) + self.eps)
1977
+
1978
+ return params
1979
+
1890
1980
  # enhanced MLP with focused forward and backward for better handling of data with varying geometric complexity,
1891
1981
  # allowing it to complement the transformer module in the ensemble method.
1892
1982
  # providing robust performance across a wider range of data complexities by dynamically adjusting its learning focus based on the data's geometric properties.
@@ -1899,7 +1989,6 @@ class MLP:
1899
1989
  self.layers = []
1900
1990
  self.layers2 = []
1901
1991
  self.lr = 0.1
1902
- self.feed_layers = []
1903
1992
 
1904
1993
  self.error_counts = None
1905
1994
  self.pred_counts = None
@@ -1909,22 +1998,11 @@ class MLP:
1909
1998
  self.temp_anisotropy_sample = 0
1910
1999
 
1911
2000
  self.softmax = SoftmaxOutput()
1912
-
1913
-
1914
- def feed_add(self, layer):
1915
- self.feed_layers.append(layer)
1916
2001
 
2002
+
1917
2003
  def add(self, layer):
1918
2004
  self.layers.append(layer)
1919
2005
 
1920
- def focused_forward(self, x, AME=None, anisotropy=None):
1921
- performance_score = self.performance_calculation(x, AME=AME, anisotropy=anisotropy)
1922
-
1923
- for layer in self.feed_layers:
1924
- x = layer.forward(np.asarray(x, dtype=np.float64), performance_score)
1925
-
1926
- return self.softmax.forward(x)
1927
-
1928
2006
  def k_fold_split(self, X, y, k=5, seed=42, min_fold_size=2):
1929
2007
  X = np.asarray(X)
1930
2008
  y = np.asarray(y)
@@ -2090,21 +2168,13 @@ class MLP:
2090
2168
  return prob
2091
2169
 
2092
2170
 
2093
- def focused_backward(self, grad, lr, AME, anisotropy):
2094
- grad = self.softmax.backward(grad)
2095
- perf_score = self.performance_calculation(grad, AME=AME, anisotropy=anisotropy)
2096
-
2097
- for layer in reversed(self.feed_layers):
2098
- grad = layer.backward(grad, lr, perf_score)
2099
- return grad
2100
-
2101
2171
  def backward(self, grad, lr):
2102
2172
  grad = self.softmax.backward(grad)
2103
2173
  perf_score = self.performance_calculation(grad, AME=self.temp_AME_sample, anisotropy=self.temp_anisotropy_sample)
2104
2174
 
2105
2175
  for layer in reversed(self.layers):
2106
- grad = layer.backward(grad, lr, perf_score)
2107
- return grad
2176
+ grad, key_grads = layer.backward(grad, lr, perf_score)
2177
+ return grad, key_grads
2108
2178
 
2109
2179
  def predict(self, X, y, epochs=1000, verbose=True):
2110
2180
  for epoch in range(epochs):
@@ -2202,7 +2272,6 @@ class MLP:
2202
2272
  def train(self, X, y, epochs=1000, lr=0.01, verbose=True, max_samples_for_focused_fit=500):
2203
2273
  X = self._sanitize_string_chars(X)
2204
2274
  y = self._sanitize_string_chars(y)
2205
- focused_fit_condition = False
2206
2275
  parameters = sum(w.size for w in self.layers[0].W) + sum(b.size for b in self.layers[0].b)
2207
2276
 
2208
2277
  AME = self.AME_Encoder(X)
@@ -2212,28 +2281,24 @@ class MLP:
2212
2281
  self.temp_AMR_sample = AMR
2213
2282
  self.temp_anisotropy_sample = anisotropy
2214
2283
 
2215
- focused_fit_condition = len(self.feed_layers) > 0 and anisotropy > 0.25 and AMR > 0.25 and len(X) < max_samples_for_focused_fit
2216
- print(f'[+] Focused fit condition: {focused_fit_condition} || Anisotropy: {self.anisotropy_measurement(X):.4f} || AME: {self.AME_Encoder(X):.4f}')
2217
-
2218
2284
  training_not_allowed = np.isnan(anisotropy) or np.isinf(anisotropy) or np.isnan(AME) or np.isinf(AME) or AME < 0.1
2219
2285
  if training_not_allowed:
2220
2286
  print(f'[!] MLP Training not allowed due to unsuitable data characteristics. Anisotropy: {anisotropy:.4f}, AME: {AME:.4f}')
2221
2287
  else:
2222
2288
  print(f'[+] MLP Training started with: {parameters} Parameters.')
2223
2289
  for epoch in range(epochs):
2224
- if not focused_fit_condition:
2225
- y_pred = self.forward(X, y=y, AME=AME, anisotropy=anisotropy, condition='training')
2226
- else:
2227
- y_pred = self.focused_forward(X, AME=AME, anisotropy=anisotropy)
2228
-
2290
+ y_pred = self.forward(X, y=y, AME=AME, anisotropy=anisotropy, condition='training')
2229
2291
  y_pred, y_true = self.adapt_predict_shape(y_pred, y)
2230
2292
 
2231
2293
  loss = Loss.categorical_crossentropy(y_true, y_pred)
2232
2294
  grad = Loss.softmax_crossentropy_derivative(y_true, y_pred)
2233
- if focused_fit_condition:
2234
- _ = self.focused_backward(grad, self.lr, AME, anisotropy)
2235
- else:
2236
- _ = self.backward(grad, self.lr)
2295
+ grad, key_grads = self.backward(grad, self.lr)
2296
+ try:
2297
+ params = self.layers[0].opt.step(self.layers[0].params, key_grads, clip_norm=5.0)
2298
+ except Exception as e:
2299
+ print(f'[>] AdamOptimizer failed: {e}')
2300
+ continue
2301
+
2237
2302
  if np.isnan(loss) or np.isinf(loss):
2238
2303
  if focused_fit_condition:
2239
2304
  focused_fit_condition = False
@@ -3705,11 +3770,11 @@ class WeightedEnsemblePredictor:
3705
3770
  n_trans_classes = trans_probs.shape[1]
3706
3771
  n_mlp_classes = mlp_probs.shape[1]
3707
3772
 
3773
+ anisotropy = self.anisotropy_measurement(attn_weights)
3708
3774
  n_classes = max(n_trans_classes, n_mlp_classes)
3709
3775
  for i in range(batch_size):
3710
3776
  trans_row = np.zeros(n_classes)
3711
- mlp_row = np.zeros(n_classes)
3712
-
3777
+ mlp_row = np.zeros(n_classes)
3713
3778
  trans_row[:n_trans_classes] = trans_probs[i]
3714
3779
  mlp_row[:n_mlp_classes] = mlp_probs[i]
3715
3780
 
@@ -3717,8 +3782,7 @@ class WeightedEnsemblePredictor:
3717
3782
  mlp_row = mlp_row / (mlp_row.sum() + 1e-8)
3718
3783
 
3719
3784
  if i < len(attn_weights):
3720
- attn = attn_weights[i]
3721
- anisotropy = self.anisotropy_measurement(attn)
3785
+ attn = attn_weights[i]
3722
3786
  # Attention entropy: lower entropy = more focused = trust transformer more
3723
3787
  if attn.size > 0:
3724
3788
  attn_flat = attn.flatten()
@@ -3835,7 +3899,8 @@ class WeightedEnsemblePredictor:
3835
3899
  # Calculate weight based on meta features
3836
3900
  trans_conf = meta_features[i, 0]
3837
3901
  mlp_conf = meta_features[i, 1]
3838
- agreement = meta_features[i, 4]
3902
+ agreement_idx = 6 if has_lstm else 4
3903
+ agreement = meta_features[i, agreement_idx]
3839
3904
 
3840
3905
  trans_pred = int(np.argmax(trans_probs[i]))
3841
3906
  mlp_pred = int(np.argmax(mlp_probs[i]))
@@ -7240,7 +7305,7 @@ class AgentDistributedInference:
7240
7305
  # Sort keys for consistent serialization
7241
7306
  sorted_message = {k: signed_message[k] for k in sorted(signed_message.keys())}
7242
7307
 
7243
- message_bytes = json.dumps(sorted_message, sort_key=True, default=str).encode('utf-8')
7308
+ message_bytes = json.dumps(sorted_message, sort_keys=True, default=str).encode('utf-8')
7244
7309
 
7245
7310
  key = self.secret_key.encode() if isinstance(self.secret_key, str) else self.secret_key
7246
7311
  signature = hmac.new(key, message_bytes, hashlib.sha256).hexdigest()
@@ -7354,7 +7419,7 @@ class AgentDistributedInference:
7354
7419
  # Sort keys for consistent serialization
7355
7420
  sorted_msg = {k: temp_msg[k] for k in sorted(temp_msg.keys())}
7356
7421
 
7357
- message_bytes = pickle.dumps(sorted_msg, protocol=pickle.HIGHEST_PROTOCOL)
7422
+ message_bytes = json.dumps(sorted_msg, sort_keys=True, default=str).encode('utf-8')
7358
7423
 
7359
7424
  key = self.secret_key.encode() if isinstance(self.secret_key, str) else self.secret_key
7360
7425
  expected = hmac.new(key, message_bytes, hashlib.sha256).hexdigest()
@@ -7390,6 +7455,7 @@ class AgentDistributedInference:
7390
7455
  # Add to trusted list with FULL trust if not exists
7391
7456
  if agent_id not in self.trusted_agents:
7392
7457
  self._add_trusted_agent(agent_id, token, TrustLevel.FULL, source="shared_secret")
7458
+ return True
7393
7459
  else:
7394
7460
  # Update trust level if higher
7395
7461
  current_level = self.trusted_agents[agent_id].get('trust_level', TrustLevel.BASIC)
@@ -7397,6 +7463,7 @@ class AgentDistributedInference:
7397
7463
  self.trusted_agents[agent_id]['trust_level'] = TrustLevel.FULL
7398
7464
  print(f"[=] Upgraded trust level to FULL")
7399
7465
  self.highly_trusted_peer.append(agent_id)
7466
+ return True
7400
7467
 
7401
7468
  elif agent_id in self.trusted_agents:
7402
7469
  stored_token = self.trusted_agents[agent_id]['token']
@@ -7493,7 +7560,7 @@ class AgentDistributedInference:
7493
7560
  self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
7494
7561
 
7495
7562
  bind_host = self._get_bind_host()
7496
- self.socket.bind(('0.0.0.0', self.port))
7563
+ self.socket.bind((bind_host, self.port))
7497
7564
 
7498
7565
  self.socket.settimeout(1.0)
7499
7566
  self.socket.listen(5)
@@ -7572,7 +7639,7 @@ class AgentDistributedInference:
7572
7639
  print(f"[-] Connection attempt from blocked IP: {host}")
7573
7640
  self._log_security_event('connection_blocked', {'ip': host})
7574
7641
  client.close()
7575
- return
7642
+ continue
7576
7643
 
7577
7644
  print(f"📡 Connected to agent at {addr}")
7578
7645
  auth_msg = self._receive_message(client)
@@ -7587,7 +7654,7 @@ class AgentDistributedInference:
7587
7654
  self._log_security_event('authentication_failed', {'agent': f"{addr[0]}:{addr[1]}"})
7588
7655
  self.report_failure(id(self), 'authentication', reason=f'Failed authentication from {addr}')
7589
7656
  client.close()
7590
- return
7657
+ continue
7591
7658
 
7592
7659
  # Send agent info to identify
7593
7660
  self._send_agent_info(client)
@@ -10263,8 +10330,6 @@ class IntegratedPipeline:
10263
10330
  model.add(layer1)
10264
10331
  model.add(layer2)
10265
10332
 
10266
- model.feed_add(layer1)
10267
- model.feed_add(layer2)
10268
10333
 
10269
10334
  return y_onehot
10270
10335
 
@@ -10285,10 +10350,7 @@ class IntegratedPipeline:
10285
10350
  self.model3 = MLP()
10286
10351
 
10287
10352
  self.model3.add(layer1)
10288
- self.model3.add(layer2)
10289
-
10290
- self.model3.feed_add(first_feed_layer)
10291
- self.model3.feed_add(sec_feed_layer)
10353
+ self.model3.add(layer2)
10292
10354
 
10293
10355
 
10294
10356
  def automatic_parameterization(self, input_size, num_classes):