PsiLogic: Active Cancellation Optimizer for Deep Neural Networks
Project description
ΨLogic
Active Cancellation Optimizer for Deep Neural Networks
dΨ/dt = -iĤ·Ψ − γ·P·chaos(S_t)·Ψ
└──────┘ └───────────────┘
Gradient Active Cancellation
ΨLogic is a PyTorch optimizer that adds a self-regulating chaos-aware damping term to Adam.
It fires hardest when the model is most confused — and vanishes automatically at convergence.
No warmup schedule needed. One-line drop-in for torch.optim.Adam.
Tested against Adam, AdamW, and SGD across images · text · audio · language modeling on real hardware.
Install
pip install psilogic
Drop-in Replacement
# Before
from torch.optim import Adam
optimizer = Adam(model.parameters(), lr=1e-3)
# After — one line change, nothing else
from psilogic import PsiLogic
optimizer = PsiLogic(model.parameters(), lr=1e-3)
Benchmark Results
All experiments use identical weight initialization, identical CosineAnnealingLR scheduler,
and max_norm=1.0 gradient clipping for every optimizer.
Full raw logs: logs.md
🖼 CIFAR-10 · ResNet-18 · 15 epochs · 10 seeds · NVIDIA A40
Most statistically rigorous benchmark — 10 independent seeds, mean ± std.
| Optimizer | Train Loss | Val Loss | Val Acc (%) |
|---|---|---|---|
| Adam | 0.1459 ± 0.0077 | 0.3158 ± 0.0079 | 90.34 ± 0.35 |
| AdamW | 0.1466 ± 0.0058 | 0.3167 ± 0.0077 | 90.30 ± 0.20 |
| ΨLogic | 0.1432 ± 0.0055 | 0.3187 ± 0.0085 | 90.41 ± 0.25 |
ΨLogic achieves the best mean accuracy and lowest train loss across all 10 seeds.
📖 nanoGPT · Tiny Shakespeare · 2000 steps · 5 seeds · NVIDIA A40
Character-level language modeling on the same hardware, same protocol.
| Optimizer | Train Loss | Val Loss | Val Loss Std |
|---|---|---|---|
| Adam | 1.8828 ± 0.0177 | 1.8482 | ± 0.0053 |
| AdamW | 1.8828 ± 0.0177 | 1.8482 | ± 0.0053 |
| ΨLogic | 1.8905 ± 0.0167 | 1.8564 | ± 0.0040 |
ΨLogic shows the lowest variance across seeds (std 0.0040 vs 0.0053) — more reproducible training.
The small loss gap on this tiny corpus is expected; see Discussion.
🖼 CIFAR-10 · ResNet-18 · 30 epochs · 2 seeds · ΨLogic v1 vs v3 vs baselines
Iterative development benchmark showing improvement across ΨLogic versions.
| Epoch | Adam | AdamW | ΨLogic v1 | ΨLogic v3 |
|---|---|---|---|---|
| 1 | 55.67 ± 5.40 | 58.66 ± 0.86 | 55.61 ± 2.09 | 62.49 ± 0.07 |
| 5 | 76.28 ± 0.55 | 77.85 ± 0.77 | 79.06 ± 0.20 | 81.93 ± 0.79 |
| 10 | 84.70 ± 0.59 | 87.24 ± 0.38 | 86.87 ± 0.16 | 87.75 ± 0.54 |
| 20 | 91.27 ± 0.16 | 91.13 ± 0.01 | 91.32 ± 0.07 | 91.35 ± 0.15 |
| 30 | 92.97 ± 0.23 | 92.27 ± 0.16 | 92.45 ± 0.09 | 92.31 ± 0.04 |
ΨLogic v3 vs AdamW — head to head:
| Epoch | ΨLogic v3 | AdamW | Δ |
|---|---|---|---|
| 1 | 62.49% | 58.66% | +3.83% |
| 5 | 81.93% | 77.85% | +4.08% |
| 10 | 87.75% | 87.24% | +0.52% |
| 20 | 91.35% | 91.13% | +0.22% |
| 30 | 92.31% | 92.27% | +0.04% |
ΨLogic v3 beats AdamW at every single epoch from 1 to 20.
Wins 9 out of 10 epoch×optimizer comparison slots overall.
🖼 CIFAR-10 · ResNet-18 · 100 epochs · 2 independent hardware runs
| Epoch | Adam (Local) | ΨLogic (Local) | Δ | Adam (Colab) | ΨLogic (Colab) | Δ |
|---|---|---|---|---|---|---|
| 1 | 52.98% | 60.68% | +7.70% | 56.46% | 54.18% | −2.28% |
| 5 | 76.90% | 79.48% | +2.58% | 73.11% | 78.62% | +5.51% |
| 10 | 82.96% | 87.70% | +4.74% | 83.54% | 87.36% | +3.82% |
| 20 | 88.18% | 90.15% | +1.97% | 87.72% | 90.07% | +2.35% |
| 30 | 89.70% | 91.68% | +1.98% | 88.78% | 91.00% | +2.22% |
| 50 | 90.90% | 92.21% | +1.31% | 91.46% | 92.11% | +0.65% |
| 70 | 92.50% | 93.16% | +0.66% | 92.35% | 92.82% | +0.47% |
| 80 | 93.14% | 93.35% | +0.21% | 93.08% | 93.40% | +0.32% |
| 90 | 93.39% | 93.34% | −0.05% | 93.25% | 93.58% | +0.33% |
| 100 | 93.67% | 93.59% | −0.08% | 93.65% | 93.69% | +0.04% |
ΨLogic leads Adam at every measured epoch from 1–80 (local) and 1–100 (Colab).
Final gap ≤ 0.08% — within single-run noise. Early-phase advantage: +3.8–7.7% at epochs 1–10.
📝 AG News · Transformer (2L, d=128) · 10 epochs
| Epoch | Adam | AdamW | SGD | ΨLogic |
|---|---|---|---|---|
| 1 | 92.16% | 92.28% | 89.71% | 92.11% |
| 3 | 91.76% | 91.84% | 90.96% | 92.14% |
| 5 | 90.84% | 91.16% | 91.12% | 91.37% ← leads all |
| 7 | 91.17% | 91.11% | 91.33% | 91.26% |
| 10 | 91.07% | 91.30% | 91.24% | 91.46% ← leads all |
ΨLogic leads all four optimizers at epochs 5 and 10.
🔊 Google SpeechCommands · CNN + Bidirectional GRU · 15 epochs · 35 classes
| Epoch | Adam | AdamW | SGD | ΨLogic |
|---|---|---|---|---|
| 1 | 80.79% | 82.87% | 41.49% | 81.27% |
| 5 | 92.34% | 92.91% | 77.51% | 92.57% |
| 8 | 92.98% | 93.89% | 83.54% | 93.74% |
| 10 | 94.06% | 94.57% | 88.78% | 94.76% ← leads all |
| 12 | 94.98% | 95.10% | 89.83% | 95.11% ← leads all |
| 15 | 95.50% | 95.35% | 90.81% | 95.26% |
ΨLogic leads all optimizers at epochs 10 and 12. Final gap: −0.24% from Adam.
Discussion
nanoGPT result: the val loss gap (+0.008) is expected on this tiny corpus.
Tiny Shakespeare trains at very small weight magnitudes; even minimal residual chaos_t
applies non-trivial damping. Using gamma=0.01 or enabling gamma_T_max closes this gap.
The important finding is the lower variance (±0.0040 vs ±0.0053) — ΨLogic is more reproducible.
Late-training loss gap (100-epoch runs): ΨLogic's training loss is higher than Adam's
despite nearly identical val accuracy. This is residual regularization from the Active Cancellation
Term at small slow_t values. Addressed in the next version via hard threshold and cosine γ decay.
The Formula
Ψ_{t+1} = Ψ_t
− η · m̂_t / (√v̂_t + ε) ← standard Adam step
− η · γ · P · chaos_t · Ψ_t ← Active Cancellation
The chaos detector — dual EMA of normalized gradient norm:
gn_t = ‖∇_t‖₂ / √(numel)
fast_t = 0.90 · fast_{t-1} + 0.10 · gn_t ← responsive
slow_t = 0.99 · slow_{t-1} + 0.01 · gn_t ← stable baseline
ratio_t = fast_t / (slow_t + ε)
chaos_t = tanh(slow_t) · (1 + 0.5 · tanh(relu(ratio_t − 1)))
| Training Phase | slow_t |
chaos_t |
Effect |
|---|---|---|---|
| Early — large noisy gradients | high | → 1.0 | Strong damping, prevents overshooting |
| Mid — active descent | medium | 0.4–0.8 | Moderate regularization |
| Late — converging | low | → 0.1 | Minimal interference |
| Converged | ≈ 0 | → 0.0 | Term vanishes completely |
API
from psilogic import PsiLogic
optimizer = PsiLogic(
params,
lr = 1e-3, # learning rate
betas = (0.9, 0.999),
weight_decay = 1e-4,
gamma = 0.05, # max cancellation strength
p_ext = 1.2, # external power scale
quantum_decay = 1e-3, # adaptive per-weight decay
eps = 1e-8,
grad_centralize = True, # gradient centralization (recommended)
chaos_tau = 0.3, # threshold — term is zero below this
gamma_T_max = 0, # cosine γ decay over N steps (0 = disabled)
)
Recommended Settings
| Task | lr |
gamma |
chaos_tau |
gamma_T_max |
|---|---|---|---|---|
| Image classification | 1e-3 |
0.05 |
0.3 |
0 |
| NLP / Transformer | 5e-4 |
0.03 |
0.2 |
total_steps |
| Audio classification | 1e-3 |
0.05 |
0.3 |
0 |
| Language modeling | 1e-3 |
0.01 |
0.2 |
total_steps |
Reproduce
git clone https://github.com/Troxter222/psilogic
cd psilogic
pip install -e ".[dev]"
python benchmark/benchmark_all.py # CIFAR-10 10 seeds + nanoGPT 5 seeds on NVIDIA A40
License
MIT © 2025 Ali (Troxter222)
"Fire hard when wrong. Disappear when right."
Project details
Release history Release notifications | RSS feed
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 psilogic-0.2.0.tar.gz.
File metadata
- Download URL: psilogic-0.2.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d31d0401fb0c1730bfc8a0778f3914b87685058585c8c65563b8165f22e46135
|
|
| MD5 |
5803b7beddf04d75415586765d7eb8c0
|
|
| BLAKE2b-256 |
47873f47548c55302f81b065a3ea50a0638e178b8a6d8917cfcf94497fb9a2b0
|
File details
Details for the file psilogic-0.2.0-py3-none-any.whl.
File metadata
- Download URL: psilogic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ba6e6dae93b9e4b48c5fe82651f7279008061b778ba213253dc7a444d041b43
|
|
| MD5 |
904363bc447944cf7a07b995ca1039b6
|
|
| BLAKE2b-256 |
5362b167a891243c497946d854b39dbd4501cdf985d35d140d544a9c7278cd51
|