Skip to main content

Fast Weight Product Key Memory

Project description

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

Project details


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.4.tar.gz (8.5 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.4.tar.gz.

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.1.4.tar.gz
Algorithm Hash digest
SHA256 041c3709bbbefde4fdf03f785c32f0e83e0cadb29ce530210174829ea6024538
MD5 433d1c57fce4d0430a58a6d6176ca74a
BLAKE2b-256 ec50ffa56e9ad039ba851ea07e938680f21b8439ca476ef25f78d9aca44f2671

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fast_weight_product_key_memory-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 91519a005d84be78f4072e89bcd7c56b6cf1de2342be27ec36b504f803e9844f
MD5 a88470f70dbf6e1d495357a106a102db
BLAKE2b-256 310b445095c6a38733b6bb2063512189f99a8150af787ef85b04e1b6091c944f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page