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}
}

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.1.5.tar.gz (8.7 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.1.5.tar.gz.

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ad7fff7ed605aa9141f0f221e2bc22dd2db900ef729e31ac9ae3a3c91bd161a4
MD5 1f525eb33934382ddf7e495efd9cb341
BLAKE2b-256 05aedc4d4bdc75751efb3bd89b31321ef00c1262ef4834bca4677a07065d5dff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc96cb59a03ed344fff8b5521335e8a0ff00f50269d8c642aaff721d5677fef
MD5 028ee94e94c06c4b83b1d6e7fea473a2
BLAKE2b-256 29c858481b791fc67761cbdf2486a04f188a25dacb2a362b105f232de11932bb

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

0.2.0

2 files

This release

0.1.5 This release

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