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

Metadata

Release files for fast-weight-product-key-memory 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fast-weight-product-key-memory 0.2.2
File Size Uploaded
fast_weight_product_key_memory-0.2.2.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fast-weight-product-key-memory 0.2.2
File Interpreter ABI Platform
fast_weight_product_key_memory-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / fast_weight_product_key_memory-0.2.2.tar.gz

Download URL fast_weight_product_key_memory-0.2.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c663e1b9403a9458e9d49dbffffacdf77325940be9fbbc7e839ef0ce161a6df0
BLAKE2b-256 checksum
How to use checksums
f170b413f661b01fea5af85990b256490c02f0e17f1e6f266674541e9b60717c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / fast_weight_product_key_memory-0.2.2-py3-none-any.whl

Download URL fast_weight_product_key_memory-0.2.2-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44c2e9d1e7b3382d0f2a6682d465b125a4fc62581a424a269d94ab9d7c516c1a
BLAKE2b-256 checksum
How to use checksums
ee453fdd8c1f1e867277cdea5bf85ff71bb87622b63b803fd600c4c387c61b1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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