Skip to main content

Fast Weight Product Key Memory

Implementation of the Fast Weight Product Key Memory proposed by Sakana AI

Appreciation

  • Pranoy for the contribution of multi-head variant!

Install

$ pip install fast-weight-product-key-memory

Usage

import torch
from fast_weight_product_key_memory import fwPKM

mem = fwPKM(
    dim = 512,
    num_memories = 256 * 256,
    dim_queries_keys = 512,
    dim_values = 512,
    topk = 8,
    learning_rate = 1.,
    chunk_size = 256
)

tokens = torch.randn(2, 256, 512)

# forward a chunk of tokens for retrieved and the fast weight episodic memories

retrieved, next_memories = mem(tokens, return_next_memories = True)

# chain memories

retrieved, next_memories = mem(tokens, return_next_memories = True, past_memories = next_memories)
retrieved, next_memories = mem(tokens, return_next_memories = True, past_memories = next_memories)
retrieved, next_memories = mem(tokens, return_next_memories = True, past_memories = next_memories)

Enwik8

Character-level language model with fwPKM

$ uv run train_enwik8.py

Citations

@misc{zhao2026fastweightproductkeymemory,
    title   = {Fast-weight Product Key Memory},
    author  = {Tianyu Zhao and Llion Jones},
    year    = {2026},
    eprint  = {2601.00671},
    archivePrefix = {arXiv},
    primaryClass = {cs.CL},
    url     = {https://arxiv.org/abs/2601.00671},
}
@article{Yaghoubietal2026,
    author  = {Yaghoubi, Mohammad and Nieto-Posadas, Andres and Mosser, Coralie-Anne and Gisiger, Thomas and Wilson, Émmanuel and Williams, Sylvain and Brandon, Mark P.},
    title   = {Predictive coding of reward in the hippocampus},
    journal = {Nature},
    year    = {2026},
    doi     = {10.1038/s41586-025-09958-0}
}
@misc{cabannes2026sparsedeltamemoryscaling,
    title   = {Sparse Delta Memory: Scaling the State of Linear RNNs through Sparsity},
    author  = {Loïc Cabannes and Pierre-Emmanuel Mazaré and Gergely Szilvasy and Matthijs Douze and Maria Lomeli and Ilze Amanda Auzina and Justin Carpentier and Gabriel Synnaeve and Hervé Jégou},
    year    = {2026},
    eprint  = {2607.07386},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2607.07386},
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_weight_product_key_memory-0.2.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file fast_weight_product_key_memory-0.2.1.tar.gz.

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0f8e386647e5bac03deab676f84cab2581308fda96c9edbab9ed6eac7b3b8a94
MD5 3aa0b471ddd5e6802759fdb98576ca3f
BLAKE2b-256 3b48181ee37a46e768366c53c5be7c92f1c7d8c3d5c334222c13035994832317

See more details on using hashes here.

File details

Details for the file fast_weight_product_key_memory-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d498480af0e15a296f9f6c5959f2e656475d9bcc79e1a4d41a92b1879659583
MD5 8c1641fb892f8746aa66a7a1ddf3cafb
BLAKE2b-256 1d07b9584f6ededef0226b2cd10a76e135918f3cc9ec7dc39826be34ab9a28a8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page