Intelligence layer for AI/ML — stabilization, selective memory, weight surgery
Project description
ZPower (zp) — v1.3.0
Intelligence layer for AI/ML systems.
Works with PyTorch and HuggingFace — not against them.
Stabilize training. Protect good weights. Detect anomalies. Reduce wasted compute.
Install
pip install zpower # numpy only (core features)
pip install zpower[torch] # + PyTorch support
pip install zpower[hf] # + HuggingFace Transformers
pip install zpower[full] # everything
Quick Start
Mode A — Attach to any existing model
import zpower as zp
zp_model = zp.attach(
my_model,
stabilize = True, # GradShield + StabilityCore
monitor = True, # NipGraph anomaly detection
weight_vault = True, # Record best weight snapshots
auto_heal = True, # Auto-recover from training failures
)
output = zp_model(input_tensor) # Forward pass unchanged
loss.backward() # GradShield hooks active automatically
Mode B — Training from scratch
trainer = zp.Trainer(
my_model,
stabilize = True,
weight_vault = True,
auto_heal = True,
heal_strategy = "both", # 'both', 'rollback_only', 'lr_only', 'restart'
)
trainer.fit(train_loader, epochs=20, lr=1e-3)
print(trainer.weight_report())
Multi-model weight selection
from zpower.weights import WeightSurgeon
surgeon = WeightSurgeon()
surgeon.auto_discover("./checkpoints/") # Scans folder, asks y/N per file
best = surgeon.select_best()
new_model.load_state_dict(best)
Module Overview
| Module | Purpose |
|---|---|
zp.memory.OtuxStore |
Selective 3D-coordinate memory — only stores important info |
zp.stabilize.GradShield |
Gradient health monitor — adaptive per-layer thresholds |
zp.stabilize.StabilityCore |
Loss EMA, plateau detection, LR signal |
zp.stabilize.ModelStabilizer |
Unified stabilization API |
zp.monitor.NipGraph |
Parity-aware training anomaly detection |
zp.weights.WeightVault |
Performance-gated weight snapshots |
zp.weights.WeightSurgeon |
Multi-model best weight selection with auto_discover |
zp.weights.WeightGuard |
EWC-style catastrophic forgetting prevention |
zp.heal.AutoHeal |
Automatic training failure recovery (4 strategies) |
zp.compute.SafeMath |
NaN-safe math with rational number fallback |
zp.compute.safe_loss |
NaN-safe loss computation |
zp.compat.ZPowerModel |
Transparent PyTorch / HuggingFace model wrapper |
Supported Model Types
ZPower is model-agnostic — it works on any torch.nn.Module:
| Model Type | Examples | How to Use |
|---|---|---|
| Text LLMs / SLMs | GPT-2, LLaMA, Mistral, Phi | zp.attach(model) or zp.compat.augment(model) |
| Image Models | ResNet, ViT, EfficientNet | zp.attach(model) |
| Audio Models | Whisper, Wav2Vec2 | zp.attach(model) |
| Video Models | VideoMAE, TimeSformer | zp.attach(model) |
| Multimodal | CLIP, LLaVA, BLIP | zp.attach(model) |
| Custom Models | Any nn.Module subclass |
zp.attach(model) |
| HuggingFace | Any PreTrainedModel |
zp.compat.augment(model) |
ZPower runs as a side-channel — it never modifies your model's forward pass, weights, or gradients (except when GradShield clips exploding gradients or AutoHeal rolls back).
v1.3.0 — What's New
Critical Bug Fixes
-
Trainer crash on StabilityCore fallback —
_ema_last()was called asself._ema_last()but it's a module-level function, causingAttributeError. Now fixed to_ema_last(model). -
AutoHeal docstring said "Reserved for v2" — AutoHeal has been fully implemented since v1.1. Both
zp.attach()andzp.Trainer()docstrings now correctly describe it. -
Memory entries all tagged
step_0— Without Trainer,ZPowerModel._stepwas never incremented inforward(), so all OtuxStore entries had the same step number. Now incremented correctly. -
Test bug:
query_by_coord()returns dicts — Test accessed.tokenattribute but the method returns dicts since v1.2. Fixed.
Smart Features
Smart Eviction (OtuxStore) — _evict() was O(N) scanning all entries. Now uses a min-heap for O(log N) eviction. The lowest-scored entry is always at the top of the heap.
Adaptive Warmup (GradShield) — Previously used a fixed 20-step warmup before activating adaptive thresholds. Now uses variance-based confidence: exits warmup when per-layer gradient statistics are stable. Prevents premature thresholds on layers with few observations.
Multiple Heal Strategies (AutoHeal) — New strategy parameter:
# Default: rollback + LR cut (v1.1/v1.2 behaviour)
healer = AutoHeal(model, vault, optimizer, strategy="both")
# Only rollback weights, keep current LR
healer = AutoHeal(model, vault, optimizer, strategy="rollback_only")
# Only reduce LR, no weight rollback
healer = AutoHeal(model, vault, optimizer, strategy="lr_only")
# Full restart: rollback + LR cut + reset optimizer momentum
healer = AutoHeal(model, vault, optimizer, strategy="restart")
Overhead Tracking — ZPower now measures its own overhead:
zp_model = zp.attach(my_model)
# ... training ...
print(f"ZPower overhead: {zp_model.overhead_per_call_ms():.3f}ms/call")
zp_model.pprint_status() # Formatted dashboard
Security & Robustness
ZPConfig.validate()usesValueErrorinstead ofassert(assert can be disabled with-O)ZPConfig.validate()now validates ALL 27 fields (was only 4)WeightSurgeonlogs WARNING when falling back toweights_only=FalseGradShield._remove_hooks()catchesRuntimeErrorfor already-removed hooksWeightVault.load()validates file existence before loadingOtuxStoreconstructor validatesdim,max_entries, threshold orderingSafeMathconstructor validatespocket_capacityzplog.set_level()validates input level
Developer Experience
__repr__on all classes — Every major class now has a useful__repr__for debuggingAutoHeal.reset()— Clear heal state for reuse between training runsWeightVault.get_snapshot_metrics()— Retrieve stored metrics (loss, accuracy, etc.) per layerWeightVault.save()now persists metrics — Metrics were lost on save/load, now preservedZPowerModel.pprint_status()— Formatted console output of all component statusOtuxStore._prep()clearer errors — Non-numeric input and zero-norm vectors explain the problemNipGraph.VarState.historyisdeque— O(1) trim instead of O(N)list.pop(0)
Release Notes
v1.2.0 — May 2026
Theme: Critical Bug Fixes + Security + Performance
3 critical bugs that silently broke core functionality were fixed. 5 high-priority correctness issues resolved. 3 performance upgrades. 1 new feature (WeightSurgeon.auto_discover).
Critical Bug Fixes
- ZPowerModel.parameters() returned empty iterator — optimizer never trained model
- StabilityCore plateau detection compared incompatible values — EMA vs raw loss
- write_batch() overwrote the wrong entry result — buf_result_idx tracking fix
Performance Upgrades
| Component | Change | Impact |
|---|---|---|
OtuxStore.query() |
np.argsort to np.argpartition |
O(N log N) to O(N) |
GradShield.status() |
Full history scan to running counters | O(N) to O(1) |
StabilityCore._history |
list + manual trim to deque(maxlen) |
O(N) to O(1) |
SafeMath pocket |
dict to OrderedDict |
O(N) to O(1) LRU |
v1.1.0 — May 2026
Theme: Performance + AutoHeal + Adaptive Thresholds
- AutoHeal Engine: automatic training failure recovery
- OTUX-S Memory: 100x faster writes, write_batch()
- GradShield: adaptive per-layer thresholds via Welford algorithm
v1.0.0 — May 2026
Initial release. Seven core modules published.
Research Origins
Original research by NNN Bhoi:
| System | Origin |
|---|---|
| OTUX-S | PERATHINK research paper — selective 3D coordinate memory |
| NipGraph | NipGraph research paper — parity-aware state tracking |
| GradShield + StabilityCore | MUSAI vGPU engine — M2 + M4 modules |
| WeightVault / Surgeon / Guard | ZPower original research |
| AutoHeal | ZPower original research |
License
MIT — free to use in any project.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zpower-1.3.0.tar.gz.
File metadata
- Download URL: zpower-1.3.0.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5b3f569ed2c6abda5c0ea205d659f1adb6ed896c3711944f5f49ac7996095d6
|
|
| MD5 |
ec0f53062dd4d33e0e61aba76a27b2a7
|
|
| BLAKE2b-256 |
d70cabdce71b787a69948f68749ed0f8942dae16b379a7c19559da20324313e1
|
File details
Details for the file zpower-1.3.0-py3-none-any.whl.
File metadata
- Download URL: zpower-1.3.0-py3-none-any.whl
- Upload date:
- Size: 47.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
278a5eaf06749c9c6e07ae92e614277df1b4cdbcae6cc3caf7209bf113dbfcee
|
|
| MD5 |
be85715ce7a21a74d8aaddfa9b2ac495
|
|
| BLAKE2b-256 |
e6d2dbcee617475133f3f36e8fa8af6bde98e36f07d318f966ab05c4d336c1f7
|