idempotent-hopfield: Zero-Copy Modern Hopfield Associative Memory & CAM Engine
Eliminate 100% of auxiliary VRAM allocations during Modern Hopfield Associative Memory pattern retrieval and Content-Addressable Memory (CAM) consolidation.
🚀 The Bottleneck: Associative Memory Reallocation
Modern Hopfield Networks (Ramsauer et al., 2020) and high-dimensional Content-Addressable Memory (CAM) architectures store massive banks of continuous prototype patterns to enable associative recall and energy-based pattern completion.
When retrieving and consolidating candidate memory states into stable attractor basins, conventional systems execute pattern compaction via out-of-place memory gathering (torch.gather / dynamic cudaMalloc):
- Auxiliary Memory Bloat: Allocating secondary destination buffers of size $O(B \cdot K \cdot D)$ consumes hundreds of megabytes of transient VRAM across memory banks.
- Memory Bus Saturation: Double-buffering redundant read/write cycles congests High-Bandwidth Memory (HBM).
- Allocation Jitter: Dynamic memory management introduces latency spikes in high-throughput retrieval pipelines and vector search systems.
⚡ The Solution: In-Situ Idempotent Attractor Basin Locking
idempotent-hopfield rearranges continuous memory patterns directly within existing memory allocations using $O(1)$ scalar hardware registers:
- Idempotent Attractor Invariant: Enforces the algebraic property $f(f(x)) = f(x)$, locking retrieved patterns into stabilized contiguous attractor basins $[0, K-1]$.
- Bitmask-Free Cycle Follower: Resolves permutation orbits on GPU streaming multiprocessors without auxiliary bitmasks or auxiliary global memory.
- In-Register 2-Cycle Fast-Path: Mutually transposed memory patterns are swapped directly across thread registers with zero memory overhead.
- 100% Zero Auxiliary VRAM: Exactly 0.00 MB auxiliary secondary memory allocated.
- Bit-Exact Numerical Parity: Zero approximation error ($\Delta = 0.000000$, 0 NaN).
- Blazing Throughput: Exceeds 74+ Million patterns/second on modern NVIDIA GPUs.
📊 Benchmark: NVIDIA RTX PRO 500 Blackwell (sm_120)
Workload: 16 Memory Banks, 4,096 Patterns/Bank (65,536 total patterns), FeatureDim=512, Capacity=2,048 (50% Active, float16)
| Implementation | Latency (ms) | Throughput | Peak Aux VRAM | VRAM Saved | Numerical Diff |
|---|---|---|---|---|---|
| PyTorch Out-of-Place Gather | 1.630 ms | 40.22 M pat/s | 96.00 MB | Baseline | 0.000000 |
idempotent-hopfield (Ours) |
0.877 ms | 74.71 M pat/s | 0.00 MB | 96.00 MB (100%) | 0.000000 |
| Improvement | 1.86x Faster | +85.7% Throughput | 0.00 MB | 100% Eliminated | Bit-Exact (0 NaN) |
📦 Installation
git clone https://github.com/aemre-cetin/idempotent-hopfield.git
cd idempotent-hopfield
pip install -e .
Requirements: torch >= 2.0.0, triton >= 2.1.0.
🛠️ Quickstart
import torch
from idempotent_hopfield import InplaceHopfieldCAM
# Initialize CAM engine
cam = InplaceHopfieldCAM(hidden_dim=512, block_d=128)
# Memory pattern bank on GPU [Banks, Patterns, FeatureDim]
patterns = torch.randn((16, 4096, 512), dtype=torch.float16, device="cuda")
# Energy / associative recall affinity scores [Banks, Patterns]
energy_scores = torch.rand((16, 4096), dtype=torch.float32, device="cuda")
# In-place consolidation: locks top-2048 patterns into attractor basins with 0 bytes aux VRAM
consolidated_patterns = cam(patterns, energy_scores, capacity=2048)
# Output shape: [16, 2048, 512] directly physically contiguous
print("Consolidated patterns shape:", consolidated_patterns.shape)
PyTorch Hopfield Layer Hook
from idempotent_hopfield.integrations import HopfieldAssociativeLayerHook
# Drop-in hook for Modern Hopfield networks
hook = HopfieldAssociativeLayerHook(hidden_dim=512, capacity=2048)
# Execute in-place attractor consolidation
consolidated_memory = hook(memory_patterns, queries=query_embeddings)
🛡️ Patent & Intellectual Property Notice
The mathematical formulations, state-transition architectures, and in-situ hardware compaction kernels implemented in this library are protected under pending patent application with the United States Patent and Trademark Office:
- U.S. Patent Application Number:
64/148,668 - Confirmation Number:
5890 - Status: PATENT PENDING
- First Named Inventor: Dr. Ahmet Emre ÇETİN
Academic evaluation, non-commercial research, and open-source collaboration are permitted under the terms of the Apache 2.0 License. Commercial deployment in proprietary hardware or commercial cloud runtimes is subject to bilateral licensing agreements with the author.
📜 Academic Citation
@article{cetin2026idempotenthopfield,
title={Zero-Copy Modern Hopfield Associative Memory and In-Situ Attractor Consolidation in Deep Learning Accelerators},
author={Cetin, A. Emre},
journal={arXiv preprint},
year={2026},
note={U.S. Patent Application No. 64/148,668}
}
@article{cetin2013idempotent,
title={Idempotent Permutations},
author={Cetin, A. E.},
journal={arXiv:1307.3877 [cs.DS]},
year={2013}
}
📄 License
Licensed under the Apache License, Version 2.0. Copyright © 2026 Dr. A. Emre ÇETİN. All Rights Reserved.
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 idempotent_hopfield-0.1.0.tar.gz.
File metadata
- Download URL: idempotent_hopfield-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec5e935ed57a04ae9833cacfacc2d501bd65fd309f9cbd63cd59b013cbd8f8ef
|
|
| MD5 |
d44a0e4e72138feb299e6f212cbde73c
|
|
| BLAKE2b-256 |
1fc07ebf643b11534232e0f3522b514bcdbb811c14d97278ad26cbf6cdbfd1d9
|
File details
Details for the file idempotent_hopfield-0.1.0-py3-none-any.whl.
File metadata
- Download URL: idempotent_hopfield-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e96a50948d0af0cd7c1d533a314c83a2a3654304f3f1ab8137b4b17605141f2
|
|
| MD5 |
db22f0fcf8ad81e3328360330add02f1
|
|
| BLAKE2b-256 |
a771cf28b2d8e18759ee255b4e18c1e72666541077d1e8c971a67a399e31da6e
|