Practical overview
When it fits
Use Memformer when a PyTorch sequence-model experiment needs memory to persist across consecutive input segments, or when exploring the included replay-based training utility.
Who it is for
- Researchers prototyping memory-augmented sequence models.
- Python and PyTorch developers building encoder-only or encoder-decoder experiments.
- Practitioners exploring training on long sequences split into segments.
Documented uses
- Pass learned memory slots from one input segment to the next.
- Build an encoder-only representation workflow over successive segments.
- Prototype encoder-decoder processing with source segments and target inputs.
- Use the provided memory-replay utility with source and target masks for segmented-sequence training.
Requirements & limits
The repository lists an MIT license and documents installation with `pip install memformer`.
- The examples require configuring token counts, dimensions, sequence lengths, attention heads, depth and memory slots.
- The encoder-only example explicitly returns encoded outputs and memory slots for reuse on the next segment.
- The memory-replay example uses CUDA tensors and the
.cuda()method.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Set up Memformer for a PyTorch experiment
Install the package and configure a documented encoder-only or encoder-decoder model.
Before you start
- Python environment with PyTorch available.
Steps
Install the package with the command below.
pip install memformerImport
Memformerfrommemformer.Choose the documented encoder-only or full encoder-decoder configuration and set its model dimensions, token counts, sequence lengths and memory slots.
Expected outcome
A configured Memformer model ready for the documented segment-processing examples.
Guide limitations
- The setup example does not document dependency versions or platform-specific installation instructions.
Pass memory through an encoder-decoder sequence
Use the documented model calls to carry memory across source segments and compute a target loss.
Before you start
- An installed Memformer package and PyTorch.
- A configured encoder-decoder Memformer model.
Steps
Pass the first source segment to the model and retain its returned memory slots.
Pass the next source segment with the retained slots using
mems.Pass a later source segment together with the target and the prior memory slots.
Use the returned loss in the documented
loss.backward()call.
Expected outcome
The example produces encoder outputs and updated memory across segments, then computes a loss for a target-bearing call.
Guide limitations
- The example uses synthetic token tensors; it does not document data preparation or a complete training loop.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 18 October 2026
- Original website title
- lucidrains/memformer · Official homepage title · retained in its source language

