How aliutkus/spe works
Purpose and layout
This research repository implements Stochastic Positional Encoding (SPE), a relative-position-compatible encoding for linear-complexity Transformers. It contains reusable PyTorch and JAX packages plus three independent experiment stacks: Long Range Arena (LRA), pop-piano generation, and groove continuation. It is not a unified application or service.
Core SPE libraries
The primary reusable entry points are framework-specific packages:
• PyTorch: src/pytorch/spe/spe.py, packaged by src/pytorch/setup.py
• JAX/Flax: src/jax/jax_spe/spe.py, packaged by src/jax/setup.py
These form the positional-encoding boundary: downstream Transformer models consume their generated positional representations while retaining framework-specific tensor/runtime conventions.
LRA benchmark pipeline
The LRA experiment compares attention/model variants across AAN, CIFAR-10, ListOps, pathfinder, and text classification through shell launchers:
• experiments/lra/run_aan.sh
• experiments/lra/run_cifar10.sh
• experiments/lra/run_listops.sh
Model/run configuration and reported outputs are persisted per architecture, task, and repeat under experiments/lra/models/gpu_16g/, e.g. experiments/lra/models/gpu_16g/performer_softmax/aan/r1/config.py and experiments/lra/models/gpu_16g/performer_softmax/aan/r1/results.json. This directory is primarily an experiment-record boundary rather than shared executable model code.
Linear-attention dependency boundary
LRA vendors a fast-attention implementation as a separately packaged component:
• experiments/lra/fast_attention/fast_self_attention/fast_self_attention.py
• experiments/lra/fast_attention/setup.py
• experiments/lra/long-range-arena
The long-range-arena path is a submodule dependency, as implied by .gitmodules; cloning recursively is required. Fast self-attention is the key mechanism that makes SPE experiments compatible with long sequences.
Pop-piano generation
This is a standalone PyTorch training/inference workflow. Entrypoints are experiments/pop_piano/train.py, experiments/pop_piano/inference.py, and experiments/pop_piano/eval.py. Serialized REMI vocabulary and dataset splits enter through experiments/pop_piano/pickles/remi_vocab.pkl, experiments/pop_piano/pickles/train_pieces.pkl, and experiments/pop_piano/dataloader.py.
Token sequences flow into APE or SPE Performer model variants, then generation utilities produce continuations; inference output can be converted to MIDI via experiments/pop_piano/convert2midi.py. Architecture selection and training/inference parameters are separated into YAML configs, notably experiments/pop_piano/configs/train/convspe_default.yaml and experiments/pop_piano/configs/inference/default.yaml.
Groove continuation
Groove uses an installable spe_music package and a notebook-oriented data/evaluation workflow:
• Training: experiments/groove/src/spe_music/train_performer_grv2grv.py
• Event representation: experiments/groove/src/spe_music/event_processor.py
• Models: experiments/groove/src/spe_music/model/music_performer.py, experiments/groove/src/spe_music/model/fast_transformer_decoder.py
Prepared groove data feeds event processing, Performer decoding, and trained experiment configurations such as experiments/groove/exp/trio_performer_softmax_convspe_l512_v01/config.yaml. Style evaluation is a separate post-generation boundary using experiments/groove/src/spe_music/style_eval/style_profiles.py and experiments/groove/src/spe_music/style_eval/note_features.py.
Runtime and infrastructure
The code is Python-based, with PyTorch for music and likely LRA model execution, plus JAX/Flax for the standalone SPE implementation. Workloads are GPU-oriented, evidenced by experiments/lra/models/gpu_16g/. There are no deployed services or network APIs; external dependencies are Python packages, benchmark/data assets, a vendored/submodule LRA dependency, and MIDI-oriented local artifacts.
Main entry points: spe.py PyTorch SPE · fast_self_attention.py Fast self-attention · inference.py Piano inference · music_performer.py Performer decoder
Components 19
SPE libraries
Framework-specific reusable positional encoding packages.
- PyTorch SPE
src/pytorch/spe/spe.py - JAX/Flax SPE
src/jax/jax_spe/spe.py
LRA benchmarks
Long-sequence attention experiments and recorded runs.
- LRA launchers · Launch task-specific benchmark runs.
experiments/lra/run_aan.sh - Fast self-attention · Vendored long-sequence attention mechanism.
experiments/lra/fast_attention/fast_self_attention/fast_self_attention.py - Long Range Arena · External benchmark dependency requiring recursive clone.
experiments/lra/long-range-arena - LRA run records · Configurations and results are stored per architecture, task, and repeat.
experiments/lra/models/gpu_16g/performer_softmax/aan/r1/results.json
Pop-piano
Standalone PyTorch generation workflow.
- Piano YAML configs · Selects architecture and training or inference parameters.
experiments/pop_piano/configs/train/convspe_default.yaml - REMI data and vocabulary · Vocabulary and split artifacts feed the dataloader.
experiments/pop_piano/pickles/remi_vocab.pkl - Piano dataloader
experiments/pop_piano/dataloader.py - APE/SPE Performer · Performer variants consume token sequences for training and generation.
- Piano training
experiments/pop_piano/train.py - Piano inference · Generates continuations.
experiments/pop_piano/inference.py - MIDI conversion
experiments/pop_piano/convert2midi.py
Groove continuation
Installable music package with notebook-oriented evaluation.
- Prepared groove data
- Event processor
experiments/groove/src/spe_music/event_processor.py - Performer decoder
experiments/groove/src/spe_music/model/music_performer.py - Groove training
experiments/groove/src/spe_music/train_performer_grv2grv.py - Groove experiment config
experiments/groove/exp/trio_performer_softmax_convspe_l512_v01/config.yaml - Style evaluation · Evaluates generated music using style profiles and note features.
experiments/groove/src/spe_music/style_eval/style_profiles.py
Connections 18
- LRA launchers → Long Range Arena: runs benchmarks
- LRA launchers → Fast self-attention: selects attention
- PyTorch SPE → Fast self-attention: SPE-compatible attention
- Fast self-attention → LRA run records: records runs
- Piano YAML configs → Piano training: configures
- Piano YAML configs → Piano inference: configures
- REMI data and vocabulary → Piano dataloader: loads
- Piano dataloader → APE/SPE Performer: token sequences
- PyTorch SPE → APE/SPE Performer: SPE variant
- APE/SPE Performer → Piano training: optimizes
- APE/SPE Performer → Piano inference: generates
- Piano inference → MIDI conversion: exports MIDI
- Prepared groove data → Event processor: events
- Event processor → Performer decoder: encoded sequences
- PyTorch SPE → Performer decoder: SPE variant
- Groove experiment config → Groove training: configures
- Performer decoder → Groove training: trains
- Groove training → Style evaluation: generated continuations